📄 citizen.java
字号:
package GameOfLife;
class Citizen
{ int homeCol, homeRow;
int vision; //Defines Vision Limit in cells in all directions
int metabolism; //Defines Amount of Sugar required to survive each round
int sugar; //Defines Amount of Sugar currently left with citizen
public void Citizen()
{ //homeCol = 0;
//homeRow = 0;
vision = 0;
metabolism = 0;
sugar = 0;
}
public int getVision() { return vision; }
public int getMetabolism() { return metabolism; }
public int getSugar() { return sugar; }
//public int getCol() { return homeCol; }
//public int getRow(int row) { return homeRow; }
//public int setCol() { return homeCol; }
//public int setRow() { return homeRow; }
public int setVision(int visionVal)
{ if (visionVal >= 0 )
{ this.vision = visionVal; }
else //visionVal = -1 then assign random value to vision
{ this.vision = ((int)(Math.random() * GoLconst.VISION_MAX));
if(this.vision == 0)
this.vision = 1; //no blind citizen
}
return vision;
}
public int setMetabolism(int metabolismVal)
{ if (metabolismVal >= 0 )
{ this.metabolism = metabolismVal; }
else //metabolismVal = -1 then assign random value to metabolism
{ this.metabolism = ((int)(Math.random() * GoLconst.METABOLISM_MAX));
if(this.metabolism == 0)
this.metabolism = 1; //a citizen's gotta eat something
}
return metabolism;
}
public int setSugar(int sugarVal)
{ if (sugarVal >= 0 )
{ this.sugar = sugarVal; }
else //sugarVal = -1 then assign random value to sugar
{ this.sugar = ((int)(Math.random() * GoLconst.SUGAR_MAX_CITIZEN)); }
return sugar;
}
public boolean eatSugar()
{ //If enough sugar available then consume & return true
if(this.sugar >= this.metabolism)
{ this.sugar -= this.metabolism;
return true;
}
else return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -