private void initializeBoard(int i_BoardSize) { this.m_BoardCells = new ButtonPoint[i_BoardSize, i_BoardSize]; this.ClientSize = new Size((i_BoardSize * k_ButtonSize) + k_MarginWidth, (i_BoardSize * k_ButtonSize) + k_MarginHeight + panelBoard.Top); for (int i_Row = 0; i_Row < i_BoardSize; i_Row++) { for (int i_Col = 0; i_Col < i_BoardSize; i_Col++) { this.m_BoardCells[i_Row, i_Col] = new ButtonPoint(i_Row, i_Col); this.m_BoardCells[i_Row, i_Col].Size = new Size(k_ButtonSize, k_ButtonSize); this.m_BoardCells[i_Row, i_Col].initializeButtonPointDetails(m_Game); this.m_BoardCells[i_Row, i_Col].Click += doWhenButtonClicked; this.panelBoard.Controls.Add(m_BoardCells[i_Row, i_Col]); if ((m_Game.GameBoard.Matrix[i_Row, i_Col].Owner != m_Playerturn) && (m_Game.GameBoard.Matrix[i_Row, i_Col].Owner != eOwner.None)) { this.m_BoardCells[i_Row, i_Col].Enabled = false; } } } m_PressButton = m_BoardCells[1, 0]; }
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!"); } } }