Exemplo n.º 1
0
        public void Is_Success()
        {
            var _apiService = Substitute.For <IApiService>();

            _apiService.PostApi <BoardQueryDto, BoardQueryResp>(null)
            .ReturnsForAnyArgs(new BoardQueryResp()
            {
                IsSuccess = true, Items = new List <BoardQueryRespItem>()
            });

            var _boardDa = Substitute.For <IBoardDa>();

            _boardDa.GetBoardData(new List <string>()).ReturnsForAnyArgs(new List <BoardDto>());

            IBoardLogic boardLogic = new BoardLogic(null, _boardDa, _apiService);

            var boardList = boardLogic.GetBoardList(null, 0).Result;

            Assert.IsTrue(boardList.IsSuccess);
        }
Exemplo n.º 2
0
        public void FinallyMoveReverterTest(int x1, int y1, int x2, int y2)
        {
            // Arrange
            var board      = new Board(true);
            var boardLogic = new BoardLogic(true);
            var expected   = board.ChessBoard;

            PieceBase[,] BackupBoard = board.CloneChessBoard();
            // Act
            boardLogic.TurnChange(board);
            if (boardLogic.LogicMove(x1, y1, x2, y2, board))
            {
                boardLogic.TurnChange(board);
                board.ChessBoard = BackupBoard; //vuelve al board clonado
            }
            var result = board.ChessBoard;

            // Assert
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 3
0
        public void xPiecesInSuccession_4Horizontal_false()
        {
            // Arrange
            BoardLogic bl = new BoardLogic();
            Board      b  = new Board(19, 19);

            Cell[,] mat     = b.getBoard();
            mat[1, 1].color = 1; // Adding white(1) piece to row 1 col 1
            mat[1, 2].color = 1;
            mat[1, 3].color = 1;
            mat[1, 4].color = 2;
            int startRow = 1;
            int startCol = 1;

            // Act
            bool isTesera = bl.xPiecesInSuccession(mat, startRow, startCol, 1, 4);

            // Assert
            Assert.AreEqual(false, isTesera);
        }
Exemplo n.º 4
0
        public void xPiecesInSuccession_4Vertical_true()
        {
            // Arrange
            BoardLogic bl = new BoardLogic();
            Board      b  = new Board(19, 19);

            Cell[,] mat     = b.getBoard();
            mat[1, 1].color = 1; // Adding white(1) piece to row 1 col 1
            mat[2, 1].color = 1;
            mat[3, 1].color = 1;
            mat[4, 1].color = 1;
            int startRow = 1;
            int startCol = 1;

            // Act
            bool isTesera = bl.xPiecesInSuccession(mat, startRow, startCol, 1, 4);

            // Assert
            Assert.AreEqual(true, isTesera);
        }
Exemplo n.º 5
0
        public GameController BuildGameControllerBlackPlayerWithJumps()
        {
            PieceLogic[] testPieces = new PieceLogic[24];
            int[,] locations = new int[24, 2] {
                { 0, 0 }, { 0, 2 }, { 0, 4 }, { 0, 6 }, { 1, 1 }, { 1, 3 }
                , { 1, 5 }, { 1, 7 }, { 2, 0 }, { 3, 3 }, { 2, 4 }, { 3, 5 }, { 4, 2 }, { 4, 4 }, { 4, 6 }, { 5, 7 }, { 6, 0 }, { 6, 2 }, { 6, 4 }, { 6, 6 }, { 7, 1 }, { 7, 3 }, { 7, 5 }, { 7, 7 }
            };
            for (int i = 0; i < 12; i++)
            {
                testPieces[i] = new PieceLogic(i, "Red");
                testPieces[i].SetLocation(new int[] { locations[i, 0], locations[i, 1] });
                testPieces[i + 12] = new PieceLogic(i + 12, "Black");
                testPieces[i + 12].SetLocation(new int[] { locations[i + 12, 0], locations[i + 12, 1] });
            }
            BoardLogic     testBoard = new BoardLogic(testPieces);
            GameController testGc    = new GameController(2, "Black", testBoard);

            testGc.SetGameStatus("Ongoing");
            return(testGc);
        }
Exemplo n.º 6
0
    protected override void Execute(List <GameEntity> entities)
    {
        var board = _contexts.game.gameBoard;

        for (int column = 0; column < board.columns; column++)
        {
            for (int row = 1; row < board.rows; row++)
            {
                var position             = new Vector2(column, row);
                var entitiesWithPosition = BoardLogic.GetEntitiesWithPosition(_contexts.game, position);
                foreach (var entity in entitiesWithPosition)
                {
                    if (entity != null && entity.isMovable)
                    {
                        MoveDown(entity, position);
                    }
                }
            }
        }
    }
Exemplo n.º 7
0
        public override bool LogicMove(int x1, int y1, int x2, int y2, Board board, BoardLogic boardLogic)
        {
            if (boardLogic.IsInRange(x1, y1, x2, y2))
            {
                PieceBase piece = board.GetPiece(x1, y1);
                if (!board.IsEmpty(x1, y1) && piece.IsValidMove(x1, y1, x2, y2, board.Turn, board))
                {
                    if (board.IsEmpty(x2, y2) && !boardLogic.CantMoveIsCheck(x1, y1, x2, y2, board))
                    {
                        if ((Math.Abs(x2 - x1) == Math.Abs(y2 - y1) && boardLogic.IsDiagonalEmpty(x1, y1, x2, y2, board)))
                        {
                            board.Move(x1, y1, x2, y2);
                            return(true);
                        }
                        if ((x2 == x1 || y2 == y1) && boardLogic.IsLineEmpty(x1, y1, x2, y2, board))
                        {
                            board.Move(x1, y1, x2, y2);
                            return(true);
                        }
                    }

                    if (!board.IsEmpty(x2, y2) && !boardLogic.IsAlly(x1, y1, x2, y2, board) && !boardLogic.CantMoveIsCheck(x1, y1, x2, y2, board))
                    {
                        if ((Math.Abs(x2 - x1) == Math.Abs(y2 - y1) && boardLogic.IsDiagonalEmpty(x1, y1, x2, y2, board)))
                        {
                            board.Remove(x2, y2);
                            board.Move(x1, y1, x2, y2);
                            return(true);
                        }
                        if ((x2 == x1 || y2 == y1) && boardLogic.IsLineEmpty(x1, y1, x2, y2, board))
                        {
                            board.Remove(x2, y2);
                            board.Move(x1, y1, x2, y2);
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Exemplo n.º 8
0
        public void xPiecesInSuccession_winVertical_false()
        {
            // Arrange
            BoardLogic bl = new BoardLogic();
            Board      b  = new Board(19, 19);

            Cell[,] mat     = b.getBoard();
            mat[0, 0].color = 1; // Adding white(1) piece to row 0 col 0
            mat[1, 0].color = 1;
            mat[2, 0].color = 1;
            mat[3, 0].color = 1;
            mat[4, 0].color = 2;
            int startRow = 0;
            int startCol = 0;

            // Act
            bool isWin = bl.xPiecesInSuccession(mat, startRow, startCol, 1, 5, true);

            // Assert
            Assert.AreEqual(false, isWin);
        }
Exemplo n.º 9
0
        public void xPiecesInSuccession_winDiagonal_false()
        {
            // Arrange
            BoardLogic bl = new BoardLogic();
            Board      b  = new Board(19, 19);

            Cell[,] mat     = b.getBoard();
            mat[1, 1].color = 1; // Adding white(1) piece to row 1 col 1
            mat[2, 2].color = 1;
            mat[3, 3].color = 1;
            mat[4, 4].color = 1;
            mat[5, 5].color = 2;
            int startRow = 1;
            int startCol = 1;

            // Act
            bool isWin = bl.xPiecesInSuccession(mat, startRow, startCol, 1, 5, true);

            // Assert
            Assert.AreEqual(false, isWin);
        }
Exemplo n.º 10
0
        public void xPiecesInSuccession_winHorizontal_true()
        {
            // Arrange
            BoardLogic bl = new BoardLogic();
            Board      b  = new Board(19, 19);

            Cell[,] mat     = b.getBoard();
            mat[0, 0].color = 1; // Adding white(1) piece to row 0 col 0
            mat[0, 1].color = 1;
            mat[0, 2].color = 1;
            mat[0, 3].color = 1;
            mat[0, 4].color = 1;
            int startRow = 0;
            int startCol = 0;

            // Act
            bool isWin = bl.xPiecesInSuccession(mat, startRow, startCol, 1, 5, true);

            // Assert
            Assert.AreEqual(true, isWin);
        }
    //Prints the board to Debug Log (for debug purposes)
    public void printCurrentBoard()
    {
        string board = "";

        for (int i = 0; i <= 7; i++)
        {
            for (int j = 0; j <= 7; j++)
            {
                if (chessGameBoard[i, j] != null)
                {
                    board += chessGameBoard[i, j].ToString();
                }
                else
                {
                    board += " - ";
                }
            }
            board += "\n";
        }
        Debug.Log(board);
    }
Exemplo n.º 12
0
        public override bool LogicMove(int x1, int y1, int x2, int y2, Board board, BoardLogic boardLogic)
        {
            if (boardLogic.IsInRange(x1, y1, x2, y2))
            {
                PieceBase piece = board.GetPiece(x1, y1);
                if (!board.IsEmpty(x1, y1) && piece.IsValidMove(x1, y1, x2, y2, board.Turn, board))
                {
                    if (boardLogic.IsPawnCapturing(x1, x2) && !board.IsEmpty(x2, y2) && !boardLogic.CantMoveIsCheck(x1, y1, x2, y2, board))
                    {
                        board.Remove(x2, y2);
                        board.Move(x1, y1, x2, y2);
                        if (boardLogic.Promoting(y2))
                        {
                            board.Promotion(x2, y2, board.Turn);
                        }
                        return(true);
                    }

                    if (boardLogic.IsPawnCapturing(x1, x2) && boardLogic.EnPassant(x1, y1, x2, y2, board) && !boardLogic.CantMoveIsCheck(x1, y1, x2, y2, board))
                    {
                        board.RemoveCapturePassant(x1, y1, x2, y2);
                        board.Move(x1, y1, x2, y2);
                        return(true);
                    }

                    if (!boardLogic.IsPawnCapturing(x1, x2) && board.IsEmpty(x2, y2) && boardLogic.IsLineEmpty(x1, y1, x2, y2, board) && !boardLogic.CantMoveIsCheck(x1, y1, x2, y2, board))
                    {
                        board.Move(x1, y1, x2, y2);
                        boardLogic.UpDateEnPassant(y1, y2, piece, board);
                        if (boardLogic.Promoting(y2))
                        {
                            board.Promotion(x2, y2, board.Turn);
                        }
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 13
0
        public void isCapture_capDiagonal_true()
        {
            // Arrange
            BoardLogic bl = new BoardLogic();
            Board      b  = new Board(19, 19);

            Cell[,] mat     = b.getBoard();
            mat[1, 1].color = 1; // Adding white(1) piece to row 1 col 1
            mat[2, 2].color = 2;
            mat[3, 3].color = 2;
            mat[4, 4].color = 1;
            int lastX    = 3;
            int lastY    = 3;
            int startRow = 4;
            int startCol = 4;

            // Act
            bool isCap = bl.isCapture(ref mat, lastX, lastY, startRow, startCol, 1, true);

            // Assert
            Assert.AreEqual(true, isCap);
        }
Exemplo n.º 14
0
        public void isCapture_capVertical_false()
        {
            // Arrange
            BoardLogic bl = new BoardLogic();
            Board      b  = new Board(19, 19);

            Cell[,] mat     = b.getBoard();
            mat[1, 0].color = 1; // Adding white(1) piece to row 1 col 0
            mat[2, 0].color = 2;
            mat[3, 0].color = 2;
            mat[4, 0].color = 1;
            int lastX    = 3;
            int lastY    = 0;
            int startRow = 3;
            int startCol = 0;

            // Act
            bool isCap = bl.isCapture(ref mat, lastX, lastY, startRow, startCol, 1, true);

            // Assert
            Assert.AreEqual(false, isCap);
        }
Exemplo n.º 15
0
        public void isCapture_capHorizontal_false()
        {
            // Arrange
            BoardLogic bl = new BoardLogic();
            Board      b  = new Board(19, 19);

            Cell[,] mat     = b.getBoard();
            mat[0, 1].color = 1; // Adding white(1) piece to row 0 col 1
            mat[0, 2].color = 2;
            mat[0, 3].color = 2;
            mat[0, 4].color = 1;
            int lastX    = 0;
            int lastY    = 3;
            int startRow = 0;
            int startCol = 3;

            // Act
            bool isCap = bl.isCapture(ref mat, lastX, lastY, startRow, startCol, 1, true);

            // Assert
            Assert.AreEqual(false, isCap);
        }
Exemplo n.º 16
0
        bool IsMirrorPartnerIndex(BoardLogic board, int currentHotIndex, int i, bool isCurrentHotIndex /*for the assert*/)
        {
            bool result = false;

            int mirrorOffsetCount = board.shapeSizes[0];
            int mirrorIndexAt     = currentHotIndex < mirrorOffsetCount ? (currentHotIndex + mirrorOffsetCount) : (currentHotIndex - mirrorOffsetCount);

            if (board.isMirrorLevel && currentHotIndex >= 0 && HasMirrorPartner(board, currentHotIndex, mirrorIndexAt))
            {
                if (currentHotIndex < mirrorOffsetCount)
                {
                    Assert.IsTrue(currentHotIndex + mirrorOffsetCount < GetTotalNumberOfShapeBlocks(board));
                    if ((currentHotIndex + mirrorOffsetCount) == i)
                    {
                        if (isCurrentHotIndex)
                        {
                            Assert.IsTrue(keyStates.isDown(ButtonType.BUTTON_LEFT_MOUSE));
                        }
                        //this would be if you grabbed the 'lower shape' and you want to hightlight the one above
                        result = true;
                    }
                }
                else
                {
                    Assert.IsTrue(currentHotIndex - mirrorOffsetCount >= 0);
                    if ((currentHotIndex - mirrorOffsetCount) == i)
                    {
                        if (isCurrentHotIndex)
                        {
                            Assert.IsTrue(keyStates.isDown(ButtonType.BUTTON_LEFT_MOUSE));
                        }
                        //this would be if you grabbed the 'higher shape'
                        result = true;
                    }
                }
            }
            return(result);
        }
Exemplo n.º 17
0
        public bool StartGame()
        {
            if (!ConnectionLogic.CanStartGame())
            {
                Logger.Get().Error("[GM] Start game conditions not met!");
                return(false);
            }

            Agents = ConnectionLogic.FlushLobby();
            state  = GameMasterState.InGame;
            currentMessageProcessor = GameLogic;
            BoardLogic.StartGame();

            Logger.Get().Info("[GM] Starting game with {count} agents", Agents.Count);
            var messages = GameLogic.GetStartGameMessages();

            foreach (var m in messages)
            {
                SendMessage(m);
            }

            return(true);
        }
Exemplo n.º 18
0
    private bool checkIfMovePossible(int dir)
    {
        if (dir < 0 || dir > 3)
        {
            return(false);
        }

        int[,] numberBoard = new int[4, 4];
        iterateOverBoard((int x, int y) => { numberBoard[x, y] = vizGrid[x, y] != null ? vizGrid[x, y].currentScore : 0; });
        if (dir == 0)
        {
            return(BoardLogic.moveInXDirection(1, numberBoard));
        }
        if (dir == 1)
        {
            return(BoardLogic.moveInYDirection(-1, numberBoard));
        }
        if (dir == 2)
        {
            return(BoardLogic.moveInXDirection(-1, numberBoard));
        }
        return(BoardLogic.moveInYDirection(1, numberBoard));
    }
Exemplo n.º 19
0
        public override bool LogicMove(int x1, int y1, int x2, int y2, Board board, BoardLogic boardLogic)
        {
            if (boardLogic.IsInRange(x1, y1, x2, y2))
            {
                PieceBase piece = board.GetPiece(x1, y1);
                if (!board.IsEmpty(x1, y1) && piece.IsValidMove(x1, y1, x2, y2, board.Turn, board))
                {
                    if (board.IsEmpty(x2, y2) && !boardLogic.CantMoveIsCheck(x1, y1, x2, y2, board))
                    {
                        board.Move(x1, y1, x2, y2);
                        return(true);
                    }
                    if (!board.IsEmpty(x2, y2) && !boardLogic.CantMoveIsCheck(x1, y1, x2, y2, board))
                    {
                        board.Remove(x2, y2);
                        board.Move(x1, y1, x2, y2);
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 20
0
    public BoardLogic CopyBoard()
    {
        BoardLogic boardLogic = new BoardLogic();

        boardLogic.Checkers = CopyCurrentCheckers();
        boardLogic.Turn     = Turn;
        if (AtackingChecker != null)
        {
            boardLogic.AtackingChecker = new Checker
            {
                Color     = AtackingChecker.Color,
                PositionX = AtackingChecker.PositionX,
                PositionY = AtackingChecker.PositionY,
                isQueen   = AtackingChecker.isQueen
            };
            boardLogic.IsMoveAtack = IsMoveAtack;
        }
        boardLogic.delX = delX;
        boardLogic.delY = delY;


        return(boardLogic);
    }
Exemplo n.º 21
0
        public MainWindow()
        {
            // Create logic
            logic      = new MainWindowLogic(this);
            boardLogic = logic.BoardLogic;

            // Create winforms widgets
            InitializeComponent();

            // Get settings
            Load += (s, e) => OnLoad();

            // Save settings on closing
            Closing += (s, e) => SaveSettings();

            // Build context menu
            var numberPicker = new NumberPicker(boardLogic);

            contextMenu = new FreeContextMenuStrip(numberPicker);
            numberPicker.ParentContextMenuStrip = contextMenu;

            // Regain focus when context menu goes away
            contextMenu.Closed += (e, s) => Focus();

            // Create the cells
            CreateCells();

            // Initial state
            buttonUndo.Enabled  = boardLogic.Undo.CanExecute();
            buttonRedo.Enabled  = boardLogic.Redo.CanExecute();
            buttonReset.Enabled = boardLogic.Reset.CanExecute();

            // Listen to logic events
            boardLogic.Undo.CanExecuteChanged  += (s, e) => buttonUndo.Enabled = boardLogic.Undo.CanExecute();
            boardLogic.Redo.CanExecuteChanged  += (s, e) => buttonRedo.Enabled = boardLogic.Redo.CanExecute();
            boardLogic.Reset.CanExecuteChanged += (s, e) => buttonReset.Enabled = boardLogic.Reset.CanExecute();
        }
        public void BoardLogicGetSet()
        {
            PieceLogic[] expectedPieces = new PieceLogic[24];
            for (int i = 0; i < 12; i++)
            {
                PieceLogic p = new PieceLogic(i, "Red");
                expectedPieces[i] = p;
            }
            for (int i = 11; i < 24; i++)
            {
                PieceLogic p = new PieceLogic(i, "Black");
                expectedPieces[i] = p;
            }
            BoardLogic board = new BoardLogic(expectedPieces);

            PieceLogic[] actualPieces = board.GetPieces();

            // test GetPieces
            Assert.AreEqual(expectedPieces, actualPieces);

            for (int i = 0; i < 12; i++)
            {
                PieceLogic p = new PieceLogic(i, "Black");
                expectedPieces[i] = p;
            }
            for (int i = 11; i < 24; i++)
            {
                PieceLogic p = new PieceLogic(i, "Red");
                expectedPieces[i] = p;
            }

            // test SetPieces
            board.SetPieces(expectedPieces);
            actualPieces = board.GetPieces();
            Assert.AreEqual(expectedPieces, actualPieces);
        }
Exemplo n.º 23
0
    public void ClearConnectedType()
    {
        int width  = 3;
        int height = 3;

        int[] boardConnection = new int[]
        {
            0, 1, 1,
            1, 0, 0,
            0, 0, 0
        };
        BoardLogic boardLogic = new BoardLogic(width, height);

        boardLogic.SetBoard(boardConnection, width, height);
        bool canMove = boardLogic.CanMove(0, 1, 0, -1).canMove;

        Assert.AreEqual(true, canMove);
        if (canMove)
        {
            boardLogic.MovePiece(0, 1, 0, -1);
            boardLogic.ClearConnectedType(1, 0, 0);
        }
        Assert.AreEqual(new int[] { -1, -1, -1, 0, 0, 0, 0, 0, 0 }, boardLogic.GetBoard());
    }
Exemplo n.º 24
0
    public void CannotMoveOutsieBoardBounds()
    {
        int width  = 3;
        int height = 3;

        int[] boardConnection = new int[]
        {
            0, 1, 3,
            1, 0, 0,
            0, 0, 0
        };
        BoardLogic boardLogic = new BoardLogic(width, height);

        boardLogic.SetBoard(boardConnection, width, height);
        bool canMove = boardLogic.CanMove(1, 0, 0, -1).canMove;

        Assert.AreEqual(false, canMove);
        canMove = boardLogic.CanMove(0, 0, -1, 0).canMove;
        Assert.AreEqual(false, canMove);
        canMove = boardLogic.CanMove(2, 0, 1, 0).canMove;
        Assert.AreEqual(false, canMove);
        canMove = boardLogic.CanMove(0, 2, 0, 1).canMove;
        Assert.AreEqual(false, canMove);
    }
Exemplo n.º 25
0
        public override bool ValidMovement(BoardLogic.ChessCoordinates startLocation, BoardLogic.ChessCoordinates endLocation)
        {
            ValidMoves.Clear();

            int column = FileLogic.GetColumnFromChar(startLocation.Column).GetHashCode();
            int row    = startLocation.Row;

            if (row - 1 >= 0)
            {
                int goingDown = row;
                while (true)
                {
                    if (goingDown - 1 >= 0)
                    {
                        BoardLogic.ChessCoordinates maybeGood = CheckSpaces(Program.board[column, goingDown - 1], startLocation);
                        if (maybeGood == new BoardLogic.ChessCoordinates('0', -1, null))
                        {
                            break;
                        }
                        else
                        {
                            ValidMoves.Add(maybeGood);
                            goingDown = goingDown - 1;
                            if (shouldStop)
                            {
                                shouldStop = false;
                                break;
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
            if (row + 1 <= 7)
            {
                int goingUp = row;
                while (true)
                {
                    if (goingUp + 1 <= 7)
                    {
                        BoardLogic.ChessCoordinates maybeGood = CheckSpaces(Program.board[column, goingUp + 1], startLocation);
                        if (maybeGood == new BoardLogic.ChessCoordinates('0', -1, null))
                        {
                            break;
                        }
                        else
                        {
                            ValidMoves.Add(maybeGood);
                            goingUp = goingUp + 1;
                            if (shouldStop)
                            {
                                shouldStop = false;
                                break;
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
            if (column - 1 >= 0)
            {
                int goingLeft = column;
                while (true)
                {
                    if (goingLeft - 1 >= 0)
                    {
                        BoardLogic.ChessCoordinates maybeGood = CheckSpaces(Program.board[goingLeft - 1, row], startLocation);
                        Console.WriteLine(maybeGood);
                        if (maybeGood == new BoardLogic.ChessCoordinates('0', -1, null))
                        {
                            break;
                        }
                        else
                        {
                            ValidMoves.Add(maybeGood);
                            goingLeft = goingLeft - 1;
                            if (shouldStop)
                            {
                                shouldStop = false;
                                break;
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
            if (column + 1 <= 7)
            {
                int goingRight = column;
                while (true)
                {
                    if (goingRight + 1 <= 7)
                    {
                        BoardLogic.ChessCoordinates maybeGood = CheckSpaces(Program.board[goingRight + 1, row], startLocation);
                        if (maybeGood == new BoardLogic.ChessCoordinates('0', -1, null))
                        {
                            break;
                        }
                        else
                        {
                            ValidMoves.Add(maybeGood);
                            goingRight = goingRight + 1;
                            if (shouldStop)
                            {
                                shouldStop = false;
                                break;
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
            BoardLogic.ChessCoordinates lookingFor = new BoardLogic.ChessCoordinates(BoardLogic.GetCharFromNumber(FileLogic.GetColumnFromChar(endLocation.Column).GetHashCode()), endLocation.Row, null);

            foreach (var space in ValidMoves)
            {
                if (space == lookingFor)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 26
0
 void Start()
 {
     animator = GetComponent <Animator>();
     board    = GameObject.FindGameObjectWithTag("Board").GetComponent <BoardLogic>();
     game     = GameObject.FindGameObjectWithTag("Game").GetComponent <GameLogic>();
 }
Exemplo n.º 27
0
        public void updateWindmillSide(BoardLogic board)
        {
            bool repeat      = true;
            bool repeatedYet = false;

            while (repeat)
            { //this is for when we get blocked
                repeat = false;
                Assert.IsTrue(this.count <= this.max);
                BoardState stateToSet;
                BoardState staticState = (this.isBomb) ? BoardState.BOARD_EXPLOSIVE : BoardState.BOARD_STATIC;

                int addend = 0;
                if (this.isOut)
                {
                    addend     = 1;
                    stateToSet = staticState;
                }
                else
                {
                    stateToSet = BoardState.BOARD_NULL;
                    addend     = -1;
                }

                bool wasJustFlipped = this.justFlipped;
                if (!this.justFlipped)
                {
                    this.count += addend;
                }
                else
                {
                    this.justFlipped = false;
                }

                if (this.count != 0)
                {
                    BoardState toBoardState = BoardState.BOARD_INVALID;
                    Assert.IsTrue(this.count >= 0 && this.count <= this.max);
                    Vector2 shift  = new Vector2(this.growDir.x * (this.count - 1), this.growDir.y * (this.count - 1));
                    Vector2 newPos = this.pos + shift;

                    toBoardState = board.GetBoardState(newPos);

                    bool settingBlock = (toBoardState == BoardState.BOARD_NULL && stateToSet == staticState);
                    bool isInBounds   = board.InBoardBounds(newPos);
                    bool blocked      = (toBoardState != BoardState.BOARD_NULL && stateToSet == staticState);
                    if (blocked || !isInBounds)
                    {
                        Assert.IsTrue(this.isOut);
                        if (this.count == 1)
                        {
                            Assert.IsTrue(stateToSet != BoardState.BOARD_NULL);
                            this.isOut = true;
                            if (this.tryingToBegin)
                            { //on the second attempt after the shape has moved
                                for (int i = 0; i < this.perpSize; ++i)
                                {
                                    this.growDir = Vector2.Perpendicular(this.growDir);
                                }
                            }
                            this.count         = 0;
                            this.tryingToBegin = true;
                        }
                        else
                        {
                            this.isOut       = false;
                            repeat           = true;
                            this.justFlipped = true;
                            this.count--;
                        }
                    }
                    else
                    {
                        Assert.IsTrue(this.count > 0);
                        Assert.IsTrue(stateToSet != BoardState.BOARD_INVALID);

                        Assert.IsTrue(isInBounds);
                        if (settingBlock || stateToSet == BoardState.BOARD_NULL)
                        {
                            if (stateToSet == BoardState.BOARD_NULL)
                            {
                                Assert.IsTrue(toBoardState == staticState);
                            }
                            board.SetBoardState(newPos, stateToSet, BoardValType.BOARD_VAL_DYNAMIC);
                        }
                    }

                    Assert.IsTrue(this.max > 0);

                    if (this.count == this.max)
                    {
                        if (!wasJustFlipped)
                        {
                            this.isOut       = false;
                            this.justFlipped = true;
                        }
                        else
                        {
                            Assert.IsTrue(!this.isOut);
                        }
                    }
                }
                else
                {
                    Assert.IsTrue(this.count == 0);
                    Assert.IsTrue(!this.isOut);
                    this.isOut = true;
                    for (int i = 0; i < this.perpSize; ++i)
                    {
                        this.growDir = Vector2.Perpendicular(this.growDir);
                    }
                    this.lagTimer.period = this.lagPeriod; //we change from the begin period to the lag period
                    if (!Equals(this.lagTimer.period, 0.0f))
                    {
                        active = false; //we lag for a bit.
                    }
                }

                if (this.count == 0 && !repeatedYet)
                {
                    repeat      = true;
                    repeatedYet = true;
                }
            }
        }
Exemplo n.º 28
0
        public IActionResult BoardTest()
        {
            Board board = BoardLogic.PseudoRandom();

            return(View(board));
        }
Exemplo n.º 29
0
 private bool checkIfGameOver()
 {
     int[,] numberBoard = new int[4, 4];
     iterateOverBoard((int x, int y) => { numberBoard[x, y] = vizGrid[x, y] != null ? vizGrid[x, y].currentScore : 0; });
     return(BoardLogic.checkIfGameOver(numberBoard));
 }
Exemplo n.º 30
0
        public IActionResult Random()
        {
            Board board = BoardLogic.Random();

            return(View("BoardDisplay", board));
        }