private void GameBoardButtons_ClickOnEmptyCell(object sender, EventArgs e) { bool printMustEatError = false; pieces.Piece currentPiece; ButtonWithLocation button = sender as ButtonWithLocation; string winner = string.Empty, winMessage = string.Empty; char whoWon; Vector2 pcMoveNewLocation = new Vector2(-1, -1), pcMoveStartLocation = new Vector2(-1, -1); if (ClickedButton != null) { currentPiece = new pieces.Piece(ClickedButton.Text[0], ClickedButton.VectorLocation); m_IsMoveLegal = Logic.GameLogic.CheckMove(currentPiece, button.VectorLocation, m_GameBoard, ref m_HasAnotherEatMove, ref printMustEatError, m_IsPcMove, ref pcMoveNewLocation); m_LastTurnGroup = Logic.GameLogic.CurrentPlayerGroup; if (m_HasAnotherEatMove || printMustEatError) { printMustEatMessageBox(); } else if (!m_IsMoveLegal) { printIllegalMoveMessageBox(); ClickedButton.BackColor = Color.White; } if (m_IsMoveLegal) { Logic.GameLogic.UpdateCurrentTurn(ref m_IsPlayerOneTurn); m_Pieces.Add(m_GameBoard[button.VectorLocation]); ClickedButton.Click -= new EventHandler(GameBoardButtons_SecondClick); ClickedButton.Click += new EventHandler(GameBoardButtons_ClickOnEmptyCell); ClickedButton.BackgroundImage = null; ClickedButton.BackColor = Color.BurlyWood; ClickedButton.Text = string.Empty; ClickedButton = null; m_IsButtonClicked = false; } if (!m_IsPlayerOneTurn) { m_IsPlayerOneTurn = !m_IsPlayerOneTurn; if (!m_Is2PlayersMode) { m_IsPcMove = true; pcGameBoardMove(); Logic.GameLogic.UpdateCurrentTurn(ref m_IsPlayerOneTurn); } } if (Logic.GameLogic.IsGameOver(m_GameBoard)) { if (!Logic.GameLogic.IsATie(m_GameBoard)) { whoWon = GameLogic.WhoWin(); winner = whoWon == 'X' ? PlayerOneName.Text : PlayerTwoName.Text; winMessage = string.Format("{0} Won!{1}Another Round?", winner, Environment.NewLine); } else { winMessage = string.Format("Tie!{0}Another Round?", Environment.NewLine); } isInterestedInAnotherGame(winMessage); } } }
private bool canMove(Position pos) { Piece p = brd.piece(pos); return(p == null || p.color != color); }