Instructs the PlayFab game server hosting service to instantiate a new Game Server Instance
Inheritance: Command
Ejemplo n.º 1
0
        public async Task <IActionResult> StartGame(StartGameCommand startGameCommand, string id)
        {
            var matchService = await _matchListService.GetMatchService(UserId, id);

            await matchService.AddEventAsync(new StartGameEvent
            {
                OccuredAt = DateTime.UtcNow
            });

            return(RedirectToAction(nameof(Index), new { id }));
        }
        public void StartNewGame_ValidGameSettings_GameCreated()
        {
            // arrange
            StartGameCommand testStartCommand = new StartGameCommand(_gameCreatorMock.Object, _manipulatorMock.Object, _defaultSettings);

            // act
            testStartCommand.Execute();

            // assert
            _gameCreatorMock.Verify(c => c.CreateGame(_defaultSettings, _manipulatorMock.Object), Times.Once());
        }
Ejemplo n.º 3
0
        public void StartGameCommandTest()
        {
            createContext();

            ICommand startGameCommand = new StartGameCommand(_context, EState.DECIDING, true);

            startGameCommand.Execute();

            Assert.IsNotNull(_context.Robot);
            Assert.IsTrue(_context.State is DecidingState);
        }
Ejemplo n.º 4
0
        public void StartGameWithTwoCounterKing()
        {
            var game = new Game
            {
                State   = new LobbyState(),
                Players =
                {
                    new Player
                    {
                        User = new User
                        {
                            Id = 1
                        },
                        IsOwner = true,
                        Deck    = new Deck
                        {
                            BattleKingCard = new DeckCard
                            {
                                Card = new Card
                                {
                                    Effect = GwintEffect.CounterKing
                                }
                            }
                        }
                    },
                    new Player
                    {
                        User = new User
                        {
                            Id = 2
                        },
                        Deck = new Deck
                        {
                            BattleKingCard = new DeckCard
                            {
                                Card = new Card
                                {
                                    Effect = GwintEffect.CounterKing
                                }
                            }
                        }
                    }
                }
            };
            var command = new StartGameCommand
            {
                SenderUserId = 1
            };

            command.Execute(game);

            Assert.True(game.Players.All(p => !p.CanUseBattleKingCard));
        }
Ejemplo n.º 5
0
        public void PlayerStartingPositionsAreLogged()
        {
            var player1 = new Player("Player 1");
            var player2 = new Player("Player 2");
            var game    = Game.CreateNewGame(10, 10, player1, player2);
            var log     = new JsonMessageLog();

            var command = new StartGameCommand();

            command.Execute(game, log);

            log.AssertMessageTypes(GameMessageType.NewGame, GameMessageType.PlayerAdded, GameMessageType.PlayerAdded);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// The OnGridPropertyChanged method is called when a property in the Grid model class changes.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OnGridPropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     try
     {
         StartGameCommand.RaiseCanExecuteChanged();
         StopGameCommand.RaiseCanExecuteChanged();
         StepGameCommand.RaiseCanExecuteChanged();
         ResetGameCommand.RaiseCanExecuteChanged();
     }
     catch (Exception ex)
     {
         throw new Exception("LangtonsAntViewModel.OnGridPropertyChanged(object sender, PropertyChangedEventArgs e): " + ex.ToString());
     }
 }
Ejemplo n.º 7
0
        public void StartGame()
        {
            var game = new Game
            {
                State   = new LobbyState(),
                Players =
                {
                    new Player
                    {
                        User = new User
                        {
                            Id = 1
                        },
                        IsOwner = true,
                        Deck    = new Deck
                        {
                            BattleKingCard = new DeckCard
                            {
                                Card = new Card()
                            }
                        }
                    },
                    new Player
                    {
                        User = new User
                        {
                            Id = 2
                        },
                        Deck = new Deck
                        {
                            BattleKingCard = new DeckCard
                            {
                                Card = new Card()
                            }
                        }
                    }
                }
            };
            var command = new StartGameCommand
            {
                SenderUserId = 1
            };

            command.Execute(game);

            Assert.IsType(typeof(RedrawState), command.NextState);
            Assert.True(game.Players.All(p => p.CanUseBattleKingCard));
            Assert.NotNull(game.Players.SingleOrDefault(p => p.IsRoundStarter));
        }
