I've written a very small class [that have to grow!] but I suddenly see something "strange".
This is the class:
class Chara{
private boolean flag_loaded;
private boolean flag_rage, flag_shield;
private int int_rage, int_shield;
Chara(String fileName){
flag_loaded = true
if(flag_loaded){
flag_rage = false;
int_rage = 0;
flag_shield = false;
int_shield = 0;
}
}
boolean rage(){return flag_rage;}
boolean shield(){return flag_shield;}
void add_rage(int toAdd){flag_rage = Bool(int_rage += limitMin(toAdd, 0));}
void add_shield(int toAdd){flag_shield = Bool(int_shield += limitMin(toAdd, 0));}
void sub_rage(int toAdd){flag_rage = Bool(int_rage -= limitMin(toAdd, 0));}
void sub_shield(int toAdd){flag_shield = Bool(int_shield -= limitMin(toAdd, 0));}
As you can see all the variables are set as private
.
NOTE: limitMin()
return the same type variable, in this case 0
if toAdd
is lower. Bool() is simply a cast.
This is a piece of main:
Chara chara = new Chara("lol");
print(chara.int_shield, (chara.shield()) ? COL_GREEN : COL_RED);
print(chara.flag_shield, (chara.shield()) ? COL_GREEN : COL_RED);
Nothing is done between declaration, instance and printing.
This piece of code is supposed to print in green the value of the shield and if there is or not the shield but it should not print anything because of int_shield
and flag_shield
that are supposed to be private
.
The result is a nice 0
and a nice false
in red...
Why is this happening? I am doing something wrong?
In despair I tried making the variables protected
but as I expected nothing happened.
EDIT: added entire Chara class.