Example #1
0
 private void ResetBoards()
 {
     m_GameBoard.InitializeBoard();
     m_GameState       = GameState.ContinuePlaying;
     currentPlayerCoin = Board.eBoardSquare.Player1;
     matchOver         = false;
 }
Example #2
0
        public FormConnectFourGameBoard()
        {
            InitializeComponent();
            r_CoinImageBoard         = new List <List <BoardCell> >();
            r_ColumnButtons          = new List <ColButton>();
            m_GameLogic              = new ConnectFourGameLogic();
            r_GameSettingConnectFour = new FormGameSettings();
            r_GameSettingConnectFour.ShowDialog();
            m_numOfRows       = r_GameSettingConnectFour.GameSettings.Rows;
            m_numOfCols       = r_GameSettingConnectFour.GameSettings.Cols;
            m_Player1Name     = r_GameSettingConnectFour.GameSettings.Player1Name;
            m_Player2Name     = r_GameSettingConnectFour.GameSettings.Player2Name;
            matchOver         = false;
            m_Player1Score    = 0;
            m_Player2Score    = 0;
            currentPlayerCoin = Board.eBoardSquare.Player1;
            MaximizeBox       = true;
            FormBorderStyle   = FormBorderStyle.FixedSingle;
            StartPosition     = FormStartPosition.CenterScreen;
            m_GameBoard       = new Board(m_numOfRows, m_numOfCols);
            m_GameBoard.InitializeBoard();
            initlizeControls(m_Player1Name, m_Player2Name, m_numOfRows, m_numOfCols);

            m_GameState = GameState.ContinuePlaying;
        }
Example #3
0
        public void MakeMove(Board connectFourBoard, Board.eBoardSquare playerCoin, int selectedColumn, ref int lastRowInsertedTo, ref bool gameWon)
        {
            int rowToInsertTo = GetFirstOpenSpotInColumn(connectFourBoard, selectedColumn);

            connectFourBoard[rowToInsertTo, selectedColumn] = playerCoin;
            lastRowInsertedTo = rowToInsertTo;
            gameWon           = CheckIfGameWon(connectFourBoard, rowToInsertTo, selectedColumn, playerCoin);
        }
