From bf6bbd5609cd125d8b3e5a7fbe6f2cd49146af49 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Mon, 19 Nov 2018 00:02:46 +0100 Subject: Add TODOs for various corrections --- src/Actor.java | 12 +++++++++++- src/Battle.java | 24 ++++++++++++++++++++++-- src/Map.java | 13 +++++++++++++ src/MapEditor.java | 3 +++ src/MapLoader.java | 5 +++++ src/MapScene.java | 16 ++++++++++++++-- src/Scene.java | 14 +++++++++++++- src/Sub.java | 5 +++++ src/Tile.java | 13 ++++++++++++- src/Weapon.java | 4 ++++ 10 files changed, 102 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/Actor.java b/src/Actor.java index ca3995a..ef63217 100644 --- a/src/Actor.java +++ b/src/Actor.java @@ -1,22 +1,31 @@ public class Actor { + // TODO: make final private String name; - private boolean alive; + // TODO: could be replaced with `bool isAlive() { return this.hp > 0; }` + private boolean alive; + // TODO: enemy should not be binary (ex clans / groups / factions) private boolean enemy; private int hp; + // TODO: pack abilities / bonus / powers in structures private int agility; private int strenght; private int defense; + private int x; private int y; + private Weapon weapon; private int actionsLeft; + // TODO: make final private int actions = 2; + // TODO: make bonus / power-ups structure public Actor(String name, int hp, boolean enemy, int agility) { this.name = name; this.hp = hp; this.enemy = enemy; this.agility = agility; + // TODO: puch should have infinite durability this.weapon = new Weapon("fist", 1, 1, 10000000); this.alive = true; @@ -49,6 +58,7 @@ public class Actor { this.weapon = weapon; } + // TODO: could be `return this.hp > 0` and remove member public boolean isAlive() { return this.alive; } diff --git a/src/Battle.java b/src/Battle.java index d7b63cc..6f614eb 100644 --- a/src/Battle.java +++ b/src/Battle.java @@ -1,35 +1,48 @@ import java.util.ArrayList; import java.util.Collections; + import java.awt.Canvas; import java.awt.Graphics2D; import java.awt.Dimension; import java.awt.BorderLayout; import java.awt.GridLayout; + import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.awt.event.MouseWheelEvent; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; + import java.awt.image.BufferStrategy; + import java.awt.geom.Point2D; import java.awt.geom.NoninvertibleTransformException; + import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JButton; +// TODO: rename to BattleScene public class Battle extends MapScene { private enum Mode { NONE, ATTACK, MOVE }; + // TODO: make sub observe this object to remove this reference private Sub main; + // TODO: refractor, make Points() private int previousX = -1; private int previousY = -1; + // TODO: what the fuck is the difference between these two? private Actor selectedActor; private Actor lastActor; + private Mode mode; + private boolean actorClicked = false; + + // TODO: these are the coordinates of the mouse => refractor names private int realX = 0; private int realY = 0; @@ -44,6 +57,7 @@ public class Battle extends MapScene { this.setLayout(new BorderLayout()); + // TODO: make a method buildUi() ? JPanel bottomPanel = new JPanel(); bottomPanel.setLayout(new GridLayout(1,4)); @@ -167,8 +181,8 @@ public class Battle extends MapScene { } private void aiPlay() { - //TODO write AI - //controll back to the player + // TODO: write AI code + // give back control back to the player this.map.resetActors(); this.selectedActor = this.map.getNextActor(); this.lastActor = this.selectedActor; @@ -177,16 +191,21 @@ public class Battle extends MapScene { @Override public void mouseClicked(MouseEvent e) { + int tileSize = this.maxSize/10; Point2D p = new Point2D.Double(e.getX(), e.getY()); + try { p = this.tx.inverseTransform(p, null); } catch (NoninvertibleTransformException ex) {} + try { + // find actor under cursor int x = (int) (p.getX()/tileSize); int y = (int) (p.getY()/tileSize); Tile tile = this.map.getTile(x, y); Actor actor = null; + for (Actor i : this.map.getActors()) { if (x == i.getX() && y == i.getY()) { actor = i; @@ -269,6 +288,7 @@ public class Battle extends MapScene { @Override public void actionPerformed(ActionEvent e) { + // TODO: rename Ui elements to ex. btn-move, btn-pass, ... if ("move".equals(e.getActionCommand()) && this.selectedActor != null) { this.map.clearSelected(); this.mode = Mode.MOVE; diff --git a/src/Map.java b/src/Map.java index 7b178cf..a870604 100644 --- a/src/Map.java +++ b/src/Map.java @@ -3,15 +3,19 @@ import java.util.ArrayList; public class Map { private final Dimension size; + // TODO: is there a particular reason to not use a 2D array? private final Tile grid[]; private ArrayList actors = new ArrayList(); + // TODO: rename to selectedActor? private int actorIndex = -1; + // TODO: make selectedTile? Tile contains x and y members private int selectedX; private int selectedY; public Map(Dimension size) { this.size = size; + // TODO: replace with Dimension.height and Dimension.width which are integer public members this.grid = new Tile[(int) this.size.getWidth() * (int) this.size.getHeight()]; for (int x = 0; x < this.size.getWidth(); x++) { for (int y = 0; y < this.size.getHeight(); y++) { @@ -20,6 +24,7 @@ public class Map { } } + // pathfinding algorithm public ArrayList getPath(Actor actor, int x, int y) { ArrayList unsettled = new ArrayList(); ArrayList settled = new ArrayList(); @@ -46,10 +51,12 @@ public class Map { settled.add(i); } } + ArrayList out = new ArrayList(); Tile workingTile = this.getTile(x, y); double bestDistance = 1000000000; Tile bestTile = workingTile; + while (true) { for (Tile i : workingTile.getAdjacent(this)) { if (i.getDistance() < bestDistance) { @@ -69,6 +76,8 @@ public class Map { } public void update(ArrayList actorsList, Tile[] tileGrid) { + // TODO: if this is needed for something, implement copy constructors for Actor and Tile + // and delete this code for (Actor actor : actorsList) { Actor newActor = new Actor(actor.getName(), actor.getHP(), actor.isEnemy(), actor.getAgility()); newActor.place(actor.getX(), actor.getY()); @@ -83,6 +92,7 @@ public class Map { } } + // TODO: refractor to resetActorActions(); public void resetActors() { for (Actor actor : this.actors) { if (!actor.isEnemy()) { @@ -112,6 +122,8 @@ public class Map { return actor; } + // TODO: there is the Map cursor and the Mouse cursor, + // a solution to the naming shall be found public void setCursor(int x, int y) { this.getTile(this.selectedX, this.selectedY).setCursor(false); if (x == -1 && y == -1) { @@ -146,6 +158,7 @@ public class Map { this.actors.add(actor); } + // TODO: remove by introducing selectedTile member public void clearSelected() { for (Tile tile : this.grid) { tile.setSelected(false); diff --git a/src/MapEditor.java b/src/MapEditor.java index 864fab7..ee07d22 100644 --- a/src/MapEditor.java +++ b/src/MapEditor.java @@ -1,4 +1,5 @@ import java.util.ArrayList; + import java.awt.Canvas; import java.awt.Graphics2D; import java.awt.Dimension; @@ -13,6 +14,7 @@ import java.awt.image.BufferStrategy; import java.awt.geom.AffineTransform; import java.awt.geom.Point2D; import java.awt.geom.NoninvertibleTransformException; + import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JButton; @@ -22,6 +24,7 @@ import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.JFileChooser; import javax.swing.JCheckBox; + import java.lang.Integer; public class MapEditor extends MapScene { diff --git a/src/MapLoader.java b/src/MapLoader.java index 6478961..b55f2ac 100644 --- a/src/MapLoader.java +++ b/src/MapLoader.java @@ -1,13 +1,17 @@ import java.lang.String; + import java.io.File; import java.io.PrintWriter; import java.io.FileReader; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.IOException; + import java.awt.Dimension; + import com.google.gson.Gson; +// TODO: this class loads AND saves classes, refractor name class MapLoader { File path; @@ -28,6 +32,7 @@ class MapLoader { try { fr = new FileReader(this.path); bf = new BufferedReader(fr); + // TODO: read all while ((line = bf.readLine()) != null) { mapText = mapText + line; } diff --git a/src/MapScene.java b/src/MapScene.java index 41ad546..785698f 100644 --- a/src/MapScene.java +++ b/src/MapScene.java @@ -4,23 +4,31 @@ import java.awt.BasicStroke; import java.awt.Dimension; import java.awt.BorderLayout; import java.awt.GridLayout; + import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.awt.event.MouseWheelEvent; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; + import java.awt.image.BufferStrategy; + import java.awt.geom.AffineTransform; import java.awt.geom.Point2D; import java.awt.geom.NoninvertibleTransformException; + import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JButton; + import java.io.FileReader; import java.io.BufferedReader; import java.io.IOException; + +// TODO: remove unused import import com.google.gson.Gson; + public class MapScene extends Scene implements ActionListener { protected Map map; protected int panX = 0; @@ -46,6 +54,8 @@ public class MapScene extends Scene implements ActionListener { } else { this.maxSize = HEIGHT; } + + // TODO: negate if condition and return if (this.map != null) { Graphics2D g = (Graphics2D) this.buffer.getDrawGraphics(); //clear @@ -104,7 +114,7 @@ public class MapScene extends Scene implements ActionListener { tileSize, tileSize); } - //TODO set as class variables the storkes + //TODO: set as class variables the storkes if (tile.cursorOnIt()) { BasicStroke oldStroke = (BasicStroke) g.getStroke(); g.setStroke(new BasicStroke( @@ -148,7 +158,7 @@ public class MapScene extends Scene implements ActionListener { (tileSize*4/5)*actor.getHP()/10, tileSize/10); } - + // Restore absolute coordinates AffineTransform invertTx = null; try { invertTx = this.tx.createInverse(); @@ -162,10 +172,12 @@ public class MapScene extends Scene implements ActionListener { } } + // TODO: make abstract protected void absoluteRender(Graphics2D g) { } + // TODO: remove this overridden method and leave abstract @Override protected void update(int deltaTime) { } diff --git a/src/Scene.java b/src/Scene.java index dcc3e5e..08608cf 100644 --- a/src/Scene.java +++ b/src/Scene.java @@ -2,6 +2,7 @@ import java.awt.Canvas; import java.awt.Graphics2D; import java.awt.Dimension; import java.awt.BorderLayout; + import java.awt.event.KeyListener; import java.awt.event.KeyEvent; import java.awt.event.MouseListener; @@ -10,20 +11,28 @@ import java.awt.event.MouseMotionListener; import java.awt.event.MouseWheelListener; import java.awt.event.MouseWheelEvent; import java.awt.image.BufferStrategy; + import javax.swing.JFrame; import javax.swing.JPanel; +// TODO: implement pause (rendering) function public class Scene extends JPanel implements Runnable, KeyListener, MouseListener, MouseMotionListener, MouseWheelListener { + // TODO: lowercase not constant values protected int WIDTH; protected int HEIGHT; protected BufferStrategy buffer; + // TODO: make final protected long desiredFPS = 60; + // TODO: make final protected long desiredDeltaLoop = (1000*1000*1000)/desiredFPS; protected JFrame frame; protected boolean running; protected Canvas canvas; + + // TODO: make accessible from user settings protected int guiSize = 2; + // TODO: remove sub argument protected Scene(JFrame frame, Sub sub) { this.frame = frame; //getting window size @@ -41,6 +50,7 @@ public class Scene extends JPanel implements Runnable, KeyListener, MouseListen this.canvas.addMouseWheelListener(this); } + // TODO: fix this weird memory shit public void start() { this.canvas.createBufferStrategy(2); this.buffer = this.canvas.getBufferStrategy(); @@ -60,6 +70,7 @@ public class Scene extends JPanel implements Runnable, KeyListener, MouseListen while (running) { beginLoopTime = System.nanoTime(); + // TODO: use WindowEventListener to wait for changes //getting window size this.WIDTH = (int) this.frame.getSize().getWidth(); this.HEIGHT = (int) this.frame.getSize().getHeight(); @@ -74,7 +85,7 @@ public class Scene extends JPanel implements Runnable, KeyListener, MouseListen deltaLoop = endLoopTime - beginLoopTime; if (deltaLoop > this.desiredDeltaLoop) { - //late + // late => skip frame } else { try { Thread.sleep((this.desiredDeltaLoop - deltaLoop)/(1000*1000)); @@ -85,6 +96,7 @@ public class Scene extends JPanel implements Runnable, KeyListener, MouseListen } } + // TODO: make abstract protected void render() {} protected void update(int deltaTime) {} diff --git a/src/Sub.java b/src/Sub.java index 06e59c2..e365032 100644 --- a/src/Sub.java +++ b/src/Sub.java @@ -1,8 +1,12 @@ +// TODO: package + import java.awt.Dimension; import java.awt.GridLayout; + import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JButton; + import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -12,6 +16,7 @@ public class Sub implements ActionListener { private JFrame frame; private JPanel menu; + // TODO: remove map editor, start directly on Battle mode public Sub() { this.frame = new JFrame("Sub"); diff --git a/src/Tile.java b/src/Tile.java index f2548f7..7420a2a 100644 --- a/src/Tile.java +++ b/src/Tile.java @@ -5,11 +5,20 @@ public class Tile { CLEAR, GRASS, WATER, MOUNTAIN, NONE }; + // TODO: make public private final int x, y; + // TODO: make final private Type type; + // TODO: refractor to inRange; private boolean selected; - private boolean cursorOnIt; + // TODO: it would be better if the MapScene had a member tileUnderCursor + private boolean cursorOnIt; // underCursor? + // TODO: make final, or make a table to match type to cost private double cost; + // TODO: remove and make here a method + // double distanceFrom(Tile other); + // or a method in Map.java + // double distanceBetween(Tile firstTile, Tile secondTile); private double distance; public Tile(Type type, int x, int y) { @@ -64,6 +73,7 @@ public class Tile { return this.type; } + // TODO: remove this feature and make the member final public void setType(Type type) { this.type = type; switch (this.type) { @@ -99,6 +109,7 @@ public class Tile { return this.selected; } + // TODO: rename to isInRange() and this.selected => inRange public boolean isSelected() { return this.selected; } diff --git a/src/Weapon.java b/src/Weapon.java index 36c2ab7..de6eb26 100644 --- a/src/Weapon.java +++ b/src/Weapon.java @@ -1,9 +1,12 @@ +// TODO: there are object such as "puch" that need infinite durability public class Weapon { private boolean broken; + // TODO: if possible make final private int damage; private int durability; private int range; private String name; + // TODO: add bonus / power-ups structure public Weapon(String name, int damage, int range, int durability) { this.name = name; @@ -27,6 +30,7 @@ public class Weapon { return false; } + // TODO: bugfix durability-- iff damage has been done this.durability--; if (this.durability <= 0) { this.broken = true; -- cgit v1.2.1