mild code refactoring

This commit is contained in:
MaxRobinsonTheGreat
2020-07-29 15:15:21 -06:00
parent b4b44b2c4f
commit 92d679ca18
6 changed files with 155 additions and 129 deletions

View File

@@ -1,7 +1,7 @@
const CellTypes = require("./CellTypes");
const Hyperparams = require("../../Hyperparameters");
// A cell exists in a grid system.
// A cell exists in a grid map.
class Cell{
constructor(type, col, row, x, y){
this.owner = null;
@@ -10,24 +10,29 @@ class Cell{
this.row = row;
this.x = x;
this.y = y;
this.func = null;
}
setType(type) {
this.type = type;
switch(this.type){
case CellTypes.mouth:
this.func = eatFood;
break;
case CellTypes.producer:
this.func = growFood;
break;
case CellTypes.killer:
this.func = killNeighbors;
break;
default:
this.func = null;
}
}
performFunction(env) {
switch(this.type){
case CellTypes.mouth:
eatFood(this, env);
break;
case CellTypes.producer:
growFood(this, env);
break;
case CellTypes.killer:
killNeighbors(this, env);
break;
}
if (this.func == null) return;
this.func(this, env);
}
getColor() {