Created
August 22, 2012 11:10
-
-
Save jake7864/3424486 to your computer and use it in GitHub Desktop.
a stat bar object with 2 variables cur + max & it also as methods for handling those variables
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 Stat | |
{ | |
private double cur = 0; | |
private double max = 0; | |
public Stat(int max) | |
{ | |
this.max = max; | |
cur = max; | |
} | |
public void add(double num) | |
{ | |
if(cur<=max)cur+=num; | |
if(cur>max)cur=max; | |
} | |
public void sub(double num) | |
{ | |
if(cur>=0)cur-=num; | |
if(cur<0)cur=0; | |
} | |
public void fill() | |
{ | |
cur = max; | |
} | |
public void refill(double per) | |
{ | |
cur = cur += max/per/100; | |
if(cur>max)cur=max; | |
} | |
public void empty() | |
{ | |
cur = 0; | |
} | |
public void drop(double per) | |
{ | |
cur = cur -= cur/per/100; | |
if(cur<0)cur=0; | |
} | |
public boolean isFull() | |
{ | |
if(cur==max)return true; | |
return false; | |
} | |
public boolean isEmpty() | |
{ | |
if(cur==0)return true; | |
return false; | |
} | |
public boolean isHalf() | |
{ | |
double range = .1; | |
if(cur<max/2+range&&cur>max/2-range) | |
{ | |
return true; | |
} | |
return false; | |
} | |
public boolean inRange(double range, double middle) | |
{ | |
if(cur>middle-range&&cur<middle+range) | |
{ | |
return true; | |
} | |
return false; | |
} | |
public int getCur(){return (int)cur;} | |
public int getMax(){return (int)max;} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment