Exemple #1
0
        private void updateBoardGraphics()
        {
            for (int rows = 0; rows < r_LogicUnit.Board.Size; rows++)
            {
                for (int cols = 0; cols < r_LogicUnit.Board.Size; cols++)
                {
                    if (r_LogicUnit.Board.GameBoard[rows, cols] == r_LogicUnit.Board.PlayerOneSign)
                    {
                        r_CheckersBoard[(rows * r_LogicUnit.Board.Size) + cols].SetSquareImage(BoardSquare.eBoardSquareType.WhitePawn);
                    }
                    else if (r_LogicUnit.Board.GameBoard[rows, cols] == r_LogicUnit.Board.PlayerOneKingSign)
                    {
                        r_CheckersBoard[(rows * r_LogicUnit.Board.Size) + cols].SetSquareImage(BoardSquare.eBoardSquareType.WhiteKing);
                    }
                    else if (r_LogicUnit.Board.GameBoard[rows, cols] == r_LogicUnit.Board.PlayerTwoSign)
                    {
                        r_CheckersBoard[(rows * r_LogicUnit.Board.Size) + cols].SetSquareImage(BoardSquare.eBoardSquareType.BlackPawn);
                    }
                    else if (r_LogicUnit.Board.GameBoard[rows, cols] == r_LogicUnit.Board.PlayerTwoKingSign)
                    {
                        r_CheckersBoard[(rows * r_LogicUnit.Board.Size) + cols].SetSquareImage(BoardSquare.eBoardSquareType.BlackKing);
                    }
                    else
                    {
                        r_CheckersBoard[(rows * r_LogicUnit.Board.Size) + cols].SetSquareImage(BoardSquare.eBoardSquareType.None);
                    }
                }
            }

            if (boardSquareActiveSquare != null)
            {
                boardSquareActiveSquare.SetInActive();
                boardSquareActiveSquare = null;
            }
        }
Exemple #2
0
 private void handleHumanTurn(BoardSquare i_ClickedSquare)
 {
     // check if the move is legal, if yes preform it
     if (checkIfValidTurnAndPreformIt(i_ClickedSquare.Col, i_ClickedSquare.Row) == true)
     {
         // check if either player has won, lost or its a tie
         manageTasksBeforeNextTurn();
     }
 }
Exemple #3
0
 public GameForm(int i_BoardSize, bool i_Player2Enable, string i_Player1Name, string i_Player2Name)
 {
     StartPosition                = FormStartPosition.CenterScreen;
     this.FormBorderStyle         = FormBorderStyle.Fixed3D;
     this.MaximizeBox             = false;
     this.Text                    = "Damka";
     this.ShowIcon                = false;
     this.boardSquareActiveSquare = null;
     r_LogicUnit                  = new LogicUnit(i_BoardSize);
     initializeLogicUnit(i_Player2Enable, i_Player1Name, i_Player2Name);
     r_CheckersBoard = new List <BoardSquare>(i_BoardSize * i_BoardSize);
     createGameFrame(i_BoardSize);
     this.BackColor   = Color.NavajoWhite;
     r_Timer          = new Timer();
     r_Timer.Interval = 400;
     r_Timer.Tick    += timerTick;
 }
Exemple #4
0
        private bool checkIfValidTurnAndPreformIt(int i_ColDestination, int i_RowDestination)
        {
            bool isValidTurn = false;

            CheckersLogic.Point startingPoint    = new CheckersLogic.Point(boardSquareActiveSquare.Row, boardSquareActiveSquare.Col);
            CheckersLogic.Point destinationPoint = new CheckersLogic.Point(i_RowDestination, i_ColDestination);
            if (r_LogicUnit.PreformMove(startingPoint, destinationPoint) == true)
            {
                isValidTurn = true;
            }
            else
            {
                MessageBox.Show(
                    @"Invalid move!
Please try again.",
                    this.Text);
                boardSquareActiveSquare.SetInActive();
                boardSquareActiveSquare = null;
            }

            return(isValidTurn);
        }
Exemple #5
0
        private void boardSquare_Clicked(object sender, EventArgs e)
        {
            BoardSquare clickedSquare = sender as BoardSquare;

            if (clickedSquare.Enabled == true)
            {
                if (boardSquareActiveSquare == null && clickedSquare.BoardSquareType != BoardSquare.eBoardSquareType.None)
                {   // board has no active square
                    clickedSquare.SetActive();
                    boardSquareActiveSquare = clickedSquare;
                }
                else if (boardSquareActiveSquare != null)
                {
                    // board has an active square, check if its a move or we click on the same square again to inactive
                    if (clickedSquare == boardSquareActiveSquare)
                    {
                        clickedSquare.SetInActive();
                        boardSquareActiveSquare = null;
                    }
                    else
                    {
                        // if we got to here, that means the user wanted to make a move
                        // Human turn
                        handleHumanTurn(clickedSquare);

                        // Initialize the timer before computer turn
                        if (r_LogicUnit.Mode == LogicUnit.eGameMode.PlayerVsComputer)
                        {
                            r_Timer.Start();
                        }

                        // update the boards graphics
                        updateBoardGraphics();
                    }
                }
            }
        }