Пример #1
0
        public void HandleInput(InputHandler inputHandler)
        {
            switch (ButtonType)
            {
            case ButtonType.GenericTowerButton:
            case ButtonType.CannonTowerButton:
            case ButtonType.BatteryTowerButton:
            case ButtonType.BlastTowerButton:
                inputHandler.CancelSelection();
                inputHandler.SelectionContext = SelectionContext.PlacingTower;
                inputHandler.SelectedObject   = CreateTowerInstance();
                break;

            case ButtonType.WallButton:
                inputHandler.CancelSelection();
                inputHandler.SelectionContext = SelectionContext.PlacingWall;
                break;

            case ButtonType.PortalButton:
                inputHandler.CancelSelection();
                inputHandler.SelectionContext = SelectionContext.PlacingPortalEntrance;
                break;

            case ButtonType.CheeseButton:
                inputHandler.CancelSelection();
                inputHandler.SelectionContext = SelectionContext.PlacingCheese;
                break;

            case ButtonType.SellButton:
            {
                if (inputHandler.SelectionContext == SelectionContext.TowerSelected)
                {
                    Tower t = inputHandler.SelectedObject as Tower;
                    t.Sell();
                    inputHandler.CancelSelection();
                }
                if (inputHandler.SelectionContext == SelectionContext.NodeSelected)
                {
                    Node n = inputHandler.SelectedObject as Node;
                    n.Sell();
                    inputHandler.CancelSelection();
                }
            }
            break;

            case ButtonType.UpgradeButton:
            {
                Tower t = inputHandler.SelectedObject as Tower;
                if (GameStats.Gold >= t.Cost)
                {
                    GameStats.Gold = GameStats.Gold - t.Cost;
                    t.upgrade();
                }
                else
                {
                    MessageLog.NotEnoughGold();
                }
            }
            break;

            case ButtonType.CancelButton:
                inputHandler.CancelSelection();
                break;
            }
        }