-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
50 lines (47 loc) · 2.15 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { directions, directionNames, plan } from './Constants';
import Vector from './components/Vector';
import Grid from './components/Grid';
import BouncingCritter from './components/BouncingCritter';
import Plant from './components/Plant';
import PlantEater from './components/PlantEater';
import Tiger from './components/Tiger';
import SmartPlantEater from './components/SmartPlantEater';
import Wall from './components/Wall';
import World from './components/World';
import LifelikeWorld from './components/LifelikeWorld';
import WallFollower from './components/WallFollower';
const world = new World(plan, {"#": Wall, "o": BouncingCritter, "~": WallFollower});
const valley = new LifelikeWorld(
["####################################################",
"# #### **** ###",
"# * @ ## ######## OO ##",
"# * ## O O **** *#",
"# ##* ########## *#",
"# ##*** * **** **#",
"#* ** # * *** ######### **#",
"#* ** # * # * **#",
"# ## # O # *** ######",
"#* @ # # * O # #",
"#* # ###### ** #",
"### **** *** ** #",
"# O @ O #",
"# * ## ## ## ## ### * #",
"# ** # * ##### O #",
"## ** O O # # *** *** ### ** #",
"### # ***** ****#",
"####################################################"],
{"#": Wall,
"@": Tiger,
"O": SmartPlantEater, // from previous exercise
"*": Plant}
);
const worldElement = document.querySelector('#world');
function updateWorldElement(w) {
worldElement.innerHTML = w.toString();
}
document.addEventListener('DOMContentLoaded', () => {
window.setInterval(() => {
valley.turn();
updateWorldElement(valley);
}, 300);
});