Ejemplo n.º 8
0
 /// <summary>
 /// The OnGameOfLifePropertyChanged method is called when a property in the GameOfLife model class changes.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OnGameOfLifePropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     try
     {
         StartGameCommand.RaiseCanExecuteChanged();
         StopGameCommand.RaiseCanExecuteChanged();
         StepGameCommand.RaiseCanExecuteChanged();
         ResetGameCommand.RaiseCanExecuteChanged();
         ToggleCellStateCommand.RaiseCanExecuteChanged();
     }
     catch (Exception ex)
     {
         throw new Exception("ConwaysGameOfLifeViewModel.OnGameOfLifePropertyChanged(object sender, PropertyChangedEventArgs e): " + ex.ToString());
     }
 }
Ejemplo n.º 9
0
        public void StartGameWithScoiataelFaction()
        {
            var game = new Game
            {
                State   = new LobbyState(),
                Players =
                {
                    new Player
                    {
                        User = new User
                        {
                            Id = 1
                        },
                        IsOwner = true,
                        Deck    = new Deck
                        {
                            Faction        = GwintFaction.Scoiatael,
                            BattleKingCard = new DeckCard
                            {
                                Card = new Card()
                            }
                        }
                    },
                    new Player
                    {
                        User = new User
                        {
                            Id = 2
                        },
                        Deck = new Deck
                        {
                            BattleKingCard = new DeckCard
                            {
                                Card = new Card()
                            }
                        }
                    }
                }
            };
            var command = new StartGameCommand
            {
                SenderUserId = 1
            };

            command.Execute(game);

            Assert.IsType(typeof(PickStartingPlayerState), command.NextState);
        }
Ejemplo n.º 10
0
        public static void Main(string[] args)
        {
            using (var dispatcher = new BlackJackDispatcher(new EventBusConfig()))
            {
                var result = Console.ReadLine();

                if (result == "startgame")
                {
                    var gsc = new StartGameCommand()
                    {
                    };
                    BlackJackDomainService bjds = new BlackJackDomainService();
                    bjds.StartGame(gsc);
                }
                Console.ReadKey();
            }
        }
Ejemplo n.º 11
0
        public void Handle(StartGameCommand command)
        {
            if (IsStarted)
            {
                throw new InvalidOperationException("The game is start.");
            }

            Player = new Player(
                _settings.InitialHealth,
                _settings.InitialMaxHealth,
                _settings.InitialPower,
                _settings.InitialCoins,
                _eventBus);

            IsStarted = true;

            _eventBus.Publish(new GameStartedEvent());
        }
Ejemplo n.º 12
0
        private ICommand GetStartGameCommand(string[] parameters)
        {
            if (parameters.Length < 4)
            {
                throw new NotEnoughParametersForCommandException("Not enough parameters for command");
            }

            if (int.TryParse(parameters[1], out int fieldSize) == false)
            {
                throw new InvalidMapSizeException("You entered invalid map size. Map size should be higher than 2 and lower than 10.");
            }

            Level     level;
            FrameType frameType;
            bool      isRandomActionsEnabled = false;

            if (fieldSize <= 2 || fieldSize >= 10)
            {
                throw new InvalidMapSizeException("You entered invalid map size. Map size should be higher than 2 and lower than 10.");
            }

            if (Enum.TryParse <Level>(parameters[2], true, out level) == false)
            {
                throw new InvalidLevelException("You entered invalid level. Available levels are 'Easy', 'Medium' and 'Hard'");
            }

            if (Enum.TryParse <FrameType>(parameters[3], true, out frameType) == false)
            {
                throw new InvalidFrameTypeException("You entered invalid frame type. Available types are 'Normal' and 'Boarded'");
            }

            if (parameters.Length >= 5) // optional parameter
            {
                if (bool.TryParse(parameters[4], out isRandomActionsEnabled) == false)
                {
                    throw new InvalidRandomActionsParameterException("You entered invalid value for activating random actions. Only 'true' or 'false' available");
                }
            }

            GameSettings settings = new GameSettings(fieldSize, level, frameType, isRandomActionsEnabled);
            ICommand     command  = new StartGameCommand(_gameCreator, _manipulator, settings);

            return(command);
        }
