internal void HandleInput(InputHandler inputHandler) { if (inputHandler.SelectionContext == SelectionContext.PlacingTower && inputHandler.SelectionInGameBounds()) { Tower t = inputHandler.SelectedObject as Tower; if (GameStats.Gold >= t.Cost) { GameStats.Gold = GameStats.Gold - t.Cost; towerlist.Add(t); t.Position = inputHandler.Position; inputHandler.CancelSelection(); ResourceManager.WallSound.Play(); } else { MessageLog.NotEnoughGold(); } } else { towerlist.ForEach(t => { if (t.BoundingBox().Contains(inputHandler.Position)) { inputHandler.CancelSelection(); inputHandler.SelectionContext = SelectionContext.TowerSelected; t.Selected = true; inputHandler.SelectedObject = t; } }); } }
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; } }
private void HandleInput(InputHandler inputHandler, Node n) { if (!GameStats.AttackPhase) { if (!n.IsEmpty && inputHandler.SelectionContext == SelectionContext.None) { inputHandler.SelectionContext = SelectionContext.NodeSelected; inputHandler.SelectedObject = n; n.Selected = true; return; } if (!n.IsEmpty) { return; } if (inputHandler.SelectionContext == SelectionContext.PlacingWall) { if (!CheckForPath(n.simplePos.X, n.simplePos.Y, inputHandler, CheckForPathType.TogglingWall)) { MessageLog.IllegalPosition(); } else if (GameStats.Gold >= 1) { n.wall = true; n.UpdateTex(ResourceManager.Wall); GameStats.Gold = GameStats.Gold - 1; ResourceManager.WallSound.Play(); inputHandler.SelectionHandled = true; } else { MessageLog.NotEnoughGold(); } } else if (inputHandler.SelectionContext == SelectionContext.PlacingPortalEntrance) { n.portal = true; n.UpdateTex(ResourceManager.Portal); inputHandler.PortalEntrance = n; inputHandler.SelectionContext = SelectionContext.PlacingPortalExit; } else if (inputHandler.SelectionContext == SelectionContext.PlacingPortalExit) { Node portalExit = n; Node portalEntrance = inputHandler.PortalEntrance; if (!CheckForPath(portalExit.simplePos.X, portalExit.simplePos.Y, inputHandler, CheckForPathType.AddingPortal)) { MessageLog.IllegalPosition(); } else if (GameStats.Gold >= 20) { portalExit.portal = true; portalExit.UpdateTex(ResourceManager.Portal); portalExit.portalsTo = portalEntrance; portalEntrance.portalsTo = portalExit; inputHandler.SelectionContext = SelectionContext.PlacingPortalEntrance; GameStats.Gold = GameStats.Gold - 20; } else { MessageLog.NotEnoughGold(); } } else if (inputHandler.SelectionContext == SelectionContext.PlacingCheese) { if (!CheckForPath(n.simplePos.X, n.simplePos.Y, inputHandler, CheckForPathType.TogglingCheese)) { MessageLog.IllegalPosition(); } else if (GameStats.Gold >= 20) { n.cheese = true; n.UpdateTex(ResourceManager.Cheese); GameStats.Gold = GameStats.Gold - 20; ResourceManager.WallSound.Play(); } else { MessageLog.NotEnoughGold(); } } } }