Virtual Life App with Carnivore

Feature Specification

 

 

 

Code Design

 

 

 

 

Use an itemOptions object that will have a key for the world item type.  See below for an example.

 

 

Do not use hard-coded symbols in the app, only use the symbol from the itemOptions object!

 

 

 

function WorldItemFactory(itemOptions) {

   

    this.itemOptions = itemOptions;

 

    // create symbol table for reverse lookups

    this.symbolTable = {};

 

    for (let type in itemOptions) {

        let symbol = this.itemOptions[type].symbol;

        this.symbolTable[symbol] = type;

    }

 

}

 

WorldItemFactory.prototype.buildFromSymbol = function(symbol,latitude,longitude) {

   

    let type = this.symbolTable[symbol];

    return this.build(type,latitude,longitude);

 

}

 

WorldItemFactory.prototype.build = function(type,latitude,longitude) {

 

    <snip… your implementation goes here>

 

}

 

 

 

app.load = function() {

 

       const ROWS = 40;

       const COLS = 60;

 

       var itemOptions = {

              wall: { symbol: "#", buildChance: 10 },

 

              <snip… what else goes here?>

 

       };

 

       var worldPlan = buildWorldPlan(ROWS, COLS, itemOptions);

       var worldItemFactory = new WorldItemFactory(itemOptions);

       var world = new World(worldPlan, worldItemFactory);

 

       animateWorld(world)

}