private void tryMakePlayerMove(GameWindowButton i_CurrentButton) { m_WindowButtonDestination = i_CurrentButton; onPieceMove(); swapButtonColor(m_CurrentWindowButton); m_CurrentWindowButton = null; m_WindowButtonDestination = null; }
private void swapButtonColor(GameWindowButton i_CurrentWindowButton) { if (i_CurrentWindowButton.BackColor == Color.White) { i_CurrentWindowButton.BackColor = Color.LightSkyBlue; } else if (i_CurrentWindowButton.BackColor == Color.LightSkyBlue) { i_CurrentWindowButton.BackColor = Color.White; } }
private void tryMakePlayerSelection(GameWindowButton i_CurrentButton) { try { OnWindowButtonSelected(i_CurrentButton); m_CurrentWindowButton = i_CurrentButton; swapButtonColor(i_CurrentButton); } catch (ArgumentException ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void gameWindowButton_ButtonClicked(object i_Sender, EventArgs i_E) { GameWindowButton currentButton = i_Sender as GameWindowButton; if (m_CurrentWindowButton == null) { resetComputerActions(); tryMakePlayerSelection(currentButton); } else if (m_CurrentWindowButton == currentButton) { undoPlayerSelection(); } else { tryMakePlayerMove(currentButton); } }
private void createButtonMatrix() { for (int row = 0; row < m_GameWindowSize; row++) { for (int col = 0; col < m_GameWindowSize; col++) { GameWindowButton currentSquare = new GameWindowButton(new Point(col, row)); if ((row % 2 == 0 && col % 2 == 0) || (row % 2 == 1 && col % 2 == 1)) { currentSquare.Enabled = false; currentSquare.BackColor = Color.Gray; } currentSquare.Top = (row * Constants.k_ButtonHeight) + Constants.k_ButtonStartY; currentSquare.Left = (col * Constants.k_ButtonWidth) + Constants.k_ButtonStartX; currentSquare.Click += gameWindowButton_ButtonClicked; Controls.Add(currentSquare); } } }
protected virtual void OnWindowButtonSelected(GameWindowButton i_CurrentWindowButton) { WindowButtonSelect?.Invoke(i_CurrentWindowButton.ButtonLocation); }
private void undoPlayerSelection() { swapButtonColor(m_CurrentWindowButton); m_CurrentWindowButton = null; }