private void showPlayerAvailableMoves() { m_GameToPlay.buildNextMovesList(); if (m_GameToPlay.NextMovesList.Count == 0) { bool isGameOver = m_GameToPlay.AreNoTilesAvailable(); if (!isGameOver) { MessageBox.Show("Current player doesn't have any valid moves. Turn is being skipped..."); switchPlayer(); showPlayerAvailableMoves(); } else { showGameOverDialog(); } } foreach (NextMoves nextMove in m_GameToPlay.NextMovesList) { Ex02_Othelo_Logic.Point validTile = nextMove.NewCoinInBoard; m_TilesMatrix[validTile.XCoord, validTile.YCoord].BackColor = Color.LimeGreen; m_TilesMatrix[validTile.XCoord, validTile.YCoord].Enabled = true; } }
private void playNextTurn() { updateTilesMatrix(); showPlayerAvailableMoves(); if (!m_GameToPlay.CurrentPlayer.HumanPlayer) { Ex02_Othelo_Logic.Point computerTile = m_GameToPlay.GenerateComputerTile(); pictureBox_Click(m_TilesMatrix[computerTile.XCoord, computerTile.YCoord], null); } }
private void pictureBox_Click(object sender, EventArgs e) { Ex02_Othelo_Logic.Point chosenTile = getPictureBoxCoordinates((PictureBox)sender); m_GameToPlay.PickTile(chosenTile); (sender as PictureBox).BackColor = Color.Blue; if (!m_GameToPlay.CurrentPlayer.HumanPlayer) { MessageBox.Show("Computer chose the tile marked in blue"); System.Threading.Thread.Sleep(500); } switchPlayer(); playNextTurn(); }
private Ex02_Othelo_Logic.Point getPictureBoxCoordinates(PictureBox i_PictureBoxTile) { int gameDimension = m_TilesMatrix.GetLength(0); Ex02_Othelo_Logic.Point pictureBoxPoint = new Ex02_Othelo_Logic.Point(); for (int i = 0; i < gameDimension; i++) { for (int j = 0; j < gameDimension; j++) { if (m_TilesMatrix[i, j].Equals(i_PictureBoxTile)) { pictureBoxPoint.XCoord = i; pictureBoxPoint.YCoord = j; } } } return(pictureBoxPoint); }