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.
195 lines (154 sloc)
3.37 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, _upgradecost, _towerid; | |
public int _level = 1; | |
public int _range = 96; | |
public int _power = 1; | |
public double _firerate = 1.0; | |
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._sprite=type.getSprite(); | |
} | |
public BufferedImage getSprite(){ | |
return _sprite; | |
} | |
public int basicAttack() { | |
if (findMinion()) { | |
} | |
return 0; | |
} | |
public boolean basicDealDamage() { | |
if (findMinion()) { | |
currentTarget.minionTakeHit(1); | |
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 getRange() { | |
return _range; | |
} | |
public double getFireRate() { | |
return _firerate; | |
} | |
public int getPower() { | |
return _power; | |
} | |
//get overall resale value of towers, at half of purchase cost | |
public int getSellValue() { | |
return (int) (_range + (_power * 10)+ (_firerate * 10))/2; | |
} | |
//get cost this tower was purchased for | |
public int getCost() { | |
_buyCost = (int) (_range + ( _power * 10) + (_firerate * 10)); | |
return _buyCost; | |
} | |
//get upgrade cost to upgrade tower, double the price of last cost | |
public int getupgradeCost() { | |
_upgradecost = _buyCost * 2; | |
return _upgradecost; | |
} | |
public void upgrade(){ | |
_buyCost = _upgradecost; | |
_level = _level + 1; | |
this._range = this._range + 1; | |
this._firerate= this._firerate + 0.3; | |
this._power = this._power + 1; | |
} | |
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; | |
} | |
} |