Example #4
0
        private void GameOver(Board.eBoardSquare CurrentPlayerCoin, GameState GameState)
        {
            if (GameState == GameState.Victory)
            {
                string playerName;

                m_GameState = GameState.Victory;
                if (currentPlayerCoin == Board.eBoardSquare.Player1)
                {
                    playerName = m_Player1Name;
                    m_Player1Score++;
                    labelPlayer1.Text = string.Format(k_PlayerAndScoreString, m_Player1Name, m_Player1Score);
                }
                else
                {
                    playerName = m_Player2Name;
                    m_Player2Score++;
                    labelPlayer2.Text = string.Format(k_PlayerAndScoreString, m_Player2Name, m_Player2Score);
                }

                DialogResult dialogResult = MessageBox.Show(
                    string.Format(
                        @"{0} Won!!
Another round?",
                        playerName),
                    k_WinString,
                    MessageBoxButtons.YesNo);

                if (dialogResult == DialogResult.Yes)
                {
                    ResetBoards();
                }
                else if (dialogResult == DialogResult.No)
                {
                    Close();
                }
            }
            else
            {
                DialogResult dialogResult = MessageBox.Show(
                    string.Format(@"Tie!!
Another round?"),
                    k_TieString,
                    MessageBoxButtons.YesNo);

                if (dialogResult == DialogResult.Yes)
                {
                    ResetBoards();
                }
                else if (dialogResult == DialogResult.No)
                {
                    Close();
                }
            }
        }
Example #5
0
 private void ChangeToNextPlayerTurn()
 {
     if (currentPlayerCoin == Board.eBoardSquare.Player1)
     {
         currentPlayerCoin = Board.eBoardSquare.Player2;
     }
     else
     {
         currentPlayerCoin = Board.eBoardSquare.Player1;
     }
 }
Example #6
0
 private void RestartGame()
 {
     currentPlayerCoin = Board.eBoardSquare.Player1;
     ClearCoinBoard();
     clearButtonPressed();
     InitColButtons(r_GameSettingConnectFour.GameSettings.Cols);
     initBoard(r_GameSettingConnectFour.GameSettings.Rows, r_GameSettingConnectFour.GameSettings.Cols);
     updatePlayersLabels(r_GameSettingConnectFour.GameSettings.Player1Name, r_GameSettingConnectFour.GameSettings.Player2Name);
     m_GameBoard.InitializeBoard();
     gamePanel.Controls.Remove(fallingCoinPicBox);
     gamePanel.Controls.Add(fallingCoinPicBox);
     fixLabelAboutSize(r_GameSettingConnectFour.GameSettings.Cols, r_GameSettingConnectFour.GameSettings.Rows);
     m_GameState = GameState.ContinuePlaying;
     CenterToParent();
 }
Example #7
0
        private bool CheckColForConnectedFour(Board connectFourBoard, int lastInsertedCol, Board.eBoardSquare playerCoin)
        {
            bool connectedFourFoundInCol = false;
            int  numOfRows = connectFourBoard.NumOfRows;
            int  coinCount = 0;

            for (int i = 0; i < numOfRows; i++)
            {
                if (connectFourBoard[i, lastInsertedCol] == playerCoin)
                {
                    coinCount++;

                    if (coinCount == 4)
                    {
                        connectedFourFoundInCol = true;
                    }
                }
                else
                {
                    coinCount = 0;
                }
            }

            return(connectedFourFoundInCol);
        }
Example #8
0
        private bool CheckRowForConnectedFour(Board connectFourBoard, int lastInsertedRow, Board.eBoardSquare playerCoin)
        {
            int  connectedFourFound      = 0;
            bool connectedFourFoundInRow = false;

            string rowString = connectFourBoard[lastInsertedRow];

            if (playerCoin == Board.eBoardSquare.Player1)
            {
                connectedFourFound = rowString.IndexOf("OOOO");
            }
            else
            {
                connectedFourFound = rowString.IndexOf("XXXX");
            }

            if (connectedFourFound != -1)
            {
                connectedFourFoundInRow = true;
            }

            return(connectedFourFoundInRow);
        }
Example #9
0
        private bool CheckIfGameWon(Board connectFourBoard, int lastInsertedRow, int lastInsertedCol, Board.eBoardSquare playerCoin)
        {
            bool gameWon = false;

            gameWon = CheckRowForConnectedFour(connectFourBoard, lastInsertedRow, playerCoin);

            if (!gameWon)
            {
                gameWon = CheckColForConnectedFour(connectFourBoard, lastInsertedCol, playerCoin);

                if (!gameWon)
                {
                    gameWon = CheckDiagonalsForConnectedFour(connectFourBoard, lastInsertedRow, lastInsertedCol, playerCoin);
                }
            }

            return(gameWon);
        }
Example #10
0
        private bool CheckFullRightDiagonalForConnectedFour(Board connectFourBoard, int row, int col, Board.eBoardSquare playerCoin)
        {
            bool validLocation = false;
            int  coinCount     = 0;
            bool connectedFourFoundInRightDiagonal = false;
            int  minRow = 0;
            int  minCol = 0;

            GetLowestBottomRightSquare(connectFourBoard, ref minRow, ref minCol, row, col);

            validLocation = connectFourBoard.CheckIfValidLocationOnBoard(minRow, minCol);

            while (validLocation)
            {
                if (connectFourBoard[minRow, minCol] == playerCoin)
                {
                    coinCount++;

                    if (coinCount == 4)
                    {
                        connectedFourFoundInRightDiagonal = true;
                    }
                }
                else
                {
                    coinCount = 0;
                }

                minRow--;
                minCol--;
                validLocation = connectFourBoard.CheckIfValidLocationOnBoard(minRow, minCol);
            }

            return(connectedFourFoundInRightDiagonal);
        }
 public EventOnCoin(int col, int row, Board.eBoardSquare playerCoin)
 {
     r_Col        = col;
     r_Row        = row;
     r_PlayerCoin = playerCoin;
 }