Exemplo n.º 1
0
 public void RegisterController(ClientStarterController controller)
 {
     this.controller = controller;
 }
Exemplo n.º 2
0
        public void StartClientGame(GameStartMode startMode)
        {
            PlayerInfo thisPlayer = CreateLocalPlayerInfo();

              // ----------------------------------------------------------
              // choose game parameters and connect (obtain server channel)
              // ----------------------------------------------------------
              ClientConnector connector = new ClientConnector(thisPlayer, servicesProvider);
              try
              {
            var initView = viewFactory.CreateClientInitializationView(startMode);
            var initModel = new ClientInitializationModel();
            var initController = new ClientInitializationController(initModel, initView, thisPlayer, connector, servicesProvider);
            initController.DeckRoomRequest += new Func<DeckItem>(initController_DeckRoomRequest);
            if(initView.ShowModal() == ViewResult.Ok)
            {
              // ------------------------------------------------------------
              // open room, wait other players and chat (obtain players list)
              // ------------------------------------------------------------
              var clientStarterModel = new ClientStarterModel(thisPlayer, initModel.Deck, servicesProvider);
              var clientStarterView = viewFactory.CreateClientStarterView();
              bool proceed = false;
              using(var commandHandler = new NetCommandHandler<IGameStarterModel>(clientStarterModel, thisPlayer.NickName))
              {
            commandHandler.AddChannel(initModel.ServerData.Channel, initModel.ServerData.Player.NickName);
            var clientStarterController = new ClientStarterController(commandHandler, clientStarterModel, connector, clientStarterView, servicesProvider, initModel);
            proceed = clientStarterView.ShowModal() == ViewResult.Ok;
              }
              if(proceed)
              {
            // ----------
            // start game
            // ----------
            switch(startMode)
            {
              case GameStartMode.NewGame:
                {
                  var players = CreatePlayerAccounts(thisPlayer.NickName, clientStarterModel.Players.ToList());
                  players.Single(e => e.Info.NickName == initModel.ServerData.Player.NickName).Channel = initModel.ServerData.Channel;
                  StartGame(players, null, GameType.Client);
                }
                break;
              case GameStartMode.SavedGame:
                {
                  var players = CreatePlayerAccounts(thisPlayer.NickName, clientStarterModel.SavedGame);
                  players.Single(e => e.Info.NickName == initModel.ServerData.Player.NickName).Channel = initModel.ServerData.Channel;
                  StartGame(players, clientStarterModel.SavedGame, GameType.Client);
                }
                break;
            }
              }
            }
              }
              finally
              {
            if(connector.IsConnected)
              connector.Disconnect();
              }
        }