Esempio n. 1
0
        private void CheckerBtn_Click(object sender, EventArgs e)
        {
            CheckerButton checkerBtn   = sender as CheckerButton;
            bool          clickedState = checkerBtn.Clicked,
                          playerIsClickingOnASquareThatHasHisSoldier = checkerBtn.Square.Color == GameManager.ActivePlayer.Color,
                          playerIsclickingAnAvailableMoveSquare      = checkerBtn.IsAnAvailableMove;

            // First, make sure you are able to click that button
            if (!playerIsClickingOnASquareThatHasHisSoldier && !playerIsclickingAnAvailableMoveSquare)
            {
                return;
            }

            if (playerIsClickingOnASquareThatHasHisSoldier)
            {
                // Unclick all the other buttons.
                m_Board.UnclickallButtons();
                clickedState = !clickedState; // We have to toggle the state now.

                // This line also triggeres the Available Moves part. Please take a look at the CheckerCheckerButton Setter for more information
                CheckedCheckerButton = clickedState ? checkerBtn : null;
            }
            else
            {
                // Player has clicked on an available move square
                Move move = AvailableMoves.First(m => m.Destination == checkerBtn.LocationOnMatrix);
                CheckedCheckerButton = null;
                GameManager.HandleMove(move);
            }
        }
Esempio n. 2
0
        public void MoveTo(int x, int y)
        {
            //TODO: remove hack for avoid switch weapons button
            var mousePosition       = Mouse.GetState().Position;
            var scaledMousePosition = new Point((int)Math.Round(mousePosition.X / CurrentDisplay.Scale), (int)Math.Round(mousePosition.Y / CurrentDisplay.Scale));

            if (scaledMousePosition.X > 700 && scaledMousePosition.Y < 900 && scaledMousePosition.Y > 850)
            {
                return;
            }
            if (AvailableMoves.Any(move => move.Last().X == x && move.Last().Y == y))
            {
                Event.Publish(new MovementConfirmed(AvailableMoves.First(move => move.Last().X == x && move.Last().Y == y)));
            }
        }