diff --git a/src/micropolisj/engine/BuildingTool.java b/src/micropolisj/engine/BuildingTool.java new file mode 100644 index 0000000..17a8988 --- /dev/null +++ b/src/micropolisj/engine/BuildingTool.java @@ -0,0 +1,60 @@ +// This file is part of MicropolisJ. +// Copyright (C) 2013 Jason Long +// Portions Copyright (C) 1989-2007 Electronic Arts Inc. +// +// MicropolisJ is free software; you can redistribute it and/or modify +// it under the terms of the GNU GPLv3, with additional terms. +// See the README file, included in this distribution, for details. + +package micropolisj.engine; + +import static micropolisj.engine.TileConstants.*; + +class BuildingTool extends ToolStroke +{ + public BuildingTool(Micropolis engine, MicropolisTool tool, int xpos, int ypos) + { + super(engine, tool, xpos, ypos); + } + + @Override + public void dragTo(int xdest, int ydest) + { + this.xpos = xdest; + this.ypos = ydest; + this.xdest = xdest; + this.ydest = ydest; + } + + @Override + boolean apply1(ToolEffectIfc eff) + { + switch (tool) + { + case FIRE: + return applyZone(eff, FIRESTATION); + + case POLICE: + return applyZone(eff, POLICESTATION); + + case POWERPLANT: + return applyZone(eff, POWERPLANT); + + case STADIUM: + return applyZone(eff, STADIUM); + + case SEAPORT: + return applyZone(eff, PORT); + + case NUCLEAR: + return applyZone(eff, NUCLEAR); + + case AIRPORT: + return applyZone(eff, AIRPORT); + + default: + // not expected + throw new Error("unexpected tool: "+tool); + } + } +} diff --git a/src/micropolisj/engine/MicropolisTool.java b/src/micropolisj/engine/MicropolisTool.java index b955adc..02322e2 100644 --- a/src/micropolisj/engine/MicropolisTool.java +++ b/src/micropolisj/engine/MicropolisTool.java @@ -54,15 +54,25 @@ public enum MicropolisTool public ToolStroke beginStroke(Micropolis engine, int xpos, int ypos) { - if (this == BULLDOZER) { + switch (this) { + case BULLDOZER: return new Bulldozer(engine, xpos, ypos); - } - else if (this == WIRE || - this == ROADS || - this == RAIL) { + + case WIRE: + case ROADS: + case RAIL: return new RoadLikeTool(engine, this, xpos, ypos); - } - else { + + case FIRE: + case POLICE: + case STADIUM: + case SEAPORT: + case POWERPLANT: + case NUCLEAR: + case AIRPORT: + return new BuildingTool(engine, this, xpos, ypos); + + default: return new ToolStroke(engine, this, xpos, ypos); } } diff --git a/src/micropolisj/engine/ToolStroke.java b/src/micropolisj/engine/ToolStroke.java index 7c54e5e..fcf5e82 100644 --- a/src/micropolisj/engine/ToolStroke.java +++ b/src/micropolisj/engine/ToolStroke.java @@ -77,27 +77,6 @@ public class ToolStroke case INDUSTRIAL: return applyZone(eff, INDCLR); - case FIRE: - return applyZone(eff, FIRESTATION); - - case POLICE: - return applyZone(eff, POLICESTATION); - - case POWERPLANT: - return applyZone(eff, POWERPLANT); - - case STADIUM: - return applyZone(eff, STADIUM); - - case SEAPORT: - return applyZone(eff, PORT); - - case NUCLEAR: - return applyZone(eff, NUCLEAR); - - case AIRPORT: - return applyZone(eff, AIRPORT); - default: // not expected throw new Error("unexpected tool: "+tool);