diff --git a/src/main/java/com/fossgalaxy/games/ggj2017/BuildOnResourceAction.java b/src/main/java/com/fossgalaxy/games/ggj2017/BuildOnResourceAction.java index d79d3375ccc5b2ac182c8e38abb271d1fc45b3eb..cf84623a8313acdf0c5eb69e9ea9e54f08bb62d3 100644 --- a/src/main/java/com/fossgalaxy/games/ggj2017/BuildOnResourceAction.java +++ b/src/main/java/com/fossgalaxy/games/ggj2017/BuildOnResourceAction.java @@ -22,11 +22,11 @@ public class BuildOnResourceAction extends DroneBuildAction { @Override public boolean isPossible(Entity entity, GameState s, CubeCoordinate co) { - if(!super.isPossible(entity, s, co)) return false; + if (!super.isPossible(entity, s, co)) return false; // Check resource of correct type is present Resource resourceAt = s.getResourceAt(co); - if(resourceAt == null){ + if (resourceAt == null) { return false; } diff --git a/src/main/java/com/fossgalaxy/games/ggj2017/JamApp.java b/src/main/java/com/fossgalaxy/games/ggj2017/JamApp.java index edaa921a22090859281d97af20e9160d880df508..d55cdf2f9f7a6a16ae3a08298a65299847a8754b 100644 --- a/src/main/java/com/fossgalaxy/games/ggj2017/JamApp.java +++ b/src/main/java/com/fossgalaxy/games/ggj2017/JamApp.java @@ -1,44 +1,29 @@ package com.fossgalaxy.games.ggj2017; -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.util.Arrays; -import java.util.Collection; -import java.util.Map; -import java.util.Set; -import java.util.UUID; -import java.util.stream.Collectors; - -import javax.swing.*; - -import com.fossgalaxy.games.ggj2017.drones.DroneBuildAction; -import com.fossgalaxy.games.rts.App; import com.fossgalaxy.games.rts.GameDef; import com.fossgalaxy.games.rts.GameState; import com.fossgalaxy.games.rts.ai.Controller; import com.fossgalaxy.games.rts.entity.Entity; -import com.fossgalaxy.games.rts.entity.EntityType; import com.fossgalaxy.games.rts.entity.ResourceType; import com.fossgalaxy.games.rts.io.SettingsIO; import com.fossgalaxy.games.rts.order.Order; import com.fossgalaxy.games.rts.order.OrderProcessor; import com.fossgalaxy.games.rts.rules.Rule; -import com.fossgalaxy.games.rts.ui.GameAction; -import com.fossgalaxy.games.rts.ui.UIModel; -import com.fossgalaxy.games.rts.ui.GameView; -import com.fossgalaxy.games.rts.ui.KeyboardController; -import com.fossgalaxy.games.rts.ui.MouseController; -import com.fossgalaxy.games.rts.ui.UIController; +import com.fossgalaxy.games.rts.ui.*; + +import javax.swing.*; +import java.awt.*; +import java.util.Collection; +import java.util.Map; +import java.util.UUID; +import java.util.stream.Collectors; /** * Hello world! - * */ -public class JamApp -{ - - public static void main( String[] args ) - { +public class JamApp { + + public static void main(String[] args) { //create the initial game state SettingsIO io = new SettingsIO("transmission.json"); @@ -46,8 +31,8 @@ public class JamApp GameDef def = io.getGameDef(); - for(ResourceType type : io.getResourceTypes()){ - for(int i = 0; i < state.getNumberOfPlayers(); i++){ + for (ResourceType type : io.getResourceTypes()) { + for (int i = 0; i < state.getNumberOfPlayers(); i++) { state.addResource(i, type, 1000); } } @@ -55,22 +40,22 @@ public class JamApp //build the player data Controller[] players = new Controller[state.getNumberOfPlayers()]; - for (int i=0; i<state.getNumberOfPlayers(); i++) { - GameState playerState = new GameState(state); - players[i] = JamApp.buildUI(playerState, "player "+i, i); + for (int i = 0; i < state.getNumberOfPlayers(); i++) { + GameState playerState = new GameState(state); + players[i] = JamApp.buildUI(playerState, "player " + i, i); } //create the thing that's doing the turn tracking. OrderProcessor processor = new OrderProcessor(state, 2); int MAX_TURNS = 100; - + for (Rule rule : def.getRules()) { - processor.addRule(rule); + processor.addRule(rule); } //turn loop //TODO this might be better inside the turn processor? - for (int i=0; i<MAX_TURNS; i++) { + for (int i = 0; i < MAX_TURNS; i++) { processor.setupTurn(); //figure out who's turn it is. @@ -83,26 +68,26 @@ public class JamApp processor.doOrderBulk(orders); processor.finishTurn(); - + if (processor.getWinner() != Rule.NO_WINNER) { - break; + break; } } - - System.out.println("Game over, player won: "+processor.getWinner()); + + System.out.println("Game over, player won: " + processor.getWinner()); } - + public static Collection<GameAction> getGameActions(Entity entity, Collection<GameAction> actions) { - return actions.stream().filter(act -> act.isPossible(entity)).collect(Collectors.toList()); + return actions.stream().filter(act -> act.isPossible(entity)).collect(Collectors.toList()); } - + public static Controller buildUI(GameState state, String title, int playerID) { JFrame frame = new JFrame(title); frame.setPreferredSize(new Dimension(800, 600)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - + //create the UI stuff UIModel model = new UIModel(state); GameView view = new GameView(model); @@ -114,59 +99,59 @@ public class JamApp view.setFocusable(true); view.requestFocus(); frame.add(viewport); - + frame.add(new ResourceBar(model, playerID), BorderLayout.NORTH); JToolBar actionList = new JToolBar(); actionList.setFloatable(false); - + model.addListener(x -> { - actionList.removeAll(); - - if (x != null) { - JButton smartBtn = new JButton("Smart"); - smartBtn.addActionListener(a -> { - model.setAction(null); - view.repaint(); - }); - - actionList.add(smartBtn); - actionList.addSeparator(); - - for (GameAction act : x.getType().getAvailableActions()) { - JButton actBtn = new JButton(act.toString()); - actBtn.addActionListener(a -> { - model.setAction(act); - view.repaint(); - }); - - actionList.add(actBtn); - } - - actionList.addSeparator(); - } - + actionList.removeAll(); + + if (x != null) { + JButton smartBtn = new JButton("Smart"); + smartBtn.addActionListener(a -> { + model.setAction(null); + view.repaint(); + }); + + actionList.add(smartBtn); + actionList.addSeparator(); + + for (GameAction act : x.getType().getAvailableActions()) { + JButton actBtn = new JButton(act.toString()); + actBtn.addActionListener(a -> { + model.setAction(act); + view.repaint(); + }); + + actionList.add(actBtn); + } + + actionList.addSeparator(); + } + JButton turnDone = new JButton("done"); turnDone.addActionListener(a -> { - model.done(); - view.repaint(); + model.done(); + view.repaint(); }); actionList.add(turnDone); - + actionList.invalidate(); actionList.revalidate(); actionList.repaint(); - + }); - + frame.add(actionList, BorderLayout.SOUTH); - + frame.pack(); frame.setVisible(true); UIController controller = new UIController(view, model); //controller.addPossibleActions(possibleActions); - + return new UIController(view, model); } } diff --git a/src/main/java/com/fossgalaxy/games/ggj2017/MineOrder.java b/src/main/java/com/fossgalaxy/games/ggj2017/MineOrder.java index 922a24f991d2d67447dfcd8c7e0ce73c9686ef21..29ad376fca55f9ff45764fe4ed4367808cbd8447 100644 --- a/src/main/java/com/fossgalaxy/games/ggj2017/MineOrder.java +++ b/src/main/java/com/fossgalaxy/games/ggj2017/MineOrder.java @@ -21,8 +21,8 @@ public class MineOrder implements Order { System.out.println("Mining"); Resource resource = gameState.getResourceAt(entity.getPos()); System.out.println(resource); - if(resource == null) return; - if(!typeToMine.equals(resource.getType())) return; + if (resource == null) return; + if (!typeToMine.equals(resource.getType())) return; int resourceMined = Math.min(resource.getAmountPerTurn(), quantityPerTurn); resourceMined = Math.max(0, resourceMined); System.out.println("Giving: " + resourceMined + " to " + entity.getOwner()); diff --git a/src/main/java/com/fossgalaxy/games/ggj2017/ResourceBar.java b/src/main/java/com/fossgalaxy/games/ggj2017/ResourceBar.java index 57f7f16f1e76729d45a49df00423653561c738ec..c02c2971f0c57563db2d5a0c6e14bf9c7bce292e 100644 --- a/src/main/java/com/fossgalaxy/games/ggj2017/ResourceBar.java +++ b/src/main/java/com/fossgalaxy/games/ggj2017/ResourceBar.java @@ -1,51 +1,46 @@ package com.fossgalaxy.games.ggj2017; -import java.awt.Dimension; -import java.awt.FontMetrics; -import java.awt.Graphics; - -import javax.swing.JComponent; - import com.fossgalaxy.games.rts.GameState; import com.fossgalaxy.games.rts.ui.UIModel; +import javax.swing.*; +import java.awt.*; + public class ResourceBar extends JComponent { - private String[] RESOURCE_NAMES = {"metal", "gold"}; - - private UIModel model; - private int playerID; - - public ResourceBar(UIModel model, int playerID) { - this.setPreferredSize(new Dimension(800, 20)); - this.model = model; - this.playerID = playerID; - } - - @Override - protected void paintComponent(Graphics g) { - super.paintComponent(g); - - GameState gs = model.getState(); - - FontMetrics metrics = g.getFontMetrics(); - int y = metrics.getHeight(); - - int startX = 0; - - for (String resource : RESOURCE_NAMES) { - int val = gs.getResource(playerID, resource); - - String out = String.format("%s: %d", resource, val); - int thisWidth = metrics.stringWidth(out); - - g.drawString(resource+": "+val, startX, y); - - startX += thisWidth + 20; - } - - } - - - + private String[] RESOURCE_NAMES = {"metal", "gold"}; + + private UIModel model; + private int playerID; + + public ResourceBar(UIModel model, int playerID) { + this.setPreferredSize(new Dimension(800, 20)); + this.model = model; + this.playerID = playerID; + } + + @Override + protected void paintComponent(Graphics g) { + super.paintComponent(g); + + GameState gs = model.getState(); + + FontMetrics metrics = g.getFontMetrics(); + int y = metrics.getHeight(); + + int startX = 0; + + for (String resource : RESOURCE_NAMES) { + int val = gs.getResource(playerID, resource); + + String out = String.format("%s: %d", resource, val); + int thisWidth = metrics.stringWidth(out); + + g.drawString(resource + ": " + val, startX, y); + + startX += thisWidth + 20; + } + + } + } diff --git a/src/main/java/com/fossgalaxy/games/ggj2017/UpgradeOrder.java b/src/main/java/com/fossgalaxy/games/ggj2017/UpgradeOrder.java index 48f3e570a33aad1d5b6d699d3594f126dee9408d..da68b1c04c62aa1cf787c4c6d7043e0652e5df99 100644 --- a/src/main/java/com/fossgalaxy/games/ggj2017/UpgradeOrder.java +++ b/src/main/java/com/fossgalaxy/games/ggj2017/UpgradeOrder.java @@ -6,24 +6,24 @@ import com.fossgalaxy.games.rts.entity.EntityType; import com.fossgalaxy.games.rts.order.Order; public class UpgradeOrder implements Order { - private EntityType from; - private EntityType to; - - public UpgradeOrder(EntityType from, EntityType to) { - this.from = from; - this.to = to; - } + private EntityType from; + private EntityType to; - @Override - public void doOrder(Entity host, GameState state) { - if (!from.equals(host.getType())) { - return; - } - - int newHealth = (int) ( host.getHealthFrac() * to.getProperty("health") ); - - host.setType(to); - host.setHealth(newHealth); - } + public UpgradeOrder(EntityType from, EntityType to) { + this.from = from; + this.to = to; + } + + @Override + public void doOrder(Entity host, GameState state) { + if (!from.equals(host.getType())) { + return; + } + + int newHealth = (int) (host.getHealthFrac() * to.getProperty("health")); + + host.setType(to); + host.setHealth(newHealth); + } } diff --git a/src/main/java/com/fossgalaxy/games/ggj2017/drones/DroneAttackAction.java b/src/main/java/com/fossgalaxy/games/ggj2017/drones/DroneAttackAction.java index 0bd1f2a08d07ea3ad59bb443d4afaf403f5f08a6..71e0b776237cbad1ea1009accda335c839ee30d2 100644 --- a/src/main/java/com/fossgalaxy/games/ggj2017/drones/DroneAttackAction.java +++ b/src/main/java/com/fossgalaxy/games/ggj2017/drones/DroneAttackAction.java @@ -1,35 +1,36 @@ package com.fossgalaxy.games.ggj2017.drones; -import java.awt.Graphics2D; -import com.fossgalaxy.object.annotations.ObjectDef; -import org.codetome.hexameter.core.api.CubeCoordinate; import com.fossgalaxy.games.rts.GameState; import com.fossgalaxy.games.rts.actions.RangeAttackAction; import com.fossgalaxy.games.rts.entity.Entity; +import com.fossgalaxy.object.annotations.ObjectDef; +import org.codetome.hexameter.core.api.CubeCoordinate; + +import java.awt.*; public class DroneAttackAction extends RangeAttackAction { - @ObjectDef("DroneAttack") - public DroneAttackAction() { - super(); - } - - @Override - public void renderHints(Graphics2D g, GameState s, Entity actor) { - if (actor == null || !DroneUtils.rangeHint(g, actor, s)) { - return; - } - - super.renderHints(g, s, actor); - } - - @Override - public boolean isPossible(Entity entity, GameState s, CubeCoordinate co) { - if (!DroneUtils.isZoneOfControl(s, entity)) { - return false; - } - - return super.isPossible(entity, s, co); - } - + @ObjectDef("DroneAttack") + public DroneAttackAction() { + super(); + } + + @Override + public void renderHints(Graphics2D g, GameState s, Entity actor) { + if (actor == null || !DroneUtils.rangeHint(g, actor, s)) { + return; + } + + super.renderHints(g, s, actor); + } + + @Override + public boolean isPossible(Entity entity, GameState s, CubeCoordinate co) { + if (!DroneUtils.isZoneOfControl(s, entity)) { + return false; + } + + return super.isPossible(entity, s, co); + } + } diff --git a/src/main/java/com/fossgalaxy/games/ggj2017/drones/DroneBuildAction.java b/src/main/java/com/fossgalaxy/games/ggj2017/drones/DroneBuildAction.java index a744ae3814ff14bd79569d6b3645b511d2cd6ce6..fa39be014bfe0615dbf899c3b6e6149a92fa0ed9 100644 --- a/src/main/java/com/fossgalaxy/games/ggj2017/drones/DroneBuildAction.java +++ b/src/main/java/com/fossgalaxy/games/ggj2017/drones/DroneBuildAction.java @@ -1,43 +1,44 @@ package com.fossgalaxy.games.ggj2017.drones; -import java.awt.Graphics2D; -import com.fossgalaxy.object.annotations.ObjectDef; -import org.codetome.hexameter.core.api.CubeCoordinate; import com.fossgalaxy.games.rts.GameState; import com.fossgalaxy.games.rts.actions.BuildAction; import com.fossgalaxy.games.rts.entity.Entity; import com.fossgalaxy.games.rts.entity.EntityType; import com.fossgalaxy.games.rts.order.BuildOrder; import com.fossgalaxy.games.rts.order.Order; +import com.fossgalaxy.object.annotations.ObjectDef; +import org.codetome.hexameter.core.api.CubeCoordinate; + +import java.awt.*; public class DroneBuildAction extends BuildAction { - @ObjectDef("DroneBuild") - public DroneBuildAction(EntityType type) { - super(type); - } - - @Override - public void renderHints(Graphics2D g, GameState s, Entity actor) { - if (actor == null || !DroneUtils.rangeHint(g, actor, s)) { - return; - } - - super.renderHints(g, s, actor); - } - - @Override - public Order generateOrder(CubeCoordinate co, GameState s) { - return new BuildOrder(type, co); - } - - @Override - public boolean isPossible(Entity entity, GameState s, CubeCoordinate co) { - if (!DroneUtils.isZoneOfControl(s, entity)) { - return false; - } - - return super.isPossible(entity, s, co); - } - + @ObjectDef("DroneBuild") + public DroneBuildAction(EntityType type) { + super(type); + } + + @Override + public void renderHints(Graphics2D g, GameState s, Entity actor) { + if (actor == null || !DroneUtils.rangeHint(g, actor, s)) { + return; + } + + super.renderHints(g, s, actor); + } + + @Override + public Order generateOrder(CubeCoordinate co, GameState s) { + return new BuildOrder(type, co); + } + + @Override + public boolean isPossible(Entity entity, GameState s, CubeCoordinate co) { + if (!DroneUtils.isZoneOfControl(s, entity)) { + return false; + } + + return super.isPossible(entity, s, co); + } + } diff --git a/src/main/java/com/fossgalaxy/games/ggj2017/drones/DroneBuildResourceAction.java b/src/main/java/com/fossgalaxy/games/ggj2017/drones/DroneBuildResourceAction.java index 9fee078f1cf29c6d86e00b05d1d26820d85b4b53..0ba810fafb765d9a6bba2c17f721d3e310907e72 100644 --- a/src/main/java/com/fossgalaxy/games/ggj2017/drones/DroneBuildResourceAction.java +++ b/src/main/java/com/fossgalaxy/games/ggj2017/drones/DroneBuildResourceAction.java @@ -1,46 +1,45 @@ package com.fossgalaxy.games.ggj2017.drones; -import java.awt.Graphics2D; -import com.fossgalaxy.object.annotations.ObjectDef; -import org.codetome.hexameter.core.api.CubeCoordinate; - import com.fossgalaxy.games.ggj2017.BuildOnResourceAction; import com.fossgalaxy.games.rts.GameState; -import com.fossgalaxy.games.rts.actions.BuildAction; import com.fossgalaxy.games.rts.entity.Entity; import com.fossgalaxy.games.rts.entity.EntityType; import com.fossgalaxy.games.rts.entity.ResourceType; import com.fossgalaxy.games.rts.order.BuildOrder; import com.fossgalaxy.games.rts.order.Order; +import com.fossgalaxy.object.annotations.ObjectDef; +import org.codetome.hexameter.core.api.CubeCoordinate; + +import java.awt.*; public class DroneBuildResourceAction extends BuildOnResourceAction { - @ObjectDef("DroneBuildResource") - public DroneBuildResourceAction(EntityType type, ResourceType rt) { - super(type, rt); - } - - @Override - public void renderHints(Graphics2D g, GameState s, Entity actor) { - if (actor == null || !DroneUtils.rangeHint(g, actor, s)) { - return; - } - - super.renderHints(g, s, actor); - } - - @Override - public Order generateOrder(CubeCoordinate co, GameState s) { - return new BuildOrder(type, co); - } - - @Override - public boolean isPossible(Entity entity, GameState s, CubeCoordinate co) { - if (!DroneUtils.isZoneOfControl(s, entity)) { - return false; - } - - return super.isPossible(entity, s, co); - } - + @ObjectDef("DroneBuildResource") + public DroneBuildResourceAction(EntityType type, ResourceType rt) { + super(type, rt); + } + + @Override + public void renderHints(Graphics2D g, GameState s, Entity actor) { + if (actor == null || !DroneUtils.rangeHint(g, actor, s)) { + return; + } + + super.renderHints(g, s, actor); + } + + @Override + public Order generateOrder(CubeCoordinate co, GameState s) { + return new BuildOrder(type, co); + } + + @Override + public boolean isPossible(Entity entity, GameState s, CubeCoordinate co) { + if (!DroneUtils.isZoneOfControl(s, entity)) { + return false; + } + + return super.isPossible(entity, s, co); + } + } diff --git a/src/main/java/com/fossgalaxy/games/ggj2017/drones/DroneMineAction.java b/src/main/java/com/fossgalaxy/games/ggj2017/drones/DroneMineAction.java index 99635df73e7db9decf8666fcab1da098fe0e8d6e..277ae1dae65fd6f21ee2bf0f26e809592521dfd7 100644 --- a/src/main/java/com/fossgalaxy/games/ggj2017/drones/DroneMineAction.java +++ b/src/main/java/com/fossgalaxy/games/ggj2017/drones/DroneMineAction.java @@ -1,36 +1,37 @@ package com.fossgalaxy.games.ggj2017.drones; -import java.awt.Graphics2D; -import com.fossgalaxy.object.annotations.ObjectDef; -import org.codetome.hexameter.core.api.CubeCoordinate; import com.fossgalaxy.games.rts.GameState; import com.fossgalaxy.games.rts.actions.MinesAction; import com.fossgalaxy.games.rts.entity.Entity; import com.fossgalaxy.games.rts.entity.ResourceType; +import com.fossgalaxy.object.annotations.ObjectDef; +import org.codetome.hexameter.core.api.CubeCoordinate; + +import java.awt.*; public class DroneMineAction extends MinesAction { - @ObjectDef("DroneMine") - public DroneMineAction(ResourceType type, int val) { - super(type, val); - } - - @Override - public void renderHints(Graphics2D g, GameState s, Entity actor) { - if (actor == null || !DroneUtils.rangeHint(g, actor, s)) { - return; - } - - super.renderHints(g, s, actor); - } - - @Override - public boolean isPossible(Entity entity, GameState s, CubeCoordinate co) { - if (!DroneUtils.isZoneOfControl(s, entity)) { - return false; - } - - return super.isPossible(entity, s, co); - } - + @ObjectDef("DroneMine") + public DroneMineAction(ResourceType type, int val) { + super(type, val); + } + + @Override + public void renderHints(Graphics2D g, GameState s, Entity actor) { + if (actor == null || !DroneUtils.rangeHint(g, actor, s)) { + return; + } + + super.renderHints(g, s, actor); + } + + @Override + public boolean isPossible(Entity entity, GameState s, CubeCoordinate co) { + if (!DroneUtils.isZoneOfControl(s, entity)) { + return false; + } + + return super.isPossible(entity, s, co); + } + } diff --git a/src/main/java/com/fossgalaxy/games/ggj2017/drones/DroneMoveAction.java b/src/main/java/com/fossgalaxy/games/ggj2017/drones/DroneMoveAction.java index fdb80ee5f1949bc68410dcab1f327c7d73b3ba13..3ab217de691d3cd07d9929b2636ee64595a57c54 100644 --- a/src/main/java/com/fossgalaxy/games/ggj2017/drones/DroneMoveAction.java +++ b/src/main/java/com/fossgalaxy/games/ggj2017/drones/DroneMoveAction.java @@ -1,41 +1,42 @@ package com.fossgalaxy.games.ggj2017.drones; -import java.awt.Graphics2D; -import com.fossgalaxy.object.annotations.ObjectDef; -import org.codetome.hexameter.core.api.CubeCoordinate; import com.fossgalaxy.games.rts.GameState; import com.fossgalaxy.games.rts.actions.MoveAction; import com.fossgalaxy.games.rts.entity.Entity; import com.fossgalaxy.games.rts.order.MoveOrder; import com.fossgalaxy.games.rts.order.Order; +import com.fossgalaxy.object.annotations.ObjectDef; +import org.codetome.hexameter.core.api.CubeCoordinate; + +import java.awt.*; public class DroneMoveAction extends MoveAction { - @ObjectDef("DroneMove") - public DroneMoveAction() { - } - - @Override - public void renderHints(Graphics2D g, GameState s, Entity actor) { - if (actor == null || !DroneUtils.rangeHint(g, actor, s)) { - return; - } - - super.renderHints(g, s, actor); - } - - @Override - public Order generateOrder(CubeCoordinate co, GameState s) { - return new MoveOrder(co); - } - - @Override - public boolean isPossible(Entity entity, GameState s, CubeCoordinate co) { - if (!DroneUtils.isZoneOfControl(s, entity)) { - return false; - } - - return super.isPossible(entity, s, co); - } - + @ObjectDef("DroneMove") + public DroneMoveAction() { + } + + @Override + public void renderHints(Graphics2D g, GameState s, Entity actor) { + if (actor == null || !DroneUtils.rangeHint(g, actor, s)) { + return; + } + + super.renderHints(g, s, actor); + } + + @Override + public Order generateOrder(CubeCoordinate co, GameState s) { + return new MoveOrder(co); + } + + @Override + public boolean isPossible(Entity entity, GameState s, CubeCoordinate co) { + if (!DroneUtils.isZoneOfControl(s, entity)) { + return false; + } + + return super.isPossible(entity, s, co); + } + } diff --git a/src/main/java/com/fossgalaxy/games/ggj2017/drones/DroneUpgradeAction.java b/src/main/java/com/fossgalaxy/games/ggj2017/drones/DroneUpgradeAction.java index 1372505719c9e89a2dd46377e6a7d4af51db1ef4..dd79a0b1702ce6f219489b1ee63f188454678145 100644 --- a/src/main/java/com/fossgalaxy/games/ggj2017/drones/DroneUpgradeAction.java +++ b/src/main/java/com/fossgalaxy/games/ggj2017/drones/DroneUpgradeAction.java @@ -1,36 +1,37 @@ package com.fossgalaxy.games.ggj2017.drones; -import java.awt.Graphics2D; -import com.fossgalaxy.object.annotations.ObjectDef; -import org.codetome.hexameter.core.api.CubeCoordinate; import com.fossgalaxy.games.rts.GameState; import com.fossgalaxy.games.rts.actions.UpgradeAction; import com.fossgalaxy.games.rts.entity.Entity; import com.fossgalaxy.games.rts.entity.EntityType; +import com.fossgalaxy.object.annotations.ObjectDef; +import org.codetome.hexameter.core.api.CubeCoordinate; + +import java.awt.*; public class DroneUpgradeAction extends UpgradeAction { - @ObjectDef("DroneUpgrade") - public DroneUpgradeAction(EntityType from, EntityType to) { - super(from, to); - } - - @Override - public void renderHints(Graphics2D g, GameState s, Entity actor) { - if (actor == null || !DroneUtils.rangeHint(g, actor, s)) { - return; - } - - super.renderHints(g, s, actor); - } - - @Override - public boolean isPossible(Entity entity, GameState s, CubeCoordinate co) { - if (!DroneUtils.isZoneOfControl(s, entity)) { - return false; - } - - return super.isPossible(entity, s, co); - } - + @ObjectDef("DroneUpgrade") + public DroneUpgradeAction(EntityType from, EntityType to) { + super(from, to); + } + + @Override + public void renderHints(Graphics2D g, GameState s, Entity actor) { + if (actor == null || !DroneUtils.rangeHint(g, actor, s)) { + return; + } + + super.renderHints(g, s, actor); + } + + @Override + public boolean isPossible(Entity entity, GameState s, CubeCoordinate co) { + if (!DroneUtils.isZoneOfControl(s, entity)) { + return false; + } + + return super.isPossible(entity, s, co); + } + } diff --git a/src/main/java/com/fossgalaxy/games/ggj2017/drones/DroneUtils.java b/src/main/java/com/fossgalaxy/games/ggj2017/drones/DroneUtils.java index 8f3a41fb778f9aa9d2d6988171cf2533d33f9fef..89c12bb404605610eccfd171cf9825ed807279a0 100644 --- a/src/main/java/com/fossgalaxy/games/ggj2017/drones/DroneUtils.java +++ b/src/main/java/com/fossgalaxy/games/ggj2017/drones/DroneUtils.java @@ -1,47 +1,46 @@ package com.fossgalaxy.games.ggj2017.drones; -import java.awt.Graphics; -import java.awt.image.BufferedImage; -import java.util.Collection; - -import org.codetome.hexameter.core.api.Hexagon; - import com.fossgalaxy.games.rts.GameState; import com.fossgalaxy.games.rts.entity.Entity; import com.fossgalaxy.games.rts.entity.HexagonTile; import com.fossgalaxy.games.rts.io.SpriteRegistry; +import org.codetome.hexameter.core.api.Hexagon; + +import java.awt.*; +import java.awt.image.BufferedImage; +import java.util.Collection; public class DroneUtils { - - public static boolean rangeHint(Graphics g, Entity actor, GameState s) { - if (!isZoneOfControl(s, actor)) { - SpriteRegistry sr = SpriteRegistry.INSTANCE; - BufferedImage img = sr.getImage("ui/no-signal"); - - Hexagon<HexagonTile> ht = s.cube2hex(actor.getPos()); - - g.drawImage(img, (int)ht.getCenterX() - 25, (int)ht.getCenterY() - 25, 50, 50, null); - - return false; - } - - return true; - } - - public static boolean isZoneOfControl(GameState state, Entity curr) { - Collection<Entity> entities = state.getOwnedEntities(curr.getOwner()); - - for (Entity e : entities) { - Integer zoneDistance = e.getType().getProperty("controlSignal"); - if (zoneDistance != null) { - int distance = state.getDistance(e.getPos(), curr.getPos()); - if (distance <= zoneDistance) { - return true; - } - } - } - - return false; - } - + + public static boolean rangeHint(Graphics g, Entity actor, GameState s) { + if (!isZoneOfControl(s, actor)) { + SpriteRegistry sr = SpriteRegistry.INSTANCE; + BufferedImage img = sr.getImage("ui/no-signal"); + + Hexagon<HexagonTile> ht = s.cube2hex(actor.getPos()); + + g.drawImage(img, (int) ht.getCenterX() - 25, (int) ht.getCenterY() - 25, 50, 50, null); + + return false; + } + + return true; + } + + public static boolean isZoneOfControl(GameState state, Entity curr) { + Collection<Entity> entities = state.getOwnedEntities(curr.getOwner()); + + for (Entity e : entities) { + Integer zoneDistance = e.getType().getProperty("controlSignal"); + if (zoneDistance != null) { + int distance = state.getDistance(e.getPos(), curr.getPos()); + if (distance <= zoneDistance) { + return true; + } + } + } + + return false; + } + }