예제 #1
0
        private void updateGraphics()
        {
            for (int row = 0; row < r_BoardSize; row++)
            {
                for (int col = 0; col < r_BoardSize; col++)
                {
                    if (r_CheckersLogic.GetCellPieceType(row, col).Equals("O"))
                    {
                        r_CheckersBoard[(row * r_BoardSize) + col].SetImageInSquare(BoardSquare.ePieceType.WhitePawn);
                    }
                    else if (r_CheckersLogic.GetCellPieceType(row, col).Equals("U"))
                    {
                        r_CheckersBoard[(row * r_BoardSize) + col].SetImageInSquare(BoardSquare.ePieceType.WhiteKing);
                    }
                    else if (r_CheckersLogic.GetCellPieceType(row, col).Equals("X"))
                    {
                        r_CheckersBoard[(row * r_BoardSize) + col].SetImageInSquare(BoardSquare.ePieceType.BlackPawn);
                    }
                    else if (r_CheckersLogic.GetCellPieceType(row, col).Equals("K"))
                    {
                        r_CheckersBoard[(row * r_BoardSize) + col].SetImageInSquare(BoardSquare.ePieceType.BlackKing);
                    }
                    else
                    {
                        r_CheckersBoard[(row * r_BoardSize) + col].SetImageInSquare(BoardSquare.ePieceType.Empty);
                    }
                }
            }

            if (boardSquareActive != null)
            {
                boardSquareActive.ReturnSquareToBeActive();
                boardSquareActive = null;
            }
        }
예제 #2
0
        private void boardSquare_Clicked(object sender, EventArgs e)
        {
            BoardSquare clickedSquare = sender as BoardSquare;

            if (clickedSquare != null && clickedSquare.Enabled)
            {
                if (boardSquareActive == null && clickedSquare.SquarePieceType != BoardSquare.ePieceType.Empty)
                {
                    clickedSquare.SquareInAction();
                    boardSquareActive = clickedSquare;
                }
                else if (boardSquareActive != null)
                {
                    if (clickedSquare == boardSquareActive)
                    {
                        clickedSquare.ReturnSquareToBeActive();
                        boardSquareActive = null;
                    }
                    else
                    {
                        makeTurn(clickedSquare);
                    }
                }
            }
        }
예제 #3
0
        private void initializeEmptyBoardSquares()
        {
            bool        v_SquareActive = true;
            int         halfBoardSize  = r_BoardSize / 2;
            BoardSquare boardSquar;

            for (int row = 0; row < r_BoardSize; row++)
            {
                for (int col = 0; col < r_BoardSize; col++)
                {
                    if ((row % 2 == 0 && col % 2 == 0) || (row % 2 == 1 && col % 2 == 1))
                    {
                        boardSquar = new BoardSquare(BoardSquare.ePieceType.Empty, !v_SquareActive, row, col);
                        r_CheckersBoard.Add(boardSquar);
                        this.Controls.Add(r_CheckersBoard[(row * r_BoardSize) + col]);
                    }
                    else
                    {
                        boardSquar = new BoardSquare(BoardSquare.ePieceType.Empty, v_SquareActive, row, col);
                        r_CheckersBoard.Add(boardSquar);
                        this.Controls.Add(r_CheckersBoard[(row * r_BoardSize) + col]);
                    }

                    addSquareToClick(row, col);
                }
            }
        }
예제 #4
0
        private void initializeBoard()
        {
            initializeEmptyBoardSquares();

            bool        v_SquareActive = true;
            int         halfBoardSize  = r_BoardSize / 2;
            BoardSquare boardSquar;

            for (int row = 0; row < r_BoardSize; row++)
            {
                for (int col = 0; col < r_BoardSize; col++)
                {
                    if ((row >= halfBoardSize + 1) && ((row % 2 == 0 && col % 2 == 1) || (row % 2 == 1 && col % 2 == 0)))
                    {
                        r_CheckersBoard[(row * r_BoardSize) + col].Visible = false;
                        boardSquar = new BoardSquare(BoardSquare.ePieceType.BlackPawn, v_SquareActive, row, col);
                        r_CheckersBoard[(row * r_BoardSize) + col] = boardSquar;
                        this.Controls.Add(r_CheckersBoard[(row * r_BoardSize) + col]);
                        addSquareToClick(row, col);
                    }
                    else if ((row < halfBoardSize - 1) && ((row % 2 == 0 && col % 2 == 1) || (row % 2 == 1 && col % 2 == 0)))
                    {
                        r_CheckersBoard[(row * r_BoardSize) + col].Visible = false;
                        boardSquar = new BoardSquare(BoardSquare.ePieceType.WhitePawn, v_SquareActive, row, col);
                        r_CheckersBoard[(row * r_BoardSize) + col] = boardSquar;
                        this.Controls.Add(r_CheckersBoard[(row * r_BoardSize) + col]);
                        addSquareToClick(row, col);
                    }
                }
            }
        }
예제 #5
0
        private void humanTurn(BoardSquare i_ClickedSquare)
        {
            if (checkIsValidTurnAndMove(i_ClickedSquare.SquareRow, i_ClickedSquare.SquareCol) && isItEndOfGame())
            {
                handleEndOfGame();
            }

            updateCurrentTurnLabel();
        }
예제 #6
0
        private void inValidMessageBox()
        {
            string messageBox = string.Format(
                @"Invalid move!
Please try again.");

            MessageBox.Show(messageBox, this.Text);
            boardSquareActive.ReturnSquareToBeActive();
            boardSquareActive = null;
        }
예제 #7
0
        private void makeTurn(BoardSquare i_ClickedSquare)
        {
            humanTurn(i_ClickedSquare);

            if (!r_IsPlayer2Mode)
            {
                r_Timer.Start();
            }

            updateGraphics();
        }
예제 #8
0
        public GameForm(int i_BoardSize, bool i_IsPlayer2Mode, string i_Player1Name, string i_Player2Name)
        {
            r_BoardSize            = i_BoardSize;
            r_CheckersLogic        = new CheckersGame(r_BoardSize);
            r_IsPlayer2Mode        = i_IsPlayer2Mode;
            r_Player1Name          = i_Player1Name;
            r_Player2Name          = i_Player2Name;
            r_CheckersBoard        = new List <BoardSquare>(r_BoardSize * r_BoardSize);
            this.BackColor         = Color.FromArgb(40, 79, 79);
            this.boardSquareActive = null;
            r_CheckersLogic.StartGame(r_Player1Name, r_Player2Name);
            createGame();

            r_Timer = new Timer();
            initializeTimer();

            InitializeComponent();
        }