diff --git a/.classpath b/.classpath
index fceb480..91ee9a5 100644
--- a/.classpath
+++ b/.classpath
@@ -1,6 +1,6 @@
-
-
-
-
-
-
+
+
+
+
+
+
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
index 3a21537..7341ab1 100644
--- a/.settings/org.eclipse.jdt.core.prefs
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -1,11 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.8
+org.eclipse.jdt.core.compiler.source=1.7
diff --git a/src/Main.java b/src/Main.java
index 2662edc..e24d452 100644
--- a/src/Main.java
+++ b/src/Main.java
@@ -5,7 +5,7 @@ public class Main extends JFrame{
public static void main(String[] args) {
- JFrame frame = new JFrame("Tower Defense Mock GUI");
+ JFrame frame = new JFrame("Tower Defense Refactor Mock GUI");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(640,640+23);
int num = 6;
@@ -40,7 +40,7 @@ public class Main extends JFrame{
//map.getTF().createBasicTower(14, 8);
- map.createMinion(0);
+ map.createMinion(MinionTypes.BASIC);
mg.step();
}
diff --git a/src/MapTowerDefense.java b/src/MapTowerDefense.java
index 17749f3..309f929 100644
--- a/src/MapTowerDefense.java
+++ b/src/MapTowerDefense.java
@@ -34,7 +34,7 @@ public class MapTowerDefense {
public MockGui getGui() {
return MG;
}
- public void createMinion(int type) {
+ public void createMinion(MinionTypes type) {
MF.createMinion(type);
}
diff --git a/src/MinionFactory.java b/src/MinionFactory.java
index 544f45d..964aa84 100644
--- a/src/MinionFactory.java
+++ b/src/MinionFactory.java
@@ -15,7 +15,7 @@ public class MinionFactory {
minions = new MinionMock[Max];
}
- public void createMinion(int type) {
+ public void createMinion(MinionTypes type) {
MinionMock m = new MinionMock(type, map);
if (id < Max) {
minions[id] = m;
diff --git a/src/MinionMock.java b/src/MinionMock.java
index b1dc1ef..d065834 100644
--- a/src/MinionMock.java
+++ b/src/MinionMock.java
@@ -1,24 +1,19 @@
public class MinionMock {
- int type;
- MapTowerDefense map;
- int x;
- int y;
- int speed;
- int visits;
- boolean alive;
- int health;
+ private int type, x, y, speed, visits, health, attackDamage;
+ private boolean alive;
+ private MapTowerDefense map;
- public MinionMock(int _type, MapTowerDefense _map) {
- type = _type;
- map = _map;
+ public MinionMock(MinionTypes type, MapTowerDefense map) {
+ this.map = map;
int[] unhashed = map.getGui().hash(map.getNodes()[0][0], map.getNodes()[0][1]);
x = unhashed[0];
y = unhashed[1];
- speed = 1;
+ health = type.getHealth();
+ attackDamage = type.getAttackDamage();
+ speed = type.getMovementSpeed();
visits = 1;
alive = true;
- health = 255;
}
public int getX() {
return x;
@@ -27,7 +22,7 @@ public class MinionMock {
return y;
}
public int getType() {
- return type;
+ return 0; //TODO
}
public int findDirection() {
if (visits == map.getNum()) {
diff --git a/src/MinionTypes.java b/src/MinionTypes.java
new file mode 100644
index 0000000..a4e6a91
--- /dev/null
+++ b/src/MinionTypes.java
@@ -0,0 +1,103 @@
+
+public enum MinionTypes {
+
+ BASIC (255, 1, 1);
+
+ private int health, attackDamage, movementSpeed;
+
+ MinionTypes(int health, int attackDamage, int movementSpeed) {
+ this.health = health;
+ this.attackDamage = attackDamage;
+ this.movementSpeed = movementSpeed;
+ }
+
+ public int getHealth() {
+ return health;
+ }
+
+ public int getAttackDamage() {
+ return attackDamage;
+ }
+
+ public int getMovementSpeed() {
+ return movementSpeed;
+ }
+
+ /*
+ public int getType() {
+ return type;
+ }
+ */
+
+ /*
+ public int findDirection() {
+ if (visits == map.getNum()) {
+ // CALL TO MAKE NEXUS LOSE HEALTH
+ return -1;
+ } else {
+ int xGoal = map.getNodes()[visits][0];
+ int yGoal = map.getNodes()[visits][1];
+ int[] Goals = map.getGui().hash(xGoal, yGoal);
+ xGoal = Goals[0];
+ yGoal = Goals[1];
+ if (x == xGoal) {
+ if (y == yGoal) {
+ visits++;
+ return findDirection();
+ }
+ if (yGoal > y) {
+ // MOVE DOWN
+ return 2;
+ } else {
+ return 0;
+ }
+ } else {
+ if (x > xGoal) {
+ return 3;
+ } else {
+ return 1;
+ }
+ }
+ }
+ }
+
+
+
+ public boolean go() {
+ int direction = findDirection();
+ if (direction == -1) {
+ alive = false;
+ return map.getTF().getTowerArray()[0].takeDamage();
+ }
+ if (direction == 0) {
+ y-=movespeed;
+ }
+ if (direction == 1) {
+ x+=movespeed;
+ }
+ if (direction == 2) {
+ y+=movespeed;
+ }
+ if (direction == 3) {
+ x-=movespeed;
+ }
+ return false;
+ }
+
+
+ public boolean isAlive() {
+ return alive;
+ }
+ public int getHealth() {
+ return health;
+ }
+ public void minionTakeDamage() {
+ int dam = map.getTF().assignTotalDamage(x, y);
+ health-=dam;
+ if (health <= 0) {
+ alive = false;
+ }
+
+ }
+ */
+}
diff --git a/src/MockGui.java b/src/MockGui.java
index 01402b2..79e4fce 100644
--- a/src/MockGui.java
+++ b/src/MockGui.java
@@ -8,44 +8,47 @@ import java.awt.event.MouseMotionListener;
import java.awt.geom.*;
public class MockGui extends JPanel{
- boolean gameEnd;
- private int X, Y, GRIDSIZE, NUMNODES;
- private int[][] NODES;
- private MapTowerDefense map;
+ boolean gameOver;
+ private int x, y, gridsize, numnodes;
+ private int[][] nodes;
+ private MapTowerDefense map;//
public MockGui(int x, int y, int gridSize, int numNodes, int[][] nodes) {
- X = x;
- Y = y;
- gameEnd = false;
- GRIDSIZE = gridSize;
- NUMNODES = numNodes;
- NODES = nodes;
+ this.x = x;
+ this.y = y;
+ gameOver = false;
+ this.gridsize = gridSize;
+ this.numnodes = numNodes;
+ this.nodes = nodes;
TowerPlacer TP = new TowerPlacer();
this.addMouseListener(TP);
- this.addMouseMotionListener(TP);
+ //this.addMouseMotionListener(TP);
repaint();
}
- public void setMap(MapTowerDefense _map) {
- map = _map;
+ public void setMap(MapTowerDefense map) {
+ this.map = map;//
}
public void step() {
int i = 0;
- while (!gameEnd) {
+ while (!gameOver) {
try {
Thread.sleep(10);
repaint();
i++;
- //map.getMF().getMinions()[0].minionTakeDamage();
+ //
+ map.getMF().getMinions()[0].minionTakeDamage();
+
map.getMF().assignAllDamage();
if (i > 63) {
- map.createMinion(0);
+ map.createMinion(MinionTypes.BASIC);
i = 0;
}
+ //
} catch (InterruptedException e) {
//e.printStackTrace();
}
@@ -54,12 +57,12 @@ public class MockGui extends JPanel{
public void paint(Graphics g) {
setBackground(new Color(99, 209, 62));
- drawGrid(X, Y, GRIDSIZE, g);
+ drawGrid(x, y, gridsize, g);
//drawMinion(96,96,0,g);
colorPath(g);
drawAllMinions(map.getMF(), g);
drawAllTowers(map.getTF(), g);
- drawHealth(g);
+ drawPlayerHealth(g);
}
public void drawGrid(int x, int y, int gridSize, Graphics g) {
g.setColor(Color.BLACK);
@@ -77,20 +80,20 @@ public class MockGui extends JPanel{
public int[] hash (int x, int y) {
// Convert x y on grid to pixel
int[] result = new int[2];
- result[0] = x*GRIDSIZE;
- result[1] = y*GRIDSIZE;
+ result[0] = x*gridsize;
+ result[1] = y*gridsize;
return result;
}
public int[] unhash(int x, int y) {
int[] result = new int[2];
- result[0] = x/GRIDSIZE;
- result[1] = y/GRIDSIZE;
+ result[0] = x/gridsize;
+ result[1] = y/gridsize;
return result;
}
public void colorBlock(int x, int y, Graphics g) {
int[] coords = hash(x,y);
- g.fillRect(coords[0], coords[1], GRIDSIZE, GRIDSIZE);
+ g.fillRect(coords[0], coords[1], gridsize, gridsize);
}
public void colorBlocks(int x1, int y1, int x2, int y2, Graphics g) {
if (x1 == x2) {
@@ -124,8 +127,8 @@ public class MockGui extends JPanel{
public void colorPath(Graphics g) {
int i = 1;
g.setColor(new Color(213,196,161));
- while (i < NUMNODES) {
- colorBlocks(NODES[i-1][0], NODES[i-1][1], NODES[i][0], NODES[i][1], g);
+ while (i < numnodes) {
+ colorBlocks(nodes[i-1][0], nodes[i-1][1], nodes[i][0], nodes[i][1], g);
i++;
}
}
@@ -134,9 +137,9 @@ public class MockGui extends JPanel{
while (i < MF.getNum()) {
if (MF.getMinions()[i].isAlive()) {
drawMinion(MF.getMinions()[i].getX(), MF.getMinions()[i].getY(), MF.getMinions()[i].getHealth(), g);
- if (MF.getMinions()[i].go())
+ if (MF.getMinions()[i].go()) //TODO view code controlling model behavior. Bad! Need to refactor
{
- gameEnd = true;
+ gameOver = true;
}
}
@@ -144,7 +147,7 @@ public class MockGui extends JPanel{
}
}
- public void drawHealth(Graphics g) {
+ public void drawPlayerHealth(Graphics g) {
int health = map.getTF().getTowerArray()[0].getHealth();
g.setColor(new Color(0,255,0));
colorBlocks(19, 0, 19, health, g);
@@ -171,25 +174,8 @@ public class MockGui extends JPanel{
g.fillRect(x, y, 32, 32);
}
- private class TowerPlacer implements MouseListener, MouseMotionListener{
-
- @Override
- public void mouseDragged(MouseEvent e) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void mouseMoved(MouseEvent e) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void mouseClicked(MouseEvent e) {
- // TODO Auto-generated method stub
-
- }
+
+ private class TowerPlacer extends MouseAdapter{
@Override
public void mousePressed(MouseEvent e) {
@@ -200,24 +186,6 @@ public class MockGui extends JPanel{
map.getTF().createBasicTower(local[0], local[1]);
}
-
- @Override
- public void mouseReleased(MouseEvent e) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void mouseEntered(MouseEvent e) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void mouseExited(MouseEvent e) {
- // TODO Auto-generated method stub
-
- }
}