Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
TowerDefense/src/MinionMock.java
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
93 lines (88 sloc)
1.72 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MinionMock { | |
private int type, x, y, speed, visits, health, attackDamage; | |
private boolean alive; | |
private MapTowerDefense 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]; | |
health = type.getHealth(); | |
attackDamage = type.getAttackDamage(); | |
speed = type.getMovementSpeed(); | |
visits = 1; | |
alive = true; | |
} | |
public int getX() { | |
return x; | |
} | |
public int getY() { | |
return y; | |
} | |
public int getType() { | |
return 0; //TODO | |
} | |
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; | |
} | |
} | |
} |