public void FlipRight(Cell[,] i_Cells, int i_Row, int i_Col, eCellValue i_Color, eCellValue i_OpponentPlayer) { int flipSquares = 0; int checkCol = i_Col + 1; bool matchFound = false; while (checkCol < m_col && !matchFound) { if (i_Cells[i_Row, checkCol].Value.Equals(i_OpponentPlayer)) { flipSquares++; } else { if (i_Cells[i_Row, checkCol].Value.Equals(i_Color)) { matchFound = true; } } checkCol++; } if (matchFound && flipSquares > 0) { i_Cells[i_Row, i_Col].Value = i_Color; while (flipSquares >= 0) { i_Col++; flipSquares--; i_Cells[i_Row, i_Col].Value = i_Color; } } }
public bool CheckUpRight(Cell[,] i_Cells, int i_Row, int i_Col, eCellValue i_Color, eCellValue i_OpponentPlayer) { int checkRow = i_Row - 1; int checkCol = i_Col + 1; if (checkRow >= 0 && checkRow < m_row && checkCol >= 0 && checkCol < m_col) { if (i_Cells[checkRow, checkCol].Value.Equals(i_OpponentPlayer)) { checkRow--; checkCol++; while (checkRow >= 0 && checkCol < m_col) { if (i_Cells[checkRow, checkCol].Value == eCellValue.Empty) { i_Cells[checkRow, checkCol].Value = eCellValue.Valid; return(true); } if (i_Cells[checkRow, checkCol].Value.Equals(i_Color) || i_Cells[checkRow, checkCol].Value.Equals(eCellValue.Valid)) { return(false); } checkRow--; checkCol++; } } } return(false); }
public bool CheckLeft(Cell[,] i_Cells, int i_Row, int i_Col, eCellValue i_Color, eCellValue i_OpponentPlayer) { int checkCol = i_Col - 1; if (checkCol >= 0 && checkCol < m_col) { if (i_Cells[i_Row, checkCol].Value.Equals(i_OpponentPlayer)) { checkCol--; while (checkCol >= 0) { if (i_Cells[i_Row, checkCol].Value == eCellValue.Empty) { i_Cells[i_Row, checkCol].Value = eCellValue.Valid; return(true); } if (i_Cells[i_Row, checkCol].Value.Equals(i_Color) || i_Cells[i_Row, checkCol].Value.Equals(eCellValue.Valid)) { return(false); } checkCol--; } } } return(false); }
private void UpdateTableByMove(eCellValue i_Symbol, eCellValue i_RivalSymbol, int i_Row, int i_Col, eDirection i_Direction) { bool stopUpdate = false; ProceedAccordingToDirection(ref i_Row, ref i_Col, i_Direction); while (!stopUpdate) { if (m_Board.GetCellValue(i_Row, i_Col) == i_Symbol) { stopUpdate = true; } if (m_Board.GetCellValue(i_Row, i_Col) == i_RivalSymbol) { m_Board.SetCellValue(i_Symbol, i_Row, i_Col); } if (m_Board.GetCellValue(i_Row, i_Col) == eCellValue.empty) { break; } ProceedAccordingToDirection(ref i_Row, ref i_Col, i_Direction); } }
public Player(string i_Name, eCellValue i_DiscColor, int i_Score) { Name = i_Name; DiscColor = i_DiscColor; Score = i_Score; m_MyTurn = false; }
public bool CheckUp(Cell[,] i_Cells, int i_Row, int i_Col, eCellValue i_Color, eCellValue i_OpponentPlayer) { int checkRow = i_Row - 1; if (checkRow >= 0 && checkRow < m_row) { if (i_Cells[checkRow, i_Col].Value.Equals(i_OpponentPlayer)) { checkRow--; while (checkRow >= 0) { if (i_Cells[checkRow, i_Col].Value.Equals(eCellValue.Empty)) { i_Cells[checkRow, i_Col].Value = eCellValue.Valid; return(true); } if (i_Cells[checkRow, i_Col].Value.Equals(i_Color) || i_Cells[checkRow, i_Col].Value.Equals(eCellValue.Valid)) { return(false); } checkRow--; } } } return(false); }
public void UpdateCurrentBoard() { for (int i = 0; i < r_SizeOfBoard; i++) { for (int j = 0; j < r_SizeOfBoard; j++) { eCellValue requiredSign = m_GameLogic.m_Board.GetCellValue(i, j); switch (requiredSign) { case eCellValue.empty: m_BoardMatrix.GetButtonHandler(i, j).ButtonCanNotBePressed(); break; case eCellValue.yellow: m_BoardMatrix.GetButtonHandler(i, j).CellOfYellowPlayer(); break; case eCellValue.red: m_BoardMatrix.GetButtonHandler(i, j).CellOfRedPlayer(); break; default: break; } } } }
public void CellOfRedPlayer() { m_PictureBox.Image = Properties.Resources.CoinRed; m_PictureBox.BackColor = Color.Snow; m_eCellValue = eCellValue.red; m_PictureBox.Enabled = false; m_PictureBox.SizeMode = PictureBoxSizeMode.StretchImage; }
public void CellOfYellowPlayer() { m_PictureBox.Image = Properties.Resources.CoinYellow; m_PictureBox.BackColor = Color.Black; m_eCellValue = eCellValue.yellow; m_PictureBox.Enabled = false; m_PictureBox.SizeMode = PictureBoxSizeMode.StretchImage; }
private bool isFoundColumnSequence(Cell i_GameCell, eCellValue i_WantedCellState) { bool result = true; for (int i = 0; i < BoardSize; i++) { if (i_GameCell != BoardGameCells[i, i_GameCell.ColumnIndex] && BoardGameCells[i, i_GameCell.ColumnIndex].CellState != i_WantedCellState) { result = false; break; } } return(result); }
private int CountPoints(Board i_Board, eCellValue i_Symbol) { int points = 0; for (int i = 0; i < i_Board.Size; i++) { for (int j = 0; j < i_Board.Size; j++) { if (i_Board.GetCellValue(i, j) == i_Symbol) { points++; } } } return(points); }
public bool GameOver(eCellValue i_CurrentPlayercolor, int i_CurrentPlayerScore, int i_OpponentPlayerScore, bool i_CurrentPlayerHasMove) { if (i_CurrentPlayerScore + i_OpponentPlayerScore == m_row * m_col) { return(true); } if (i_OpponentPlayerScore == 0 || i_CurrentPlayerScore == 0) { return(true); } if (i_CurrentPlayerHasMove) { return(false); } else { return(true); } }
public void FlipOpponentsDiscs(int i_Row, int i_Col, eCellValue i_MyPlayer) { eCellValue opponentPlayer; if(i_MyPlayer.Equals(eCellValue.Black)) { opponentPlayer = eCellValue.White; } else { opponentPlayer = eCellValue.Black; } m_Logic.FlipUp(m_Cells, i_Row, i_Col, i_MyPlayer, opponentPlayer); m_Logic.FlipUpLeft(m_Cells, i_Row, i_Col, i_MyPlayer, opponentPlayer); m_Logic.FlipLeft(m_Cells, i_Row, i_Col, i_MyPlayer, opponentPlayer); m_Logic.FlipDownLeft(m_Cells, i_Row, i_Col, i_MyPlayer, opponentPlayer); m_Logic.FlipDown(m_Cells, i_Row, i_Col, i_MyPlayer, opponentPlayer); m_Logic.FlipDownRight(m_Cells, i_Row, i_Col, i_MyPlayer, opponentPlayer); m_Logic.FlipRight(m_Cells, i_Row, i_Col, i_MyPlayer, opponentPlayer); m_Logic.FlipUpRight(m_Cells, i_Row, i_Col, i_MyPlayer, opponentPlayer); }
public void GameRunning(int i_row, int i_col, eCellValue i_Color) { m_User1PossibleMove.Clear(); m_User2PossibleMove.Clear(); ScanAndUpdatePossiblMovesList(m_User1.Color, ref m_User1PossibleMove); ScanAndUpdatePossiblMovesList(m_User2.Color, ref m_User2PossibleMove); if (m_User1PossibleMove.Count != k_NoPossibleMoves || m_User2PossibleMove.Count != k_NoPossibleMoves) { if (m_User1PossibleMove.Count != k_NoPossibleMoves && m_User1.Color == i_Color) { m_Board.SetCellValue(i_Color, i_row, i_col); CheckAndUpdateBoard(i_row, i_col, i_Color, true); } m_User2PossibleMove.Clear(); ScanAndUpdatePossiblMovesList(m_User2.Color, ref m_User2PossibleMove); if (m_User2PossibleMove.Count != k_NoPossibleMoves && m_User2.Color == i_Color) { if (r_GameMode == k_GameAgainstComputer) { int randomCell = RandomMove(m_User2PossibleMove); m_Board.SetCellValue(m_User2.Color, m_User2PossibleMove[randomCell].Row, m_User2PossibleMove[randomCell].Col); CheckAndUpdateBoard(m_User2PossibleMove[randomCell].Row, m_User2PossibleMove[randomCell].Col, m_User2.Color, true); } else { m_Board.SetCellValue(i_Color, i_row, i_col); CheckAndUpdateBoard(i_row, i_col, i_Color, true); } } m_User1PossibleMove.Clear(); ScanAndUpdatePossiblMovesList(m_User1.Color, ref m_User1PossibleMove); m_User2PossibleMove.Clear(); ScanAndUpdatePossiblMovesList(m_User2.Color, ref m_User2PossibleMove); } }
public void ScanAndUpdatePossiblMovesList(eCellValue i_CellValue, ref List <CellMatrix> i_ListOfOptionalCell) { i_ListOfOptionalCell.Clear(); bool isPossible = false; for (int i = 0; i < m_Board.Size; i++) { for (int j = 0; j < m_Board.Size; j++) { if (m_Board.GetCellValue(i, j) == eCellValue.empty) { isPossible = CheckAndUpdateBoard(i, j, i_CellValue, false); if (isPossible == true) { i_ListOfOptionalCell.Add(new CellMatrix(i, j)); } } isPossible = false; } } }
private void r_TicTacToe_OnGUIBoardChange(Point i_Point, eCellValue i_Symbol) { TicTacToeCellButton button = getButtonByPoint(i_Point); button.SetSymbol(i_Symbol); button.Enabled = false; switch (GameLogicManager.GameState) { case eGameState.Tie: showNewGameMessage(tieMessage()); break; case eGameState.HasWinner: showNewGameMessage(winnerMessage()); break; case eGameState.Active: togglePlayers(); break; } }
private bool isFoundDiagonalSequence(Cell i_GameCell, eCellValue i_WantedCellState) { bool firstDiagonalIsTrue = true; bool secondDiagonal = true; if (i_GameCell.RowIndex == i_GameCell.ColumnIndex) { for (int i = 0; i < BoardSize; i++) { if (i_GameCell != BoardGameCells[i, i] && BoardGameCells[i, i].CellState != i_WantedCellState) { firstDiagonalIsTrue = false; break; } } } else { firstDiagonalIsTrue = false; } if (i_GameCell.RowIndex + i_GameCell.ColumnIndex == BoardSize - 1) { for (int i = 0; i < BoardSize; i++) { if (i_GameCell != BoardGameCells[i, BoardSize - 1 - i] && BoardGameCells[i, BoardSize - 1 - i].CellState != i_WantedCellState) { secondDiagonal = false; break; } } } else { secondDiagonal = false; } return(firstDiagonalIsTrue || secondDiagonal); }
public void FlipDownLeft(Cell[,] i_Cells, int i_Row, int i_Col, eCellValue i_Color, eCellValue i_OpponentPlayer) { int flipSquares = 0; int checkRow = i_Row + 1; int checkCol = i_Col - 1; bool matchFound = false; while (checkRow < m_row && checkCol >= 0 && !matchFound) { if (i_Cells[checkRow, checkCol].Value.Equals(i_OpponentPlayer)) { flipSquares++; } else { if (i_Cells[checkRow, checkCol].Value.Equals(i_Color)) { matchFound = true; } } checkRow++; checkCol--; } if (matchFound && flipSquares > 0) { i_Cells[i_Row, i_Col].Value = i_Color; while (flipSquares >= 0) { i_Row++; i_Col--; flipSquares--; i_Cells[i_Row, i_Col].Value = i_Color; } } }
public void SetSymbol(eCellValue i_Symbol) { Text = i_Symbol != eCellValue.Empty ? i_Symbol.ToString() : string.Empty; }
public void SetCellValue(eCellValue i_Symbol, int i_Row, int i_Col) { r_BoardGame[i_Row, i_Col] = i_Symbol; }
private bool examineIfPlayerMadeTheGameEnd(Cell i_GameCell, eCellValue i_WantedCellState) { return(isFoundRowSequence(i_GameCell, i_WantedCellState) || isFoundColumnSequence(i_GameCell, i_WantedCellState) || isFoundDiagonalSequence(i_GameCell, i_WantedCellState)); }
public void InsertSymbol(eCellValue i_Symbol) { CellState = i_Symbol == eCellValue.X ? eCellValue.X : eCellValue.O; }
public Cell(int i_RowIndex, int i_ColumnIndex) { m_CellState = eCellValue.Empty; m_RowIndex = i_RowIndex; m_ColumnIndex = i_ColumnIndex; }
public bool IsValidCell(eCellValue i_CurrentPlayer) { m_HasMove = false; eCellValue OpponentPlayer; if (i_CurrentPlayer.Equals(eCellValue.White)) { OpponentPlayer = eCellValue.Black; } else { OpponentPlayer = eCellValue.White; } for (int row = 0; row < m_Rows; row++) { for (int col = 0; col < m_Cols; col++) { if(m_Cells[row, col].Value.Equals(i_CurrentPlayer)) { if(m_Logic.CheckUp(m_Cells, row, col, i_CurrentPlayer, OpponentPlayer)) { m_HasMove = true; } if(m_Logic.CheckUpLeft(m_Cells, row, col, i_CurrentPlayer, OpponentPlayer)) { m_HasMove = true; } if (m_Logic.CheckLeft(m_Cells, row, col, i_CurrentPlayer, OpponentPlayer)) { m_HasMove = true; } if (m_Logic.CheckDownLeft(m_Cells, row, col, i_CurrentPlayer, OpponentPlayer)) { m_HasMove = true; } if (m_Logic.CheckDown(m_Cells, row, col, i_CurrentPlayer, OpponentPlayer)) { m_HasMove = true; } if (m_Logic.CheckDownRight(m_Cells, row, col, i_CurrentPlayer, OpponentPlayer)) { m_HasMove = true; } if (m_Logic.CheckRight(m_Cells, row, col, i_CurrentPlayer, OpponentPlayer)) { m_HasMove = true; } if (m_Logic.CheckUpRight(m_Cells, row, col, i_CurrentPlayer, OpponentPlayer)) { m_HasMove = true; } } } } return m_HasMove; }
public bool GameOver(eCellValue Color, int i_BlackScore, int i_WhiteScore) { return m_Logic.GameOver(Color, i_BlackScore, i_WhiteScore, m_HasMove) ? true : false; }
private bool CheckAndUpdateBoard(int i_Row, int i_Col, eCellValue i_CellValue, bool i_UpdateBoard) { bool check = false; eCellValue rivalSymbol; bool wasRivalSymbol = false; if (i_CellValue == eCellValue.yellow) { rivalSymbol = eCellValue.red; } else { rivalSymbol = eCellValue.yellow; } int i = i_Row, j = i_Col; int countDirectionEnum = Enum.GetNames(typeof(eDirection)).Length; for (int k = 0; k < countDirectionEnum; k++) { for (int q = 0; q < m_Board.Size; q++) { ProceedAccordingToDirection(ref i, ref j, (eDirection)k); if (CheckIfExceedingTheBoundariesOfTheMatrix(i, j) == true) { goto NextDirecrtion; } if (m_Board.GetCellValue(i, j) == rivalSymbol) { wasRivalSymbol = true; } if (m_Board.GetCellValue(i, j) == i_CellValue) { if (wasRivalSymbol == true) { check = true; if (i_UpdateBoard == true) { UpdateTableByMove(i_CellValue, rivalSymbol, i_Row, i_Col, (eDirection)k); goto NextDirecrtion; } else { goto Finish; } } else { goto NextDirecrtion; } } if (m_Board.GetCellValue(i, j) == eCellValue.empty) { goto NextDirecrtion; } } NextDirecrtion: i = i_Row; j = i_Col; wasRivalSymbol = false; } Finish: return(check); }
public Player(eCellValue i_Symbol, string i_Name) { m_PlayerName = i_Name; m_Symbol = i_Symbol; m_PlayerScore = 0; }
public Player(eCellValue i_Color) { m_Color = i_Color; m_Points = 2; }