-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhealth.ts
44 lines (35 loc) · 1.02 KB
/
health.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/// <reference path="typings/index.d.ts" />
class Health {
private div : HTMLElement;
private _percentage : number;
private game : Game;
get percentage(){
return this._percentage;
}
set percentage(value){
this._percentage = value;
this.displayHealth(this._percentage);
}
constructor(g : Game){
this.div = document.createElement("health");
document.body.appendChild(this.div);
this.div.style.position = "absolute";
this.div.style.top = 20 + "px";
this.div.style.left = window.innerWidth - 200 + "px";
this._percentage = 100;
this.displayHealth(this._percentage);
this.game = g;
}
private displayHealth(percentage : number) : void {
this.div.innerHTML = "Health: " + percentage + "%";
}
public checkDeath() : boolean {
if(this._percentage <= 0){
return true;
}
return false;
}
public remove() : void {
this.div.remove();
}
}