private bool checkIfMustToEat(eOwner i_CurPlayer) { eCoinSign i_CoinSign; bool v_MustToEat = false; for (int i = 0; i < GameBoard.NumOfRowsAndCols; i++) { for (int j = 0; j < GameBoard.NumOfRowsAndCols; j++) { i_CoinSign = GameBoard.Matrix[i, j].Sign; if (GameBoard.Matrix[i, j].Owner == i_CurPlayer) { if (i_CoinSign == eCoinSign.PlayerX) { v_MustToEat = checkIfMustToEatDownToUp(i_CurPlayer, i, j) || v_MustToEat; } else if (i_CoinSign == eCoinSign.PlayerO) { v_MustToEat = checkIfMustToEatUpToDown(i_CurPlayer, i, j) || v_MustToEat; } else if ((i_CoinSign == eCoinSign.PlayerXKing) || (i_CoinSign == eCoinSign.PlayerOKing)) { v_MustToEat = checkIfMustToEatDownToUp(i_CurPlayer, i, j) || checkIfMustToEatUpToDown(i_CurPlayer, i, j) || v_MustToEat; } } } } return(v_MustToEat); }
private void checkEndGame() { if (!m_Game.CheckIfExistsMoves(m_Game.Players[(int)m_Playerturn])) { m_TheWinner = m_Game.Winner(); endGameRound(m_Game, m_TheWinner); } }
private bool checkIfMustToEatDownToUpRight(eOwner i_CurOwner, int i_RowSource, int i_ColSource) { bool v_checkIfMustToEatDownToUpRight = false; if ((i_ColSource < GameBoard.NumOfRowsAndCols - 2) && (i_RowSource >= 2)) { v_checkIfMustToEatDownToUpRight = checkMustToEatCells(i_CurOwner, i_RowSource - 1, i_ColSource + 1, i_RowSource - 2, i_ColSource + 2); } return(v_checkIfMustToEatDownToUpRight); }
private bool checkIfMustToEatDownToUpLeft(eOwner i_CurOwner, int i_RowSource, int i_ColSource) { bool v_checkIfMustToEatDownToUpLeft = false; if ((i_ColSource >= 2) && (i_RowSource >= 2)) { v_checkIfMustToEatDownToUpLeft = checkMustToEatCells(i_CurOwner, i_RowSource - 1, i_ColSource - 1, i_RowSource - 2, i_ColSource - 2); } return(v_checkIfMustToEatDownToUpLeft); }
private bool checkMustToEatCells(eOwner I_CurOwner, int i_EatenCellRow, int i_EatenCellCol, int i_TargetCellRow, int i_TargetCellCol) { bool v_CheckMustToEatBounds = false; if ((I_CurOwner != GameBoard.Matrix[i_EatenCellRow, i_EatenCellCol].Owner) && (GameBoard.Matrix[i_EatenCellRow, i_EatenCellCol].Owner != eOwner.None)) { v_CheckMustToEatBounds = GameBoard.Matrix[i_TargetCellRow, i_TargetCellCol].Status == eStatus.NotExistCoin; } return(v_CheckMustToEatBounds); }
public FormBoard(GameProgress i_gameProgress) { this.m_Playerturn = eOwner.Player1; this.m_Game = i_gameProgress; this.InitializeComponent(); this.LabelScorePlayer1.Text = "0"; this.LabelScorePlayer2.Text = "0"; this.Player1Name.Text = m_Game.Players[0].Name; this.Player2Name.Text = m_Game.Players[1].Name; this.initializeBoard((int)this.m_Game.GameBoard.NumOfRowsAndCols); }
private void doMoveIFComputerTurn() { if (m_Game.Players[(int)m_Playerturn].TypeOfPlayer == eTypeOfPlayer.Computer) { m_Game.FillLigalMovesList(); SourceAndTargetMove io_SourceAndTargetMove, io_MoreSkipMove; m_Game.ComputerMove(out io_SourceAndTargetMove, out io_MoreSkipMove); updateBoard(); m_Playerturn = m_Game.ChangeTurn(); } }
private void endGameRound(GameProgress m_Game, eOwner m_TheWinner) { string i_WinnerName = null; if (m_TheWinner != eOwner.None) { m_Game.UpdateScore(m_TheWinner); } i_WinnerName = getWinnersString(m_Game, m_TheWinner); dialogGameRound(i_WinnerName); }
public Cell(eCoinSign i_Sign) { this.m_Sign = i_Sign; this.m_Status = eStatus.Illegal; if (i_Sign == eCoinSign.PlayerO) { this.m_Owner = eOwner.Player1; } else { this.m_Owner = eOwner.Player2; } }
public void initializeButtonPointDetails(GameProgress m_Game) { eOwner i_OpposingPlayer = (m_Game.CurrentPlayerTurn == eOwner.Player1) ? eOwner.Player2 : eOwner.Player1; int i_Col = this.m_PointLocation.X; int i_Row = this.m_PointLocation.Y; if (m_Game.GameBoard.Matrix[i_Row, i_Col].Status == eStatus.Illegal) { this.BackColor = Color.Black; this.Enabled = false; } else { this.Enabled = true; this.BackColor = Color.White; if (m_Game.GameBoard.Matrix[i_Col, i_Row].Sign == eCoinSign.PlayerO) { this.BackgroundImage = EnglishCheckersUI.Properties.Resources.WhiteCheckerPlayer; this.BackgroundImageLayout = ImageLayout.Stretch; } else if (m_Game.GameBoard.Matrix[i_Col, i_Row].Sign == eCoinSign.PlayerX) { this.BackgroundImage = EnglishCheckersUI.Properties.Resources.BlackCheckerPlayer; this.BackgroundImageLayout = ImageLayout.Stretch; } else if (m_Game.GameBoard.Matrix[i_Col, i_Row].Sign == eCoinSign.PlayerOKing) { this.BackgroundImage = EnglishCheckersUI.Properties.Resources.WhiteKing; this.BackgroundImageLayout = ImageLayout.Stretch; } else if (m_Game.GameBoard.Matrix[i_Col, i_Row].Sign == eCoinSign.PlayerXKing) { this.BackgroundImage = EnglishCheckersUI.Properties.Resources.BlackKing; this.BackgroundImageLayout = ImageLayout.Stretch; } else if (m_Game.GameBoard.Matrix[i_Col, i_Row].Sign == eCoinSign.None) { this.BackgroundImage = null; } if (m_Game.GameBoard.Matrix[i_Col, i_Row].Owner == i_OpposingPlayer) { this.Enabled = false; } } this.Margin = Padding.Empty; this.Font = new Font(this.Font, FontStyle.Bold); this.Location = new Point(this.Width * i_Row, this.Height * i_Col); }
private static string getWinnersString(GameProgress i_Game, eOwner i_TheWinner) { string i_winnerNameStr; if (i_TheWinner == eOwner.None) { i_winnerNameStr = "Tie!"; } else { i_winnerNameStr = "The winner is: " + i_Game.Players[(int)i_TheWinner].Name; } return(i_winnerNameStr); }
public eOwner Winner() { eOwner i_TheWinner = eOwner.None; if (!CheckIfExistsMoves(Players[0]) && !CheckIfExistsMoves(Players[1])) { i_TheWinner = eOwner.None; } else { i_TheWinner = CheckIfExistsMoves(Players[0]) ? eOwner.Player1 : eOwner.Player2; } return(i_TheWinner); }
public GameProgress(int i_BoardSize, string i_FirstPlayerName, string m_SecondPlayerName, int i_NumOfPlayers) { this.m_GameBoard = new Board(i_BoardSize); int i_NumOfCoins = (i_BoardSize / 2) * ((i_BoardSize / 2) - 1); this.m_Players[0] = new Player(i_FirstPlayerName, eTypeOfPlayer.Human, i_NumOfCoins, eCoinSign.PlayerO); if (i_NumOfPlayers == 2) { this.m_Players[1] = new Player(m_SecondPlayerName, eTypeOfPlayer.Human, i_NumOfCoins, eCoinSign.PlayerX); } else { this.m_Players[1] = new Player(m_SecondPlayerName, eTypeOfPlayer.Computer, i_NumOfCoins, eCoinSign.PlayerX); } m_CurrentPlayerTurn = eOwner.Player1; }
private void fillMustEatMovesListUpToDown(int i_RowSource, int i_ColSource) { eOwner i_CurOwner = GameBoard.Matrix[i_RowSource, i_ColSource].Owner; eTypeOfMove i_MoveType = eTypeOfMove.MustToEat; eCoinSign i_CoinSign = GameBoard.Matrix[i_RowSource, i_ColSource].Sign; if (checkIfMustToEatUpToDownRight(i_CurOwner, i_RowSource, i_ColSource)) { i_MoveType = checkIfMustToEatDownToUp(i_CurOwner, i_RowSource + 2, i_ColSource + 2) || checkIfMustToEatUpToDown(i_CurOwner, i_RowSource + 2, i_ColSource + 2) ? eTypeOfMove.CanMoreSkip : eTypeOfMove.MustToEat; Players[1].LigalMovesList.Add(new SourceAndTargetMove(i_RowSource, i_ColSource, i_RowSource + 2, i_ColSource + 2, i_RowSource + 1, i_ColSource + 1, i_MoveType)); } if (checkIfMustToEatUpToDownLeft(i_CurOwner, i_RowSource, i_ColSource)) { i_MoveType = checkIfMustToEatDownToUp(i_CurOwner, i_RowSource + 2, i_ColSource - 2) || checkIfMustToEatUpToDown(i_CurOwner, i_RowSource + 2, i_ColSource - 2) ? eTypeOfMove.CanMoreSkip : eTypeOfMove.MustToEat; Players[1].LigalMovesList.Add(new SourceAndTargetMove(i_RowSource, i_ColSource, i_RowSource + 2, i_ColSource - 2, i_RowSource + 1, i_ColSource - 1, i_MoveType)); } }
private eTypeOfMove eatAndUpdateCellMoveDownToUp(eTypeOfMove i_MoveType, int[] i_Source, int[] i_Terget, int i_ColSource) { resetCell(i_Source[0] - 1, i_ColSource); updateSourceAndTargetCells(i_Source, i_Terget); eCoinSign i_CurrentPlayer = GameBoard.Matrix[i_Terget[0], i_Terget[1]].Sign; eOwner i_CurrentOwner = GameBoard.Matrix[i_Terget[0], i_Terget[1]].Owner; if (i_CurrentPlayer == eCoinSign.PlayerX) { i_MoveType = checkIfMustToEatDownToUp(i_CurrentOwner, i_Terget[0], i_Terget[1]) ? eTypeOfMove.CanMoreSkip : eTypeOfMove.SkipMove; } if ((i_CurrentPlayer == eCoinSign.PlayerXKing) || (i_CurrentPlayer == eCoinSign.PlayerOKing)) { i_MoveType = checkIfMustToEatUpToDown(i_CurrentOwner, i_Terget[0], i_Terget[1]) || checkIfMustToEatDownToUp(i_CurrentOwner, i_Terget[0], i_Terget[1]) ? eTypeOfMove.CanMoreSkip : eTypeOfMove.SkipMove; } return(i_MoveType); }
private void dialogGameRound(string i_winnerNameStr) { i_winnerNameStr = string.Format( @"{0} Did you want another game? ", i_winnerNameStr); DialogResult dialogResult = MessageBox.Show(i_winnerNameStr, "Game Over!", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dialogResult == DialogResult.Yes) { updateScoreWinner(); m_Game.GameBoard = new Board(m_Game.GameBoard.NumOfRowsAndCols); m_Game.CurrentPlayerTurn = eOwner.Player1; m_Playerturn = eOwner.Player1; updatePlayerTurnLabel(); updateBoard(); } else if (dialogResult == DialogResult.No) { this.Close(); } }
private bool checkIfCanMove(eOwner i_CurOwner, int i_Row, int i_Col) { bool v_CanMove = false; eCoinSign i_CurSign = GameBoard.Matrix[i_Row, i_Col].Sign; if (i_CurSign == eCoinSign.PlayerO) { v_CanMove = checkIfMustToEatUpToDown(i_CurOwner, i_Row, i_Col) || checkIfExistRegularMoveAndFillMovesList(i_Row, i_Col); } if (i_CurSign == eCoinSign.PlayerX) { v_CanMove = checkIfMustToEatDownToUp(i_CurOwner, i_Row, i_Col) || checkIfExistRegularMoveAndFillMovesList(i_Row, i_Col); } if ((i_CurSign == eCoinSign.PlayerXKing) || (i_CurSign == eCoinSign.PlayerOKing)) { v_CanMove = checkIfMustToEatUpToDown(i_CurOwner, i_Row, i_Col) || checkIfMustToEatDownToUp(i_CurOwner, i_Row, i_Col) || checkIfExistRegularMoveAndFillMovesList(i_Row, i_Col); } return(v_CanMove); }
public void UpdateScore(eOwner i_TheWinner) { int i_NumberOfWinner = (int)i_TheWinner; int i_PlayerOneScore = 0; int i_PlayerTwoScore = 0; for (int i = 0; i < GameBoard.NumOfRowsAndCols; ++i) { for (int j = 0; j < GameBoard.NumOfRowsAndCols; ++j) { if (GameBoard.Matrix[i, j].Sign == eCoinSign.PlayerX) { i_PlayerTwoScore++; } else if (GameBoard.Matrix[i, j].Sign == eCoinSign.PlayerXKing) { i_PlayerTwoScore += 4; } else if (GameBoard.Matrix[i, j].Sign == eCoinSign.PlayerO) { i_PlayerOneScore++; } else if (GameBoard.Matrix[i, j].Sign == eCoinSign.PlayerOKing) { i_PlayerOneScore += 4; } } } if (i_PlayerOneScore > i_PlayerTwoScore) { Players[i_NumberOfWinner].Score += i_PlayerOneScore - i_PlayerTwoScore; } if (i_PlayerOneScore < i_PlayerTwoScore) { Players[i_NumberOfWinner].Score += i_PlayerTwoScore - i_PlayerOneScore; } }
private eTypeOfMove moveUpToDown(int[] i_Source, int[] i_Terget) { eTypeOfMove i_MoveType = eTypeOfMove.IllegalMove; eOwner i_CurPlayerOwner = GameBoard.Matrix[i_Source[0], i_Source[1]].Owner; if ((i_Terget[0] - 1 == i_Source[0]) && ((i_Source[1] == i_Terget[1] + 1) || (i_Source[1] == i_Terget[1] - 1))) { if (checkIfMustToEat(i_CurPlayerOwner)) { i_MoveType = eTypeOfMove.MustToEat; } else { i_MoveType = eTypeOfMove.RegularMove; updateSourceAndTargetCells(i_Source, i_Terget); } } else if ((i_Terget[0] - 2 == i_Source[0]) && (i_Source[1] == i_Terget[1] - 2)) { eOwner i_EatenOwner = GameBoard.Matrix[(i_Source[0] + 1), (i_Source[1] + 1)].Owner; if ((i_EatenOwner != i_CurPlayerOwner) && (i_EatenOwner != eOwner.None)) { i_MoveType = eatAndUpdateCellMoveUpToDown(i_MoveType, i_Source, i_Terget, i_Source[1] + 1); } } else if ((i_Terget[0] - 2 == i_Source[0]) && (i_Source[1] == i_Terget[1] + 2)) { eOwner i_EatenOwner = GameBoard.Matrix[(i_Source[0] + 1), (i_Source[1] - 1)].Owner; if ((i_EatenOwner != i_CurPlayerOwner) && (i_EatenOwner != eOwner.None)) { i_MoveType = eatAndUpdateCellMoveUpToDown(i_MoveType, i_Source, i_Terget, i_Source[1] - 1); } } return(i_MoveType); }
public eOwner ChangeTurn() { return(m_CurrentPlayerTurn = (m_CurrentPlayerTurn == eOwner.Player1) ? eOwner.Player2 : eOwner.Player1); }
private void doWhenButtonClicked(object sender, EventArgs e) { eTypeOfMove i_TypeOfMove; ButtonPoint i_CurrentBtn = sender as ButtonPoint; if (m_IsAnotherButtonPress) { if (m_Game.GameBoard.Matrix[i_CurrentBtn.PointLocation.X, i_CurrentBtn.PointLocation.Y].Status != eStatus.NotExistCoin) { if (i_CurrentBtn != m_PressButton) { if (this.v_CanMoreSkip) { showWarningMessage("You must eat again with the coin that made eating"); } else { showWarningMessage("Illegal Target!"); } } m_PressButton.BackColor = Color.White; } else { i_TypeOfMove = m_Game.DoMove(m_PressButton.PointLocation, i_CurrentBtn.PointLocation); if (i_TypeOfMove == eTypeOfMove.IllegalMove) { if (this.v_CanMoreSkip) { showWarningMessage("You must eat again with the coin that made eating"); } else { showWarningMessage("Illegal Move!"); } } else if (i_TypeOfMove == eTypeOfMove.MustToEat) { showWarningMessage("You Must To Eat!"); } else if (i_TypeOfMove == eTypeOfMove.CanMoreSkip) { int[] target = { i_CurrentBtn.PointLocation.X, i_CurrentBtn.PointLocation.Y }; m_Game.TryCreateKing(target); this.v_CanMoreSkip = true; m_PressButton = i_CurrentBtn; } else { int[] target = { i_CurrentBtn.PointLocation.X, i_CurrentBtn.PointLocation.Y }; m_Game.TryCreateKing(target); m_Playerturn = m_Game.ChangeTurn(); doMoveIFComputerTurn(); updatePlayerTurnLabel(); checkEndGame(); this.v_CanMoreSkip = false; } updateBoard(); } if (this.v_CanMoreSkip) { m_PressButton.BackColor = Color.LightBlue; } else { m_PressButton = null; m_IsAnotherButtonPress = false; } } else { if (m_Playerturn == m_Game.GameBoard.Matrix[i_CurrentBtn.PointLocation.X, i_CurrentBtn.PointLocation.Y].Owner) { m_PressButton = i_CurrentBtn; m_PressButton.BackColor = Color.LightBlue; m_IsAnotherButtonPress = true; } else { showWarningMessage("Not your coin!"); } } }
private bool checkIfMustToEatDownToUp(eOwner i_CurOwner, int i_RowSource, int i_ColSource) { return(checkIfMustToEatDownToUpRight(i_CurOwner, i_RowSource, i_ColSource) || checkIfMustToEatDownToUpLeft(i_CurOwner, i_RowSource, i_ColSource)); }
private bool checkIfMustToEatUpToDown(eOwner i_CurOwner, int i_Row, int i_Col) { return(checkIfMustToEatUpToDownRight(i_CurOwner, i_Row, i_Col) || checkIfMustToEatUpToDownLeft(i_CurOwner, i_Row, i_Col)); }