Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ssl10003 committed Apr 23, 2015
2 parents fc9a720 + a8fe91f commit 48e49ed
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 27 deletions.
57 changes: 31 additions & 26 deletions src/Main.java
Expand Up @@ -2,59 +2,64 @@ import java.awt.*;
import javax.swing.*;

public class Main extends JFrame{

private static int[][] nodes;
private static final int NUM = 6;

public static void main(String[] args) {
JFrame frame = new JFrame("Tower Defense Refactor Mock GUI");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(650,720);
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;*/

setupDefaultNodes();

JPanel container = new JPanel();
//container.setLayout(new BoxLayout(container, BoxLayout.X_AXIS));
container.setLayout(new BorderLayout(10,10));
MockGui mg = new MockGui(640,640,32, num, nodes);
MockGui mg = new MockGui(640,640,32, NUM, nodes);
StatGui sg= new StatGui(0,0);
//sg.setPreferredSize(new Dimension(1, 0)); //this keeps statgui from overlapping mockgui

//container.add(mg);
//container.add(sg);
container.add(mg, BorderLayout.CENTER);
container.add(sg, BorderLayout.PAGE_END);
container.add(sg, BorderLayout.SOUTH);


MapTowerDefense map = new MapTowerDefense(100, num, nodes, mg, sg);
MapTowerDefense map = new MapTowerDefense(100, NUM, nodes, mg, sg);
mg.setMap(map);
sg.setMap(map);
sg.setup();

frame.add(container);
frame.pack();
frame.setSize(650,720);
frame.setVisible(true);

map.createMinion(MinionTypes.BASIC);
mg.step();

}


private static void setupDefaultNodes()
{
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;*/

}
}
31 changes: 30 additions & 1 deletion src/TowerFactory.java
Expand Up @@ -58,20 +58,49 @@ public class TowerFactory {
}

public void createBasicTower(int x, int y, TowerTypes type){
System.out.println("x is: "+ x + " , y is: "+ y);
//Checks if there's already a tower here
//TODO make this better
if (!_map.getStatGui().spendMoney(cost)) {
if (!_map.getStatGui().canAfford(type.getBuycost())) { //check to see if player can afford
return;
}
if (quantity < _max) {
int i = 0;
//prevents tower from being placed on existing towers or on path
while (i < quantity) {
if ((towerarray[i].getTowerXlocation() == x) && (towerarray[i].getTowerYlocation() == y)) {
System.out.println("CONSEQUENCES WILL NEVER BE THE SAME"); //informal logging
return;
}
i++;
}

//first segment
if (((x >= 1) &&(x <= 16)) &&(y == 3)) {
System.out.println("NO TOWER ON PATH");
return;
}
//second segment
if (((y >= 3) &&(y <= 9)) &&(x == 16)) {
System.out.println("NO TOWER ON PATH");
return;
}
//third segment
if (((x >= 4) &&(x <= 16)) &&(y == 9)) {
System.out.println("NO TOWER ON PATH");
return;
}
//fourth segment
if (((y >= 9) &&(y <= 15)) &&(x == 4)) {
System.out.println("NO TOWER ON PATH");
return;
}
//fifth segment
if (((x >= 4) &&(x <= 18)) &&(y == 15)) {
System.out.println("NO TOWER ON PATH");
return;
}
_map.getStatGui().spendMoney(type.getBuycost()); //actually spend money, prevent double spending
towerarray[quantity] = new TowerMock(quantity, x, y, true, type, _map);
quantity++;
}
Expand Down

0 comments on commit 48e49ed

Please sign in to comment.