예제 #1
0
        public TestView()
        {
            InitializeComponent();
              logicStarter = new LogicHandler(new WinFormsViewFactory());

              clientPlayer1 = CreatePlayerInfo("ClientPlayer1");
              clientDeck1 = logicStarter.ServicesProvider.DecksService.LoadDeck("Reali", "Samurai");
              clientDeck1.MainCards.Shuffle();
              clientStarter1 = new ClientStarterModel(clientPlayer1, clientDeck1, logicStarter.ServicesProvider);
              clientStarter1.Started += new Action<object>(clientStarter1_Started);
              connector1 = new ClientConnector(clientPlayer1, logicStarter.ServicesProvider);

              clientPlayer2 = CreatePlayerInfo("ClientPlayer2");
              clientDeck2 = logicStarter.ServicesProvider.DecksService.LoadDeck("Reali", "Samurai");
              clientDeck2.MainCards.Shuffle();
              clientStarter2 = new ClientStarterModel(clientPlayer2, clientDeck2, logicStarter.ServicesProvider);
              clientStarter2.Started += new Action<object>(clientStarter2_Started);
              connector2 = new ClientConnector(clientPlayer2, logicStarter.ServicesProvider);

              serverPlayer = CreatePlayerInfo("ServerPlayer");
              serverDeck = logicStarter.ServicesProvider.DecksService.LoadDeck("Reali", "Samurai");
              serverDeck.MainCards.Shuffle();
        }
예제 #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();
              }
        }