private void button_Click(object sender, EventArgs e) { if (!r_Game.GameOver) { ListenerButton buttonClicked = sender as ListenerButton; buttonClicked.Click -= new System.EventHandler(button_Click); buttonClicked.Click += new System.EventHandler(button_SecondClick); if (!m_IsFromButtonClicked) { buttonClicked.BackColor = Color.LightBlue; m_From = buttonClicked.Position; fromButton = buttonClicked; m_IsFromButtonClicked = true; } else { m_To = buttonClicked.Position; m_Step = new Step(m_From, m_To); m_IsFromButtonClicked = false; buttonClicked.PerformClick(); fromButton.PerformClick(); m_Status = r_Game.TakeAction(m_Step); checkStatus(); checkValidSteps(); } } else { checkValidSteps(); } }
private void button_SecondClick(object sender, EventArgs e) { ListenerButton buttonClicked = sender as ListenerButton; m_IsFromButtonClicked = false; buttonClicked.BackColor = Color.Empty; buttonClicked.Click -= new System.EventHandler(button_SecondClick); buttonClicked.Click += new System.EventHandler(button_Click); }
private void InitializeComponent() { //// //// GameForm //// Icon = Properties.Resources.Icon; FormBorderStyle = FormBorderStyle.Fixed3D; getLocationsAndSizes(); CenterToScreen(); Size = new Size(Width, Height); Text = "Damka"; //// //// labelPlayer1 //// labelPlayer1.Location = new System.Drawing.Point(player1Location, 15); labelPlayer1.Size = new Size(100, 20); labelPlayer1.Text = string.Format(@"{0} : {1}", player1Name, r_Game.Player1.CalcScore() - r_Game.Player2.CalcScore()); labelPlayer1.Font = new Font(labelPlayer1.Font, FontStyle.Bold); Controls.Add(labelPlayer1); //// //// labelPlayer2 //// labelPlayer2.Location = new System.Drawing.Point(player2Location, 15); labelPlayer2.Size = new Size(100, 20); labelPlayer2.Text = string.Format(@"{0} : {1}", player2Name, r_Game.Player2.CalcScore() - r_Game.Player1.CalcScore()); labelPlayer2.ForeColor = Color.Red; Controls.Add(labelPlayer2); for (int i = 0; i < m_BoardSize; i++) { for (int j = 0; j < m_BoardSize; j++) { Box box = r_Game.Board.board[i, j]; ListenerButton specialButton = new ListenerButton(box); specialButton.Click += new System.EventHandler(button_Click); Controls.Add(specialButton); } } }