-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
89 lines (82 loc) · 2.47 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
var app = angular.module('app', ['ngRoute']);
app.service('CellService', function(){
this.plan =
["############################",
"#.....................######",
"#....***................**##",
"#...*##**.........**..c..*##",
"#....***.....c....##**....*#",
"#.......c.........##***...*#",
"#.................##**....*#",
"#...c.......#*............*#",
"#*..........#**.......c...*#",
"#***....##**....c........**#",
"#*****.....###***.......*###",
"############################"];
this.terranium = new LifeLikeTerrarium(this.plan);
this.arr = []
for (var i=0; i<this.plan.length; i++){
var row = [];
for (var j=0; j<this.plan[i].length; j++){
row.push(this.plan[i][j]);
}
this.arr.push(row);
}
});
app.controller('HomeController', function($scope, $http, $interval, CellService){
$scope.CellService = CellService
$scope.startSim = function(){
Terrarium.prototype.start = function() {
console.log('start function being run')
if (!this.running)
this.running = $interval(bind(function(){
this.step();
var gridString = this.toString()
var grid = gridString.split('\n');
CellService.plan = grid;
grid.pop();
CellService.arr = []
for (var i=0; i<grid.length; i++){
var row = [];
for (var j=0; j<grid[i].length; j++){
row.push(grid[i][j]);
}
CellService.arr.push(row);
}
}
, this), 1000);
};
CellService.terranium.start()
}
$scope.stopSim = function(){
Terrarium.prototype.stop = function() {
if (this.running) {
$interval.cancel(this.running);
this.running = null;
}
};
CellService.terranium.stop();
}
$scope.changeMap = function(x,y,newValue){
this.stopSim();
this.CellService.arr[x][y] = newValue;
var arr = [];
for (var i=0; i<CellService.arr.length; i++){
var string = ''
for (var j=0; j<CellService.arr[0].length; j++){
string += CellService.arr[i][j];
}
arr.push(string);
}
this.CellService.plan = arr;
this.CellService.terranium = new LifeLikeTerrarium(this.CellService.plan);
}
})
app.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
templateUrl: 'home.html',
controller: 'HomeController'
});
$locationProvider.html5Mode(true);
}]);