Ejemplo n.º 13
0
        public void TwoPlayersStartInOppositeCorners()
        {
            var player1 = new Player("Player 1");
            var player2 = new Player("Player 2");
            var game    = Game.CreateNewGame(10, 10, player1, player2);
            var log     = new JsonMessageLog();

            var command = new StartGameCommand();

            command.Execute(game, log);

            var pos1 = player1.Position;
            var pos2 = player2.Position;

            Assert.AreEqual(0, pos1.X);
            Assert.AreEqual(0, pos1.Y);

            Assert.AreEqual(9, pos2.X);
            Assert.AreEqual(9, pos2.Y);
        }
        public Round StartGame(StartGameCommand command)
        {
            Dealer dealer = new Dealer();
            Round  round  = new Round()
            {
                Dealer = dealer,
                Player = new Player()
                {
                    Hand = new PlayerHand()
                    {
                        CardsInHand = new List <Card>()
                        {
                            dealer.Hit(), dealer.Hit()
                        }
                    }
                },
            };
            GameStartedEvent gse = new GameStartedEvent()
            {
                round = round, RoutingKey = "blabla", GUID = Guid.NewGuid().ToString(), TimeStamp = DateTime.UtcNow
            };

            // Publish event
            using (var eventPublishService =
                       new EventPublisher(
                           new EventBusConfig()
            {
                QueueName = "web-app-listener-queue",
                Host = "localhost"
            })
                   )
            {
                eventPublishService.Publish(gse);
            }

            return(round);
        }
        public void ParseCommand(int action)
        {
            switch (action)
            {
            case 1:
                ICommand startGameCommand = new StartGameCommand(this.gameService, this.userService,
                                                                 this.boardOutputService, this.tetrominoService, this.currentTetrominoService,
                                                                 this.boardService);
                startGameCommand.Execute();
                break;

            case 2:
                ICommand howToPlayCommand = new HowToPlayCommand(this.menuService);
                howToPlayCommand.Execute();
                break;

            case 3:
                ICommand showScoresCommand = new ShowScoresCommand(this.menuService, this.userService);
                showScoresCommand.Execute();
                break;

            case 4:
                ICommand showHighScoresCommand = new ShowHighScoresCommand(this.menuService, this.highScoreService);
                showHighScoresCommand.Execute();
                break;

            case 5:
                ICommand showCreditsCommand = new ShowCreditsCommand(this.menuService);
                showCreditsCommand.Execute();
                break;

            case 6:
                Environment.Exit(0);
                break;
            }
        }
 private void updateButtonCanExecute()
 {
     StartGameCommand.RaiseCanExecuteChanged();
     StopGameCommand.RaiseCanExecuteChanged();
     PauseGameCommand.RaiseCanExecuteChanged();
 }
Ejemplo n.º 17
0
        public async Task <ActionResult> StartGame(StartGameCommand command)
        {
            var lobby = await _mediator.Send(command);

            return(Ok());
        }
Ejemplo n.º 18
0
 public async Task <IActionResult> StartGame(StartGameCommand command)
 {
     return(Ok(await _mediator.Send(command)));
 }