Skip to content

Commit

Permalink
New Minions Types
Browse files Browse the repository at this point in the history
Money plays role
Towers cost money
Minion deaths give you money
Minions deal damage beside value 1
  • Loading branch information
jrb10014 committed Apr 15, 2015
1 parent b4cd1a6 commit 5dc3172
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 15 deletions.
27 changes: 24 additions & 3 deletions src/MinionMock.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@


public class MinionMock {
private int x, y, speed, visits, health, attackDamage;
private int x, y, speed, visits, health, attackDamage, maxHealth;
private MinionTypes type;
private boolean alive;
private MapTowerDefense map;
private BufferedImage sprite;
private int value;
private String name;

public MinionMock(MinionTypes type, MapTowerDefense map) {
this.type = type;
Expand All @@ -15,9 +17,12 @@ public MinionMock(MinionTypes type, MapTowerDefense map) {
x = unhashed[0];
y = unhashed[1];
health = type.getHealth();
maxHealth = health;
name = type.getName();
attackDamage = type.getAttackDamage();
speed = type.getMovementSpeed();
sprite = type.getSprite();
value = type.getValue();
visits = 1;
alive = true;
}
Expand Down Expand Up @@ -71,7 +76,7 @@ public boolean go() {
int direction = findDirection();
if (direction == -1) {
alive = false;
return map.getTF().getTowerArray()[0].takeDamage();
return map.getTF().getTowerArray()[0].takeDamage(attackDamage);
}
if (direction == 0) {
y-=speed;
Expand All @@ -94,11 +99,27 @@ public boolean isAlive() {
public int getHealth() {
return health;
}
public int getMaxHealth() {
return maxHealth;
}
public String getName() {
return name;
}
public int getValue() {
return value;
}
public int getAttackDamage() {
return attackDamage;
}

public void minionTakeDamage() {
int dam = map.getTF().assignTotalDamage(x, y);
health-=dam;
if (health <= 0) {
alive = false;
if (alive == true) {
map.getStatGui().payDay(value);
alive = false;
}
}

}
Expand Down
29 changes: 21 additions & 8 deletions src/MinionTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,27 @@
import javax.imageio.ImageIO;

public enum MinionTypes {
//NAME (Health, Attack, Speed)
WEAKLING(100, 1, 1, "Basic Minion.png"),
BASIC (255, 1, 1, "Basic Minion.png"),
SPEEDO (100, 1, 4, "Basic Minion.png"),
SUPERSPEEDO (255, 1, 4, "Basic Minion.png");
//NAME (Health, Attack, Speed, goldValue)
WEAKLING(100, 1, 1, "Basic Minion.png", 1),
BASIC (255, 1, 1, "Basic Minion.png", 2),
SPEEDO (100, 1, 4, "Basic Minion.png", 3),
SUPERSPEEDO (255, 1, 4, "Basic Minion.png", 5),
JUGGERNAUT (1000, 1, 1, "Basic Minion.png", 10),
UNKILLABLE (10000,1,1, "Basic Minion.png", 100),
DOUBLEBASIC(255, 2, 1, "Basic Minion.png", 12),
SUPERKILLER(10, 20, 8, "Basic Minion.png", 100),
MONEYBAGS(350, 1, 2, "Basic Minion.png", 50);

private int health, attackDamage, movementSpeed;

private int health, attackDamage, movementSpeed, value;
private BufferedImage sprite;
private static final String SPRITE_FILE_DIR = "src/";

MinionTypes(int health, int attackDamage, int movementSpeed, String spriteFileName) {
MinionTypes(int health, int attackDamage, int movementSpeed, String spriteFileName, int value) {
this.health = health;
this.attackDamage = attackDamage;
this.movementSpeed = movementSpeed;
this.value = value;
try {
this.sprite = ImageIO.read(new File(SPRITE_FILE_DIR.concat(spriteFileName)));
} catch (IOException ex) {
Expand All @@ -34,10 +41,16 @@ public int getAttackDamage() {
return attackDamage;
}

public String getName() {
return this.toString();
}

public int getMovementSpeed() {
return movementSpeed;
}

public int getValue() {
return value;
}
public BufferedImage getSprite()
{
return sprite;
Expand Down
12 changes: 8 additions & 4 deletions src/MockGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ public void paint(Graphics g) {
drawGrid(x, y, gridsize, g);
//drawMinion(96,96,0,g);
colorPath(g);

drawAllMinions(map.getMF(), g);
drawAllTowers(map.getTF(), g);
drawAllMinions(map.getMF(), g);
drawPlayerHealth(g);
}
public void drawGrid(int x, int y, int gridSize, Graphics g) {
Expand Down Expand Up @@ -173,14 +172,19 @@ public void drawPlayerHealth(Graphics g) {
}

public void drawMinion(int x, int y, int health, Graphics g) {

g.drawImage(image, x,y, null);
}
// IS THIS METHOD STILL CALLED?


public void drawMinion(MinionMock m, Graphics g)
{
g.drawImage(m.getSprite(), m.getX(), m.getY(), null);

String h = "[" + m.getHealth() + "/" + m.getMaxHealth() +"]";
g.setColor(Color.RED);
g.drawString(h, m.getX()-15, m.getY()-10);
//g.drawString(m.getName(), m.getX()-15, m.getY()+45);
//g.drawString(("V: " + m.getValue() + "\nD: " + m.getAttackDamage()), m.getX(), m.getY()+46);
}

public void drawAllTowers(TowerFactory TF, Graphics g) {
Expand Down
24 changes: 24 additions & 0 deletions src/StatGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,30 @@ public StatGui (int x, int y) {
Y = y;

}
public int getMoney() {
return playermoney;
}
public boolean canAfford(int cost) {
if (playermoney >= cost) {
return true;
} else {
return false;
}
}

public boolean spendMoney(int cost) {
if (canAfford(cost)) {
playermoney -= cost;
return true;
} else {
return false;
}
}

public boolean payDay(int value) {
playermoney += value;
return true;
}

public void setMap(MapTowerDefense map){
this.map=map;
Expand Down
5 changes: 5 additions & 0 deletions src/TowerFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ public class TowerFactory {
TowerMock[] towerarray;
int quantity;
int _max;
int cost;

public TowerFactory(MapTowerDefense amap, int max){
_map = amap;
_max = max;
towerarray = new TowerMock[_max];
createNexus();
quantity = 1;
cost = 100;
}
public int assignTotalDamage(int x, int y) {
int i = 1;
Expand Down Expand Up @@ -47,6 +49,9 @@ public void createNexus(){
public void createBasicTower(int x, int y){
//Checks if there's already a tower here
//TODO make this better
if (!_map.getStatGui().spendMoney(cost)) {
return;
}
if (quantity < _max) {
int i = 0;
while (i < quantity) {
Expand Down
8 changes: 8 additions & 0 deletions src/TowerMock.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ public int dealDamage(int x, int y) {
}

}
public boolean takeDamage(int i) {
if (i > 1) {
takeDamage();
return takeDamage(i-1);
} else {
return takeDamage();
}
}

public boolean takeDamage() {
health--;
Expand Down

0 comments on commit 5dc3172

Please sign in to comment.