Ejemplo n.º 1
0
        public GameStatusResponse GetGameStatus(string gameId)
        {
            var gameStatus = GameKeeper.GetGameState(gameId);
            var response   = new GameStatusResponse(gameStatus);

            return(response);
        }
Ejemplo n.º 2
0
 public void GettingInvalidGameStateReturnsNull()
 {
     Assert.Throws <KeyNotFoundException>(() =>
     {
         var gameState = GameKeeper.GetGameState("bogusId");
     });
 }
Ejemplo n.º 3
0
        public void MajorDiagonalWinRegistersProperly()
        {
            /*   |1| | | |
             *   |0|1| |0|
             *   |1|0|1|0|
             *   |0|1|0|1|
             * */

            var newGameId = GameKeeper.AddGame(4, 4, players);
            var move1     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 0));
            var move2     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 1));
            var move3     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 2));
            var move4     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 3));
            var move5     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 1));
            var move6     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 0));
            var move7     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 3));
            var move8     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 2));
            var move9     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 0));
            var move10    = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 1));
            var move11    = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 3));

            var beforeMoveGameState = GameKeeper.GetGameState(newGameId);
            var move12             = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 0));
            var afterMoveGameState = GameKeeper.GetGameState(newGameId);

            Assert.AreEqual(Game.GameStates.IN_PROGRESS, beforeMoveGameState.State);
            Assert.IsNull(beforeMoveGameState.Winner);
            Assert.AreEqual(Game.GameStates.DONE, afterMoveGameState.State);
            Assert.AreEqual(players[1], afterMoveGameState.Winner);
        }
Ejemplo n.º 4
0
        public void CanGetGameState()
        {
            var gameId1   = GameKeeper.AddGame(4, 4, players);
            var gameState = GameKeeper.GetGameState(gameId1);

            Assert.IsNotNull(gameState);
            Assert.AreEqual(Game.GameStates.IN_PROGRESS, gameState.State);
            Assert.IsNull(gameState.Winner);
            Assert.AreEqual(players, gameState.Players);
        }
Ejemplo n.º 5
0
        public void PlayerCanQuitEvenWhenNotThatPlayersTurn()
        {
            var newGameId = GameKeeper.AddGame(4, 4, players);
            var move1     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 0));

            var beforeMoveGameState = GameKeeper.GetGameState(newGameId);
            var move2 = GameKeeper.RegisterMove(newGameId, new QuitMove(players[0]));
            var afterMoveGameState = GameKeeper.GetGameState(newGameId);

            Assert.AreEqual(Game.GameStates.IN_PROGRESS, beforeMoveGameState.State);
            Assert.IsNull(beforeMoveGameState.Winner);
            Assert.AreEqual(Game.GameStates.DONE, afterMoveGameState.State);
            Assert.AreEqual(players[1], afterMoveGameState.Winner);     // the player that didn't quit is the winner
        }
Ejemplo n.º 6
0
        public void RowWinRegistersProperly()
        {
            var newGameId = GameKeeper.AddGame(4, 4, players);
            var move1     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 0));
            var move2     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 0));
            var move3     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 1));
            var move4     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 1));
            var move5     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 2));
            var move6     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 2));

            // each player should have 3 tokens on the board - player 0 in column 3 should win with one more token there...

            var beforeMoveGameState = GameKeeper.GetGameState(newGameId);
            var move7 = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 3));
            var afterMoveGameState = GameKeeper.GetGameState(newGameId);

            Assert.AreEqual(Game.GameStates.IN_PROGRESS, beforeMoveGameState.State);
            Assert.IsNull(beforeMoveGameState.Winner);
            Assert.AreEqual(Game.GameStates.DONE, afterMoveGameState.State);
            Assert.AreEqual(players[0], afterMoveGameState.Winner);
        }