-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.js
131 lines (120 loc) · 3.91 KB
/
game.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//All things related to cash should be in this class
function Game() {
this.totalLand = 1000;
this.cash = 100; //Actual default: 100
this.oxygen = 0;
this.science = 0; //Actual default: 0
this.wood = 0;
this.metal = 0;
this.power = 0;
this.tick = function() {
this.ice.tick();
this.robots.tick();
this.computer.tick();
this.farms.tick(this.land.transferWater());
this.population.tick();
this.water.outdoor += this.farms.transferWater();
this.trees.tick(this.land.transferWater());
this.water.outdoor += this.trees.transferWater();
this.land.tick(this.clouds.transferWater());
this.clouds.tick(this.water.transferWater());
this.energy.tick();
this.water.tick(this.ice.transferWater());
this.tractorBeam.tick();
this.spaceStation.tick();
this.space.tick();
this.oxygenLeak = this.oxygen / 100000;
this.oxygen -= this.oxygenLeak;
this.hangar.tick();
};
this.initialize = function() {
this.space = new Space();
this.ice = new Ice();
this.water = new Water();
this.clouds = new Clouds();
this.land = new Land(this.totalLand);
this.trees = new Trees();
this.farms = new Farms();
this.population = new City();
this.computer = new Computer();
this.robots = new Robots();
this.energy = new Energy();
this.spaceStation = new SpaceStation();
this.tractorBeam = new TractorBeam();
this.spaceDock = new SpaceDock();
this.hangar = new Hangar();
for(var i = 0; i < this.computer.processes.length; i++) {
view.addComputerRow(i);
this.computer.processes[i].isMoving = 0;
this.computer.processes[i].completions = 0;
}
for(i = 0; i < this.robots.jobs.length; i++) {
view.addRobotRow(i);
this.robots.jobs[i].completions = 0;
}
};
this.buyIce = function() {
var toBuy = this.cash;
if(toBuy <= 0) {
return;
}
this.cash -= this.ice.buyIce(toBuy);
};
this.buyFarms = function() {
var toBuy = Number(document.getElementById('buyFarmAmount').value);
if(toBuy * 50 > this.land.soil) {
toBuy = Math.floor(this.land.soil/50);
}
if(toBuy <= 0) {
return;
}
this.land.soil -= toBuy * 50;
this.farms.addFarm(toBuy);
view.update();
};
this.buyBattery = function() {
var toBuy = Number(document.getElementById('buyBattery').value);
if(toBuy * 3e4 > this.oxygen) {
toBuy = Math.floor(this.oxygen/3e4);
}
if(toBuy * 2e4 > this.science) {
toBuy = Math.floor(this.science/2e4);
}
if(toBuy <= 0) {
return;
}
this.oxygen -= toBuy * 3e4;
this.science -= toBuy * 2e4;
this.energy.buyBattery(toBuy);
view.update();
};
this.buyBattleship = function() {
var toBuy = Number(document.getElementById('buyBattleshipAmount').value);
if(toBuy * 3e7 > this.oxygen) {
toBuy = Math.floor(this.oxygen / 3e7);
}
if(toBuy * 1.5e7 > this.science) {
toBuy = Math.floor(this.science / 1.5e7);
}
if(toBuy <= 0) {
return;
}
this.oxygen -= 3e7*toBuy;
this.science -= 1.5e7*toBuy;
this.spaceDock.addBattleship(toBuy);
view.update();
};
this.buyHangar = function() {
const cost=1000000;
var toBuy = Number(document.getElementById('buyHangarAmount').value);
if(toBuy * cost > this.land.soil) {
toBuy = Math.floor(this.land.soil/cost);
}
if(toBuy <= 0) {
return;
}
this.land.soil -= toBuy * cost;
this.hangar.sendRate+=toBuy;
view.update();
};
}