Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
First commit
  • Loading branch information
jrb10014 committed Mar 27, 2015
0 parents commit a78f1b0
Show file tree
Hide file tree
Showing 15 changed files with 685 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
6 changes: 6 additions & 0 deletions .classpath
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="output" path="bin"/>
</classpath>
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
/bin/
17 changes: 17 additions & 0 deletions .project
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>TowerDefenseWork</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
11 changes: 11 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
@@ -0,0 +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.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
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
Binary file added src/.DS_Store
Binary file not shown.
49 changes: 49 additions & 0 deletions src/Main.java
@@ -0,0 +1,49 @@
import java.awt.*;
import javax.swing.*;

public class Main extends JFrame{


public static void main(String[] args) {
JFrame frame = new JFrame("Tower Defense Mock GUI");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(640,640+23);
int num = 6;
int[][] nodes = new int[num][2];
nodes[0][0] = 1;
nodes[0][1] = 3;
nodes[1][0] = 16;
nodes[1][1] = 3;
nodes[2][0] = 16;
nodes[2][1] = 9;
nodes[3][0] = 4;
nodes[3][1] = 9;
nodes[4][0] = 4;
nodes[4][1] = 15;
nodes[5][0] = 18;
nodes[5][1] = 15;
/*nodes[6][0] = 18;
nodes[6][1] = 13;
nodes[7][0] = 11;
nodes[7][1] = 13;
nodes[8][0] = 11;
nodes[8][1] = 1;*/
MockGui mg = new MockGui(640,640,32, num, nodes);
MapTowerDefense map = new MapTowerDefense(100, num, nodes, mg);
mg.setMap(map);
frame.add(mg);
frame.setVisible(true);
//StatGui sg = new StatGui(100, 640);
//sg.setLocation(640, 0);

//frame.add(sg);


//map.getTF().createBasicTower(14, 8);
map.createMinion(0);
mg.step();

}


}
46 changes: 46 additions & 0 deletions src/MapTowerDefense.java
@@ -0,0 +1,46 @@



public class MapTowerDefense {

private int maxTowers;
private int numNodes;
private int[][] nodes;
private MinionFactory MF;
private TowerFactory TF;
private MockGui MG;


public MapTowerDefense(int _maxTowers, int _numNodes, int[][] _nodes, MockGui _mg) {
maxTowers = _maxTowers;
numNodes = _numNodes;
nodes = _nodes;
MF = new MinionFactory(nodes[0][0], nodes[0][1], this);
TF = new TowerFactory(this, maxTowers);
MG = _mg;
}
public MinionFactory getMF() {
return MF;
}
public TowerFactory getTF() {
return TF;
}
public int getNum() {
return numNodes;
}
public int[][] getNodes() {
return nodes;
}
public MockGui getGui() {
return MG;
}
public void createMinion(int type) {
MF.createMinion(type);
}






}
Binary file added src/Minion.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions src/MinionFactory.java
@@ -0,0 +1,42 @@

public class MinionFactory {
private int X, Y;
private MapTowerDefense map;
private MinionMock[] minions;
private int Max;
private int id;

public MinionFactory(int x, int y, MapTowerDefense _map) {
X = x;
Y = y;
map = _map;
Max = 100;
id = 0;
minions = new MinionMock[Max];
}

public void createMinion(int type) {
MinionMock m = new MinionMock(type, map);
if (id < Max) {
minions[id] = m;
id++;
}
}
public MinionMock[] getMinions() {
return minions;
}
public int getNum() {
return id;
}

public void assignAllDamage() {
int i = 0;
while (i < id) {
if (minions[i].isAlive()) {
minions[i].minionTakeDamage();
}
i++;
}
}

}
98 changes: 98 additions & 0 deletions src/MinionMock.java
@@ -0,0 +1,98 @@

public class MinionMock {
int type;
MapTowerDefense map;
int x;
int y;
int speed;
int visits;
boolean alive;
int health;

public MinionMock(int _type, MapTowerDefense _map) {
type = _type;
map = _map;
int[] unhashed = map.getGui().hash(map.getNodes()[0][0], map.getNodes()[0][1]);
x = unhashed[0];
y = unhashed[1];
speed = 1;
visits = 1;
alive = true;
health = 255;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
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-=speed;
}
if (direction == 1) {
x+=speed;
}
if (direction == 2) {
y+=speed;
}
if (direction == 3) {
x-=speed;
}
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;
}

}
}

0 comments on commit a78f1b0

Please sign in to comment.