Beispiel #1
0
        private void frmGameWindow_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            GameRoot root = GameRoot.GetGameRoot();

            e.Handled = true;
            switch (e.KeyCode)
            {
            case Keys.NumPad3:
                if (root.ActiveUnit != null)
                {
                    root.ActiveUnit.MoveTo((GridCell)root.ActiveUnit.Location.BottomCell);
                }
                break;

            case Keys.NumPad7:
                if (root.ActiveUnit != null)
                {
                    root.ActiveUnit.MoveTo((GridCell)root.ActiveUnit.Location.TopCell);
                }
                break;

            case Keys.NumPad1:
                if (root.ActiveUnit != null)
                {
                    root.ActiveUnit.MoveTo((GridCell)root.ActiveUnit.Location.LeftCell);
                }
                break;

            case Keys.NumPad9:
                if (root.ActiveUnit != null)
                {
                    root.ActiveUnit.MoveTo((GridCell)root.ActiveUnit.Location.RightCell);
                }
                break;

            case Keys.NumPad4:
                if (root.ActiveUnit != null)
                {
                    root.ActiveUnit.MoveTo((GridCell)root.ActiveUnit.Location.TopCell.LeftCell);
                }
                break;

            case Keys.NumPad6:
                if (root.ActiveUnit != null)
                {
                    root.ActiveUnit.MoveTo((GridCell)root.ActiveUnit.Location.RightCell.BottomCell);
                }
                break;

            case Keys.NumPad2:
                if (root.ActiveUnit != null)
                {
                    root.ActiveUnit.MoveTo((GridCell)root.ActiveUnit.Location.BottomCell.LeftCell);
                }
                break;

            case Keys.NumPad8:
                if (root.ActiveUnit != null)
                {
                    root.ActiveUnit.MoveTo((GridCell)root.ActiveUnit.Location.TopCell.RightCell);
                }
                break;

            case Keys.B:
                BuildNewCity();
                break;

            case Keys.I:
                Irrigate();
                break;

            case Keys.Space:
                _gameRoot.DoTurn();
                break;

            case Keys.R:
                BuildNewRoad();
                break;

            case Keys.M:
                BuildMine();
                break;
            }

            if (_gameRoot.Year > 0)
            {
                _yearPanel.Text =
                    Convert.ToInt32(Math.Abs(_gameRoot.Year)).ToString() + " A.D.";
            }
            else
            {
                _yearPanel.Text =
                    Convert.ToInt32(Math.Abs(_gameRoot.Year)).ToString() + " B.C.";
            }

            if (root.ActiveUnit != null)
            {
                _movesLeftPanel.Text =
                    root.ActiveUnit.MovesLeft.ToString() + " moves left";

                if (root.ActiveUnit.MovesLeft == 0)
                {
                    if (root.GetNextUnit() == null)
                    {
                        _gameRoot.DoTurn();
                    }
                }
            }
            else if (e.KeyCode != Keys.Space)
            {
                _gameRoot.DoTurn();
            }

            _gameWindow.Refresh();
            e.Handled = true;
        }