Exemple #1
0
        public void UndoTest_ShouldUndo_CanUndo()
        {
            var movesRecorder = new MovesRecorder();
            var gridMapInit   = new GridMock[9];
            var shouldUndo    = true;
            var gameManager   = new GameManagerMockUp();

            for (int i = 0; i < gridMapInit.Length; i++)
            {
                gridMapInit[i] = new GridMock();
                movesRecorder.movesRecorder.Push(i);
            }
            gameManager.UndoLastMoves(movesRecorder, gridMapInit, shouldUndo);
            for (int j = 0; j < gridMapInit.Length; j++)
            {
                if (j < 7)
                {
                    Assert.AreEqual(gridMapInit[j].PlayerID, 0);
                }
                else
                {
                    Assert.AreEqual(gridMapInit[j].PlayerID, -1);
                }
            }
        }
Exemple #2
0
        public void UndoTest_ShouldUndo_CanNotUndo()
        {
            var movesRecorder = new MovesRecorder();
            var gridMapInit   = new GridMock[9];
            var shouldUndo    = true;
            var gameManager   = new GameManagerMockUp();

            for (int i = 0; i < gridMapInit.Length; i++)
            {
                gridMapInit[i] = new GridMock();
            }
            Assert.IsFalse(gameManager.UndoLastMoves(movesRecorder, gridMapInit, shouldUndo));
        }
Exemple #3
0
    public bool CheckIfGameEnded(MovesRecorder movesRecord, Solutions solutions, Grid[,] gridMap, Grid[] gridMapInit, GameEvent gameEvent)
    {
        var currTurn = Players.CurrentPlayer;

        if (movesRecord.movesRecorder.Count > 4 && solutions.CheckIfGameWon(gridMap)) // one of the players won.
        {
            gameEvent.FireEvent("EndGame");
            Debug.Log("game has ended!, the winner is player" + (currTurn));
            return(true);
        }
        if (movesRecord.movesRecorder.Count == gridMapInit.Length) // draw.
        {
            gameEvent.FireEvent("EndGame");
            Debug.Log("game has ended with a draw!");
            return(true);
        }
        return(false);
    }
Exemple #4
0
    public bool UndoLastMoves(MovesRecorder movesRecorder, GridMock[] gridMapInit, bool shouldUndo)
    {
        var lastMove     = movesRecorder.movesRecorder;
        var undoSucceded = false;

        if (lastMove.Count > 0 && shouldUndo)
        {
            gridMapInit[lastMove.Pop()].ResetGridSlot();
            gridMapInit[lastMove.Pop()].ResetGridSlot();
            undoSucceded = true;
        }
        else if (lastMove.Count == 1 && shouldUndo)
        {
            gridMapInit[lastMove.Pop()].ResetGridSlot();
            undoSucceded = true;
        }
        return(undoSucceded);
    }
Exemple #5
0
        public void CheckIfGameDraw()
        {
            var _gridMap       = new Grid[3, 3];
            var gridMapInit    = new Grid[9];
            var _solutions     = new Solutions();
            var _gameManager   = new GameManagerMockUp();
            var _movesRecorder = new MovesRecorder();
            var _gameEvent     = new GameEvent();
            var index          = 0;

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    _gridMap[i, j]          = new Grid();
                    _gridMap[i, j].PlayerID = index;
                    index++;
                }
            }
            Assert.IsFalse(_gameManager.CheckIfGameEnded(_movesRecorder, _solutions, _gridMap, gridMapInit, _gameEvent));
        }