private void createButtons() { const int k_LeftStartSpace = 10; const int k_DiskSize = 50; const int k_BetweenDiskSpace = 5; int top = 10; int left = 0; for (int i = 1; i <= m_ButtonMatrixSize; i++) { left = k_LeftStartSpace; for (int j = 1; j <= m_ButtonMatrixSize; j++) { m_ButtonDiskMatrix[i - 1, j - 1] = new ButtonOthelloDisk(i, j, m_OthelloGameLogic[i, j].DiskColor); m_ButtonDiskMatrix[i - 1, j - 1].Width = k_DiskSize; m_ButtonDiskMatrix[i - 1, j - 1].Height = k_DiskSize; m_ButtonDiskMatrix[i - 1, j - 1].Location = new Point(top, left); m_ButtonDiskMatrix[i - 1, j - 1].Click += othelloDisk_Click; left += k_DiskSize + k_BetweenDiskSpace; Controls.Add(m_ButtonDiskMatrix[i - 1, j - 1]); m_OthelloGameLogic.DiskUpdate += m_ButtonDiskMatrix[i - 1, j - 1].DiskUpdate; } top += k_DiskSize + k_BetweenDiskSpace; m_OthelloGameLogic.AskForRefreshPossibleNextMove(); } }
private void othelloDisk_Click(object i_Sender, EventArgs i_EventArgs) { ButtonOthelloDisk currentButtonOthelloDisk = i_Sender as ButtonOthelloDisk; bool isPlayingVsPlayer = m_FormOthelloSettings.IsPlayingAgainstHuman; if (currentButtonOthelloDisk != null && m_OthelloGameLogic.IsBlackTurn) { m_OthelloGameLogic.BlackMakeMove(currentButtonOthelloDisk.Row, currentButtonOthelloDisk.Column); if (isPlayingVsPlayer) { Text = "Othello - White's Turn"; } } else if (currentButtonOthelloDisk != null && !m_OthelloGameLogic.IsBlackTurn) { m_OthelloGameLogic.WhiteMakeMove(currentButtonOthelloDisk.Row, currentButtonOthelloDisk.Column); if (isPlayingVsPlayer) { Text = "Othello - Black's Turn"; } } }