Skip to content

Instantly share code, notes, and snippets.

@jake7864
Created August 22, 2012 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jake7864/3424486 to your computer and use it in GitHub Desktop.
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
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