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/TowerMock.java
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
185 lines (144 sloc)
2.95 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
import java.awt.image.BufferedImage; | |
public class TowerMock{ | |
public int _xlocation, _ylocation, _sellCost, _buyCost, _range, _power, _upgradecost, _towerid; | |
public int _level = 1; | |
private BufferedImage _sprite; | |
public TowerTypes type; | |
public int health; // (FOR NEXUS ONLY) | |
private MapTowerDefense _map; | |
public boolean _isTower; //false is Nexus | |
public String Description = "Tower lol."; | |
public MinionMock currentTarget; | |
/* | |
public TowerMock(int id, int xloc, int yloc, boolean isTower){ | |
_towerid = id; | |
_xlocation = xloc; | |
_ylocation = yloc; | |
_isTower = isTower; | |
if (!isTower) { | |
health = 20; | |
} | |
} | |
*/ | |
public TowerMock(int id, int xloc, int yloc, boolean isTower, TowerTypes type, MapTowerDefense map){ | |
_towerid = id; | |
_map = map; | |
_xlocation = xloc; | |
_ylocation = yloc; | |
_isTower = isTower; | |
if (!isTower) { | |
health = 20; | |
_power = 0; | |
} | |
this.type=type; | |
this._buyCost=type.getBuycost(); | |
this._sellCost= type.getSellcost(); | |
this._power = type.getPower(); | |
this._range = type.getRange(); | |
this._sprite=type.getSprite(); | |
} | |
public BufferedImage getSprite(){ | |
return _sprite; | |
} | |
public int basicAttack() { | |
if (findMinion()) { | |
} | |
return 0; | |
} | |
public boolean basicDealDamage() { | |
if (findMinion()) { | |
currentTarget.minionTakeHit(_power); | |
return true; | |
} else { | |
return false; | |
} | |
} | |
public boolean findMinion() { | |
int i = 0; | |
while (i < 100) { | |
MinionMock m = _map.getMF().getMinions()[i]; | |
if (m == null) { | |
return false; | |
} | |
if (m.isAlive()) { | |
if (1 == inRange(m.getX(), m.getY())) { | |
currentTarget = m; | |
return true; | |
} | |
} | |
i++; | |
} | |
return false; | |
} | |
public int inRange(int x, int y) { | |
int deltax = (32*_xlocation - x); | |
int deltay = (32*_ylocation - y); | |
int dist2 = deltax*deltax + deltay*deltay; | |
if (dist2 > _range*_range) { | |
return 0; | |
} else { | |
return 1; | |
} | |
} | |
public boolean takeDamage(int damage) { | |
if (this.health <= damage) | |
{ | |
health = 0; | |
return true; //gameover | |
} | |
else | |
{ | |
health -= damage; | |
System.out.println(health); | |
return false; | |
} | |
} | |
public boolean takeDamage() { | |
return takeDamage(1); | |
} | |
public int getHealth() { | |
return health; | |
} | |
public int getTowerXlocation() { | |
return _xlocation; | |
} | |
public int getTowerYlocation() { | |
return _ylocation; | |
} | |
public int getPower() { | |
return _power; | |
} | |
public int getSellValue() { | |
return _sellCost; | |
} | |
public int getBuyCost() { | |
return _buyCost; | |
} | |
public int getRange(){ | |
return _range; | |
} | |
public int getUpgradeCost() { | |
_upgradecost = _buyCost * 2; | |
return _upgradecost; | |
} | |
public void upgrade(){ | |
this._power++; | |
this._range += 30; | |
_level++; | |
} | |
public int getLevel() { | |
return _level; | |
} | |
public boolean isActuallyTower() { | |
return _isTower; | |
} | |
public String getDescription() { | |
return Description; | |
} | |
public void setTarget(MinionMock aminion){ | |
currentTarget = aminion; | |
} | |
public int getID() { | |
return _towerid; | |
} | |
} |