If you think the Android project Apocalypse-Defense listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.apocalypsedefense.core;
//www.java2s.compublicclass Person extends MapElement {
publicint hp;
publicboolean isAlive;
public Weapon weapon;
privateint previousHealth;
public Person(Weapon weapon, int hp, int size, Point position) {
super(size,position);
this.hp = hp;
this.isAlive = true;
this.weapon = weapon;
previousHealth = hp;
}
publicvoid takeDamage(int damage) {
this.hp = this.hp - damage;
if (this.hp <= 0){ //If the actor died
this.isAlive = false;
}
}
publicint attack() {
return 0;
}
publicvoid getStats(){
System.out.print("HP:" + this.hp);
System.out.print("Position:" + this.position);
}
privatestaticfinalint ATTACK_COUNTER_START = 5; // How many frames to indicate being attacked
privateint wasAttackedCounter=0;
publicboolean isBeingAttacked() {
if (wasAttackedCounter > 0) {
wasAttackedCounter--;
return true;
}
if (hp < previousHealth) {
wasAttackedCounter = ATTACK_COUNTER_START;
previousHealth = hp;
return true;
}
return false;
}
}
/*
Python code:
class Person(MapElement):
def __init__(self, weapon, hp=100, size=(1,1), position=(0,0)):
MapElement.__init__(self, size, position)
self.hp = hp
self.isAlive = True
self.weapon = weapon
def takeDamage(self, damage):
self.hp = self.hp - damage
if self.hp <= 0: #If the actor died
self.isAlive = False
def attack(self):
pass
def getStats(self):
print 'HP: ' + str(self.hp)
print 'Position: ' + str(self.position)
*/