Пример #1
0
        /// <summary>
        /// Handles the typing in the control.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnKeyDown(KeyEventArgs e)
        {
            ClientApplication client = ClientApplication.Instance;
            GameRoot          root   = client.ServerInstance;

            if (e.KeyCode == Keys.Space)
            {
                if (root.ActiveCountry.NotifyEndOfTurn)
                {
                    root.ActivateNextCountry();
                }
                else
                {
                    root.ActivateNextUnit();
                }
                return;
            }

            Unit unit = root.ActiveUnit;

            if (unit == null)
            {
                return;
            }

            Point newCoordinates = Point.Empty;

            switch (e.KeyCode)
            {
            case Keys.NumPad3:
                newCoordinates = new Point(unit.Coordinates.X + 1, unit.Coordinates.Y + 1);
                break;

            case Keys.NumPad7:
                newCoordinates = new Point(unit.Coordinates.X - 1, unit.Coordinates.Y - 1);
                break;

            case Keys.NumPad1:
                newCoordinates = new Point(unit.Coordinates.X - 1, unit.Coordinates.Y + 1);
                break;

            case Keys.NumPad9:
                newCoordinates = new Point(unit.Coordinates.X + 1, unit.Coordinates.Y - 1);
                break;

            case Keys.NumPad4:
                newCoordinates = new Point(unit.Coordinates.X - 1, unit.Coordinates.Y);
                break;

            case Keys.NumPad6:
                newCoordinates = new Point(unit.Coordinates.X + 1, unit.Coordinates.Y);
                break;

            case Keys.NumPad2:
                newCoordinates = new Point(unit.Coordinates.X, unit.Coordinates.Y + 1);
                break;

            case Keys.NumPad8:
                newCoordinates = new Point(unit.Coordinates.X, unit.Coordinates.Y - 1);
                break;
            }

            if (newCoordinates == Point.Empty)
            {
                return;
            }
            unit.MoveTo(newCoordinates);
            Invalidate();
        }
Пример #2
0
        /// <summary>
        /// Handles the user pressing a key in the control.
        /// </summary>
        /// <param name="kea"></param>
        protected override void OnKeyPress(DXKeyboardEventArgs e)
        {
            GameRoot root = GameRoot.Instance;

            base.OnKeyPress(e);
            MoveResult result = MoveResult.MoveSuccess;

            if (e.KeyboardState[Key.Up])
            {
                result = root.ActiveUnit.MoveTo(root.ActiveUnit.Coordinates);
            }
            else if (e.KeyboardState[Key.Down])
            {
                result = root.ActiveUnit.MoveTo(root.ActiveUnit.Coordinates);
            }
            else if (e.KeyboardState[Key.Left])
            {
                result = root.ActiveUnit.MoveTo(root.ActiveUnit.Coordinates);
            }
            else if (e.KeyboardState[Key.Right])
            {
                result = root.ActiveUnit.MoveTo(root.ActiveUnit.Coordinates);
            }
            else if (e.KeyboardState[Key.NumPad7])
            {
                result = root.ActiveUnit.MoveTo(root.ActiveUnit.Coordinates);
            }
            else if (e.KeyboardState[Key.Home])
            {
                result = root.ActiveUnit.MoveTo(root.ActiveUnit.Coordinates);
            }
            else if (e.KeyboardState[Key.PageDown])
            {
                result = root.ActiveUnit.MoveTo(root.ActiveUnit.Coordinates);
            }
            else if (e.KeyboardState[Key.End])
            {
                result = root.ActiveUnit.MoveTo(root.ActiveUnit.Coordinates);
            }
            else if (e.KeyboardState[Key.S])
            {
                ((Settler)root.ActiveUnit).Settle(string.Empty);
            }
            else if (e.KeyboardState[Key.Space])
            {
                root.ActivateNextUnit();
            }

            switch (result)
            {
            case MoveResult.CellTaken:
                break;

            case MoveResult.Killed:
                break;

            case MoveResult.MoveSuccess:
                if (root.ActiveUnit != null)
                {
                    if (root.ActiveUnit.MovesLeft == 0)
                    {
                        root.ActivateNextUnit();
                    }
                }
                break;

            case MoveResult.UnreachableTerrain:
                break;

            case MoveResult.UnresolvedCombat:
                break;
            }
        }