/// <summary> /// Tell selected units to build a building at the specified location /// </summary> /// <param name="buildingType">Building Type</param> /// <param name="upperLeftCellCoords">Game coordinate</param> internal void TellSelectedUnitsToBuildAt(string buildingType, Point upperLeftCellCoords) { List <ModelComponent> selectedEntities = getGameModel().GetSelectionState().SelectedEntities; if (CanAllUnitsBuild(selectedEntities) && AllBelongsToPlayer(selectedEntities) && CellsAreEmpty(upperLeftCellCoords.X, upperLeftCellCoords.Y, 6, 6)) { // TODO: Check resources. // Create the actual building that each action will reference. BuildingFactory factory = BuildingFactory.Instance; Building buildingToAdd = factory.Build(buildingType, false); buildingToAdd.PointLocation = new PointF(upperLeftCellCoords.X, upperLeftCellCoords.Y); foreach (UnitComponent u in selectedEntities) { u.GetActionQueue().AddChild(new BuildAction(buildingToAdd, getGameModel().GetScenario().GetGameWorld().GetMap())); } } }
internal void OnClickMapCell(CellComponent cellComponent, float xPercent, float yPercent) { if (model.GetSelectionState().SelectionType == typeof(ZRTSModel.Tile)) { TileFactory tf = TileFactory.Instance; ZRTSModel.Tile tile = tf.GetImprovedTile(model.GetSelectionState().SelectedTileType); ChangeCellTileCommand command = new ChangeCellTileCommand(cellComponent, tile); if (command.CanBeDone()) { model.GetCommandStack().ExecuteCommand(command); } } else if (model.GetSelectionState().SelectionType == typeof(UnitComponent)) { UnitFactory uf = UnitFactory.Instance; UnitComponent unit = uf.Create(model.GetSelectionState().SelectedUnitType); //unit.PointLocation = new PointF((float)cellComponent.X + xPercent, (float)cellComponent.Y + yPercent); PlayerComponent player = model.GetScenario().GetGameWorld().GetPlayerList().GetPlayerByName(model.GetSelectionState().SelectedPlayer); AddUnitCommand command = new AddUnitCommand(unit, player, cellComponent); if (command.CanBeDone()) { model.GetCommandStack().ExecuteCommand(command); } } else if (model.GetSelectionState().SelectionType == typeof(Building)) { BuildingFactory bf = BuildingFactory.Instance; Building building = bf.Build(model.GetSelectionState().SelectedBuildingType, true); //building.PointLocation = new PointF((float)cellComponent.X + xPercent, (float)cellComponent.Y + yPercent); PlayerComponent player = model.GetScenario().GetGameWorld().GetPlayerList().GetPlayerByName(model.GetSelectionState().SelectedPlayer); AddBuildingCommand command = new AddBuildingCommand(building, player, cellComponent); if (command.CanBeDone()) { model.GetCommandStack().ExecuteCommand(command); } } }
private void ProcessCommand() { CommandFeedback = "Did nothing."; switch (Command) { case ShipCommand.MoveLeft: try { CommandFeedback = "Moved left."; var deltaX = PlayerNumber == 1 ? -1 : 1; GetMap().MoveEntity(this, X + deltaX, Y); } catch (CollisionException e) { CommandFeedback = "Tried to move left, but collided with something."; } catch (MoveNotOnMapException e) { CommandFeedback = "Tried to move left, but collided with something."; } break; case ShipCommand.MoveRight: try { CommandFeedback = "Moved right."; var deltaX = PlayerNumber == 1 ? 1 : -1; GetMap().MoveEntity(this, X + deltaX, Y); } catch (CollisionException e) { CommandFeedback = "Tried to move right, but collided with something."; } catch (MoveNotOnMapException e) { CommandFeedback = "Tried to move right, but collided with something."; } break; case ShipCommand.Shoot: CommandFeedback = "Fired a missile."; Shoot(); break; case ShipCommand.BuildShield: CommandFeedback = "Built shields."; try { ShieldFactory.BuildAtShip(PlayerNumber); } catch (NotEnoughLivesException e) { CommandFeedback = "Tried to build shields but didn't have enough lives."; } break; case ShipCommand.BuildAlienFactory: case ShipCommand.BuildMissileController: CommandFeedback = "Building a building."; try { BuildingFactory.Build(Command, PlayerNumber); } catch (NotEnoughLivesException e) { CommandFeedback = "Tried to build a building but didn't have enough lives."; } catch (AlreadyHasBuildingException e) { CommandFeedback = "Tried to build a building, but already had one."; } catch (CollisionException e) { CommandFeedback = "Tried to build a building but there was something in the way."; } break; } Command = ShipCommand.Nothing; }