private void animate(InstrumentButton i_OriginButton) { m_AnimationTimer.Start(); Image animationImage = i_OriginButton.Image; i_OriginButton.Image = null; m_AnimationPictureBox.Visible = true; m_AnimationPictureBox.BackgroundImage = null; calcualteStopLocation(i_OriginButton.Location); m_AnimationPictureBox.Location = i_OriginButton.Location; m_AnimationPictureBox.Size = new Size(m_ButtonSize, m_ButtonSize); m_AnimationPictureBox.Image = animationImage; }
private void button_Click(object sender, EventArgs e) { if (m_PreviousPressedButton == null) { (sender as InstrumentButton).BackColor = Color.CornflowerBlue; m_PreviousPressedButton = sender as InstrumentButton; } else if ((sender as InstrumentButton).Equals(m_PreviousPressedButton)) { m_PreviousPressedButton = null; m_CurrentPressedButton = null; (sender as InstrumentButton).BackColor = Color.Empty; } else { m_CurrentPressedButton = sender as InstrumentButton; tryToMakeMove(); } }
private InstrumentButton createButton(Point i_Location, bool i_isEnabled, int i_RowIndex, int i_ColIndex) { InstrumentButton button = new InstrumentButton(); button.RowIndex = i_RowIndex; button.ColIndex = i_ColIndex; button.Height = m_ButtonSize; button.Width = m_ButtonSize; button.Location = new Point(i_Location.X, i_Location.Y); button.Enabled = i_isEnabled; if (!i_isEnabled) { button.BackColor = Color.Gray; } this.Controls.Add(button); button.Click += new System.EventHandler(this.button_Click); return(button); }
private void tryToMakeMove() { int colMoveFrom = m_PreviousPressedButton.ColIndex; int rowMoveFrom = m_PreviousPressedButton.RowIndex; int colMoveTo = m_CurrentPressedButton.ColIndex; int rowMoveTo = m_CurrentPressedButton.RowIndex; try { m_GameHandler.TryToMakeMove(rowMoveFrom, colMoveFrom, rowMoveTo, colMoveTo); m_AnimationMove = m_GameHandler.LastMove(); animate(m_Board[rowMoveFrom, colMoveFrom]); m_CurrentPressedButton = null; m_PreviousPressedButton = null; } catch (Exception e) { MessageBox.Show(e.Message, "Damka", MessageBoxButtons.OK); m_CurrentPressedButton = null; m_PreviousPressedButton = null; updateDisplay(); } }