private void askForNewGame() { string WinnerMsg = getWinnerMsg(); string gameScore = r_OtheloLogicGame.GetScore(); DialogResult answer = MessageBox.Show( string.Format( @"{0} {1} ({2}\{3}) {4}", WinnerMsg, gameScore, r_Player1.Score.ToString(), r_Player2.Score.ToString(), k_NewGameMessege), "Othello", MessageBoxButtons.YesNo); if (answer == DialogResult.Yes) { r_OtheloLogicGame.StartNewGame(); m_CurrentTurnSign = BoardSigns.eBoardSigns.Player1Sign; } else { Close(); } }
private bool findSignInDir(int i_RowNumber, int i_ColNumber, BoardSigns.eBoardSigns i_SignToFind, int i_RowDir, int i_ColDir) { bool fullCell = IsFullCell(i_RowNumber, i_ColNumber); bool foundSign = false; i_RowNumber += i_RowDir; i_ColNumber += i_ColDir; while (IsInBounds(i_RowNumber, i_ColNumber)) { if (r_GameBoard[i_RowNumber, i_ColNumber].CellSign == i_SignToFind) { foundSign = true; break; } else if (!IsFullCell(i_RowNumber, i_ColNumber)) { break; } i_RowNumber += i_RowDir; i_ColNumber += i_ColDir; } if (fullCell && foundSign) { flipSignsInDir(i_RowNumber - i_RowDir, i_ColNumber - i_ColDir, i_SignToFind, -i_RowDir, -i_ColDir); } return(foundSign); }
internal int CalcOptions(BoardSigns.eBoardSigns i_PlayerSign) { int numOfOption = 0; for (int row = 0; row < r_GameBoard.GetLength(0); row++) { for (int col = 0; col < r_GameBoard.GetLength(0); col++) { if (!IsFullCell(row, col)) { if (findOpositeSignInSquareAroundMe(row, col, BoardSigns.GetOpositeSign(i_PlayerSign))) { r_GameBoard[row, col].CellSign = BoardSigns.eBoardSigns.Option; numOfOption++; } else { r_GameBoard[row, col].CellSign = BoardSigns.eBoardSigns.Empty; } } } } return(numOfOption); }
private void Board_Load(object sender, EventArgs e) { m_CurrentTurnSign = BoardSigns.eBoardSigns.Player1Sign; r_OtheloLogicGame.StartNewGame(); Text = string.Format("{0} {1} Turn", k_FormName, r_Player1.Name); int clientSize = (r_BoardButtons.GetLength(0) * OthelloBoardButton.sr_ButtonSize) + (k_FirstButtonPosition * 2); ClientSize = new Size(clientSize, clientSize); }
private void flipSignsInDir(int i_Row, int i_Col, BoardSigns.eBoardSigns i_SignToFlip, int i_RowDir, int i_ColDir) { while (r_GameBoard[i_Row, i_Col].CellSign != i_SignToFlip) { r_GameBoard[i_Row, i_Col].CellSign = i_SignToFlip; i_Row += i_RowDir; i_Col += i_ColDir; } }
public bool ThereAreMoves(BoardSigns.eBoardSigns i_PlayerSign) { int numberOfOptions = r_Board.CalcOptions(i_PlayerSign); if (PcTurn(i_PlayerSign)) { r_PcPlayer.OptionsCounter = numberOfOptions; } return(numberOfOptions != 0); }
public void ChangeButtonStatus(BoardSigns.eBoardSigns i_Sign) { switch (i_Sign) { case BoardSigns.eBoardSigns.Player1Sign: { BackColor = Color.LightGray; Image = Properties.Resources.RedCoin; BorderStyle = BorderStyle.Fixed3D; SizeMode = PictureBoxSizeMode.StretchImage; Enabled = false; break; } case BoardSigns.eBoardSigns.Player2Sign: { BackColor = Color.LightGray; Image = Properties.Resources.YellowCoin; BorderStyle = BorderStyle.Fixed3D; SizeMode = PictureBoxSizeMode.StretchImage; Enabled = false; break; } case BoardSigns.eBoardSigns.Option: { BackColor = Color.Green; Image = null; Enabled = true; BorderStyle = BorderStyle.Fixed3D; break; } case BoardSigns.eBoardSigns.Empty: { BackColor = Color.LightGray; Image = null; Enabled = false; BorderStyle = BorderStyle.Fixed3D; break; } } }
private void prepareNextUserTurn() { if (noMovesForPlayer(BoardSigns.GetOpositeSign(m_CurrentTurnSign))) { if (noMovesForPlayer(m_CurrentTurnSign)) { askForNewGame(); } } else { m_CurrentTurnSign = BoardSigns.GetOpositeSign(m_CurrentTurnSign); Text = string.Format("{0}{1} Turn", k_FormName, getCurrentPlayerName()); if (r_OtheloLogicGame.PcTurn(m_CurrentTurnSign)) { r_OtheloLogicGame.GetPcCellChoice(out int row, out int col); BoardButton_Click(r_BoardButtons[row, col], EventArgs.Empty); } } }
private bool noMovesForPlayer(BoardSigns.eBoardSigns i_Sign) { return(!r_OtheloLogicGame.ThereAreMoves(i_Sign)); }
public bool PcTurn(BoardSigns.eBoardSigns i_CurrentTurnSign) { return(SecondPlayerTurn(i_CurrentTurnSign) && GameType.IsPlayerVsPc(r_GameType)); }
public bool SecondPlayerTurn(BoardSigns.eBoardSigns i_CurrentTurnSign) { return(i_CurrentTurnSign == BoardSigns.eBoardSigns.Player2Sign); }
public void Play(BoardSigns.eBoardSigns io_CurrentTureSign, int i_RowNumber, int i_ColNumber) { r_Board.FillCell(i_RowNumber, i_ColNumber, io_CurrentTureSign); updateScore(); }
private bool findOpositeSignInSquareAroundMe(int i_RowNumber, int i_ColNumber, BoardSigns.eBoardSigns i_OpositeSignToFind) { bool anyOptionFound = false; for (int rowDir = -1; rowDir < 2; rowDir++) { for (int colDir = -1; colDir < 2; colDir++) { if (IsInBounds(i_RowNumber + rowDir, i_ColNumber + colDir) && r_GameBoard[i_RowNumber + rowDir, i_ColNumber + colDir].CellSign == i_OpositeSignToFind) { anyOptionFound |= findSignInDir(i_RowNumber, i_ColNumber, BoardSigns.GetOpositeSign(i_OpositeSignToFind), rowDir, colDir); } } } return(anyOptionFound); }
internal void FillCell(int i_RowNumber, int i_ColNumber, BoardSigns.eBoardSigns i_Sign) { r_GameBoard[i_RowNumber, i_ColNumber].CellSign = i_Sign; findOpositeSignInSquareAroundMe(i_RowNumber, i_ColNumber, BoardSigns.GetOpositeSign(i_Sign)); }
internal bool IsOptionalCell(BoardSigns.eBoardSigns i_SignOfCell) { return(i_SignOfCell == BoardSigns.eBoardSigns.Option); }