forked from vexpaer/incremental_game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
432 lines (388 loc) · 18.9 KB
/
index.html
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>增量游戏</title>
<script>
//定义变量--------------------------------------------------
var resource_type_number = 3;//资源类型数量
var machine_type_number = 2;//机器level数量
var machine_study_type_number = 2;//科技机器level数量
var machine_power_type_number = 2;//能源机器level数量
var power=0;//能量数量
var knowledge=0;//知识数量
var resource_number = Array(resource_type_number).fill(0);//资源数量
var resource_name = Array(resource_type_number).fill("");//资源名称
var unlock_type_number = 7;//可解锁数量
var unlock;//解锁表
var unlock_switch = Array(unlock_type_number).fill(0);//是否解锁
unlock_switch[0] = 1;//解锁第一个解锁
var machine;//资源机器
var machine_number = Array(resource_type_number);//资源机器数量
for(var i=0;i<resource_type_number;i++)
{machine_number[i] = Array(machine_type_number).fill(0);}
var machine_switch = Array(resource_type_number);//资源机器开关
for(var i=0;i<resource_type_number;i++)
{machine_switch[i] = Array(machine_type_number).fill(1);}
var machine_study;//科技机器
var machine_study_number = Array(machine_type_number).fill(0);//科技机器数量
var machine_power;//能源机器
var machine_power_number = Array(machine_type_number).fill(0);//能源机器数量
var machine_power_switch = Array(machine_type_number).fill(1);//能源机器开关
//ui切换函数-----------------------------------------------
function ui(x)//ui函数,用于切换ui
{
for(var i=1;i<=2;i++)
{
document.getElementById("ui"+i).style.display="none";
}
document.getElementById("ui"+x).style.display="block";
}
//计算机器价格函数------------------------------------------
function machine_cost(x,level,k)
{
var tmp = 0;
tmp=parseInt(machine[x][level].build_cost[k]*Math.pow(machine[x][level].build_cost_boost,machine_number[x][level]));
return tmp;
}
//计算能源机器价格函数---------------------------------------
function machine_power_cost(x,k)
{
var tmp = 0;
tmp=parseInt(machine_power[x].build_cost[k]*Math.pow(machine_power[x].build_cost_boost,machine_power_number[x]));
return tmp;
}
//计算科技机器价格函数---------------------------------------
function machine_study_cost(x,k)
{
var tmp = 0;
tmp=parseInt(machine_study[x].build_cost[k]*Math.pow(machine_study[x].build_cost_boost,machine_study_number[x]));
return tmp;
}
//初始化函数------------------------------------------------
window.onload = function()
{
ui(1);//默认显示资源页面
fetch('http://127.0.0.1:3000/get-json-resource')//拉取resource json
.then(response => response.json())
.then(data => {
for(var i=0;i<resource_type_number;i++)
resource_name[i] = data[i].name;
for(var i=0;i<resource_type_number;i++)//更新资源名称
document.getElementById("resource_"+i).innerHTML = resource_name[i];
})
.catch(error => alert(error));
fetch('http://127.0.0.1:3000/get-json-machine')//拉取machine json
.then(response => response.json())
.then(data => {
machine=data;
for(var i=0;i<resource_type_number;i++)//更新机器名称,描述,购买价格
for(var j=0;j<machine_type_number;j++)
{
document.getElementById("machine_name_"+i+"."+j).innerHTML = machine[i][j].name;
document.getElementById("machine_describe_"+i+"."+j).innerHTML = machine[i][j].describe;
var tmp=machine[i][j].name;
for(var k=0;k<resource_type_number;k++)
{
if(machine[i][j].build_cost[k]!=0)
tmp+=" "+resource_name[k]+"x"+machine[i][j].build_cost[k];
}
document.getElementById("machine_buy_"+i+"."+j).innerHTML = tmp;
}
})
.catch(error => alert('Error fetching data: '+error));
fetch('http://127.0.0.1:3000/get-json-machine-study')//拉取machine_study json
.then(response => response.json())
.then(data => {
machine_study=data;
for(var i=0;i<machine_type_number;i++)//更新科技机器名称,描述,购买价格
{
document.getElementById("machine_study_name_"+i).innerHTML = machine_study[i].name;
document.getElementById("machine_study_describe_"+i).innerHTML = machine_study[i].describe;
var tmp=machine_study[i].name;
for(var k=0;k<resource_type_number;k++)
{
if(machine_study[i].build_cost[k]!=0)
tmp+=" "+resource_name[k]+"x"+machine_study[i].build_cost[k];
}
document.getElementById("machine_study_buy_"+i).innerHTML = tmp;
}
})
.catch(error => alert('Error fetching data: '+error));
fetch('http://127.0.0.1:3000/get-json-machine-power')//拉取machine_power json
.then(response => response.json())
.then(data => {
machine_power=data;
for(var i=0;i<machine_type_number;i++)//更新科技机器名称,描述,购买价格
{
document.getElementById("machine_power_name_"+i).innerHTML = machine_power[i].name;
document.getElementById("machine_power_describe_"+i).innerHTML = machine_power[i].describe;
var tmp=machine_power[i].name;
for(var k=0;k<resource_type_number;k++)
{
if(machine_power[i].build_cost[k]!=0)
tmp+=" "+resource_name[k]+"x"+machine_power[i].build_cost[k];
}
document.getElementById("machine_power_buy_"+i).innerHTML = tmp;
}
})
.catch(error => alert('Error fetching data: '+error));
// fetch('http://127.0.0.1:3000/get-json-unlock')//拉取machine_power_switch json
}
//update函数,每秒更新----------------------------------------
setInterval(update, 1000);
function update()
{
//增加知识点
var knowledge_velocity=0;
for(var i=0;i<machine_study_type_number;i++)
{
knowledge_velocity+=machine_study_number[i]*machine_study[i].production;
}
knowledge+=knowledge_velocity;
var word_for_knowledge="知识点数 ";
word_for_knowledge+=knowledge+" +"+knowledge_velocity+"/s";
document.getElementById("knowledge_number").innerHTML = word_for_knowledge;
//检测能源机器有无资源
var power_velocity=0;
for(var i=0;i<machine_power_type_number;i++)
{
for(var j=0;j<resource_type_number;j++)
{
if(machine_power_number[i]>0)
{
if(machine_power_number[i]*machine_power[i].material_cost[j]*machine_power_switch[i]>resource_number[j])
{//如果资源不足就关机
machine_power_switch[i]=0;
document.getElementById("machine_power_switch_"+i).innerHTML = "关";
}
}
}
//计算能力速度
power_velocity+=machine_power_number[i]*machine_power[i].production*machine_power_switch[i];
}
power+=power_velocity;
var word_for_power="能源 ";
word_for_power+=power+" +"+power_velocity+"/s";
document.getElementById("power_number").innerHTML = word_for_power;
//检测机器有无足够资源/电力生产
for(var i=0;i<resource_type_number;i++)
{
for(var j=0;j<machine_type_number;j++)
{
if(machine_number[i][j]>0)
{
if(machine_number[i][j]*machine[i][j].power_cost*machine_switch[i][j]>power)
{//如果电力不足就关机
machine_switch[i][j]=0;
document.getElementById("machine_switch_"+i+"."+j).innerHTML = "关";
}
power-=machine_number[i][j]*machine[i][j].power_cost*machine_switch[i][j];
for(var k=0;k<resource_type_number;k++)
{
if(machine_number[i][j]*machine[i][j].material_cost[k]*machine_switch[i][j]>resource_number[k])
{//如果资源不足就关机
machine_switch[i][j]=0;
document.getElementById("machine_switch_"+i+"."+j).innerHTML = "关";
}
resource_number[k]-=machine_number[i][j]*machine[i][j].material_cost[k]*machine_switch[i][j];
}
}
}
}
//计算资源生产速度
for(var i=0;i<resource_type_number;i++)
{
var velocity = 0;
for(var j=0;j<machine_power_type_number;j++)//计算能源机器消耗速度
{
velocity-=machine_power_number[j]*machine_power[j].material_cost[i]*machine_power_switch[j];
}
for(var j=0;j<machine_type_number;j++)//计算资源机器产速
{
velocity+=machine_number[i][j]*machine[i][j].production*machine_switch[i][j];
}
resource_number[i]+=velocity;
document.getElementById("resource_"+i+"_number").innerHTML = resource_number[i];
document.getElementById("resource_"+i).innerHTML = resource_name[i]+" +"+velocity+"/s";
}
}
//资源获取---------------------------------------------------
function get_resource(x)//获取资源
{
resource_number[x]+=1;
document.getElementById("resource_"+x+"_number").innerHTML = resource_number[x];
}
//购买资源机器------------------------------------------------
function get_machine(x,level)//获取机器
{
//检测能不能买得起
var flag=1;
for(var i=0;i<resource_type_number;i++)
if(resource_number[i]<machine_cost(x,level,i))
flag=0;
if(flag==1)//如果买得起
{
for(var i=0;i<resource_type_number;i++)
resource_number[i]-=machine_cost(x,level,i);
for(var i=0;i<resource_type_number;i++)
document.getElementById("resource_"+i+"_number").innerHTML = resource_number[i];
machine_number[x][level]+=1;
document.getElementById("machine_number_"+x+"."+level).innerHTML = machine_number[x][level];
//更新价格
var tmp=machine[x][level].name;
for(var k=0;k<resource_type_number;k++)
{
if(machine[x][level].build_cost[k]!=0)
tmp+=" "+resource_name[k]+"x"+machine_cost(x,level,k);
}
document.getElementById("machine_buy_"+x+"."+level).innerHTML = tmp;
}
if(flag==0) alert("资源不足");
}
//购买能源机器------------------------------------------------
function get_machine_power(x)//获取能源机器
{
//检测能不能买得起
var flag=1;
for(var i=0;i<resource_type_number;i++)
if(resource_number[i]<machine_power_cost(x,i))
flag=0;
if(flag==1)//如果买得起
{
for(var i=0;i<resource_type_number;i++)
resource_number[i]-=machine_power_cost(x,i);
for(var i=0;i<resource_type_number;i++)
document.getElementById("resource_"+i+"_number").innerHTML = resource_number[i];
machine_power_number[x]+=1;
document.getElementById("machine_power_number_"+x).innerHTML = machine_power_number[x];
//更新价格
var tmp=machine_power[x].name;
for(var k=0;k<resource_type_number;k++)
{
if(machine_power_cost(x,k)!=0)
tmp+=" "+resource_name[k]+"x"+machine_power_cost(x,k);
}
document.getElementById("machine_power_buy_"+x).innerHTML = tmp;
}
if(flag==0) alert("资源不足");
}
//购买科技机器------------------------------------------------
function get_machine_study(x)//获取科技机器
{
//检测能不能买得起
var flag=1;
for(var i=0;i<resource_type_number;i++)
if(resource_number[i]<machine_study_cost(x,i))
flag=0;
if(flag==1)//如果买得起
{
for(var i=0;i<resource_type_number;i++)
resource_number[i]-=machine_study_cost(x,i);
for(var i=0;i<resource_type_number;i++)
document.getElementById("resource_"+i+"_number").innerHTML = resource_number[i];
machine_study_number[x]+=1;//更新数量
document.getElementById("machine_study_number_"+x).innerHTML = machine_study_number[x];
//更新价格
var tmp=machine_study[x].name;
for(var k=0;k<resource_type_number;k++)
{
if(machine_study_cost(x,k)!=0)
tmp+=" "+resource_name[k]+"x"+machine_study_cost(x,k);
}
document.getElementById("machine_study_buy_"+x).innerHTML = tmp;
}
if(flag==0) alert("资源不足");
}
//花费知识点进行解锁-------------------------------------------
function get_unlock(x)//获取解锁
{
}
</script>
</head>
<body>
<button onclick="ui(1)">资源</button><button onclick="ui(2)">研究</button>
<div id="ui1">资源
<div class="power_0" id="power">能源
<div class="power_0" id="power_number">0</div>
<hr>
<div class="power_0" id="machine_power_name_0">能源机器0</div>
<button class="power_0" id="machine_power_buy_0" onclick="get_machine_power(0)">能源机器0</button>
<div class="power_0" id="machine_power_describe_0">能源机器描述</div>
<div class="power_0" id="machine_power_switch_0">开</div>
<div class="power_0" id="machine_power_number_0">0</div>
<hr>
<div class="power_1" id="machine_power_name_1">能源机器1</div>
<button class="power_1" id="machine_power_buy_1" onclick="get_machine_power(1)">能源机器1</button>
<div class="power_1" id="machine_power_describe_1">能源机器描述</div>
<div class="power_1" id="machine_power_switch_1">开</div>
<div class="power_1" id="machine_power_number_1">0</div>
</div>
<hr>
<div id="resource_0">资源0</div>
<div id="resource_0_number">0</div>
<button onclick="get_resource(0)">获取</button>
<hr>
<div class="level_0" id="machine_name_0.0">机器0.0</div>
<button class="level_0" id="machine_buy_0.0" onclick="get_machine(0,0)">机器0.0</button>
<div class="level_0" id="machine_describe_0.0">机器0.0描述</div>
<div class="level_0" id="machine_switch_0.0">开</div>
<div class="level_0" id="machine_number_0.0">0</div>
<hr>
<div class="level_1" id="machine_name_0.1">机器0.1</div>
<button class="level_1" id="machine_buy_0.1" onclick="get_machine(0,1)">机器0.1</button>
<div class="level_1" id="machine_describe_0.1">机器0.1描述</div>
<div class="level_1" id="machine_switch_0.1">开</div>
<div class="level_1" id="machine_number_0.1">0</div>
<hr>
<div id="resource_1">资源1</div>
<div id="resource_1_number">0</div>
<button onclick="get_resource(1)">获取</button>
<hr>
<div class="level_0" id="machine_name_1.0">机器1.0</div>
<button class="level_0" id="machine_buy_1.0" onclick="get_machine(1,0)">机器1.0</button>
<div class="level_0" id="machine_describe_1.0">机器1.0描述</div>
<div class="level_0" id="machine_switch_1.0">开</div>
<div class="level_0" id="machine_number_1.0">0</div>
<hr>
<div class="level_1" id="machine_name_1.1">机器1.1</div>
<button class="level_1" id="machine_buy_1.1" onclick="get_machine(1,1)">机器1.1</button>
<div class="level_1" id="machine_describe_1.1">机器1.1描述</div>
<div class="level_1" id="machine_switch_1.1">开</div>
<div class="level_1" id="machine_number_1.1">0</div>
<hr>
<div id="resource_2">资源2</div>
<div id="resource_2_number">0</div>
<button onclick="get_resource(2)">获取</button>
<hr>
<div class="level_0" id="machine_name_2.0">机器2.0</div>
<button class="level_0" id="machine_buy_2.0" onclick="get_machine(2,0)">机器2.0</button>
<div class="level_0" id="machine_describe_2.0">机器2.0描述</div>
<div class="level_0" id="machine_switch_2.0">开</div>
<div class="level_0" id="machine_number_2.0">0</div>
<hr>
<div class="level_1" id="machine_name_2.1">机器2.1</div>
<button class="level_1" id="machine_buy_2.1" onclick="get_machine(2,1)">机器2.1</button>
<div class="level_1" id="machine_describe_2.1">机器2.1描述</div>
<div class="level_1" id="machine_switch_2.1">开</div>
<div class="level_1" id="machine_number_2.1">0</div>
</div>
<div id="ui2">研究
<hr>
<div>科学生产</div>
<div id="knowledge_number">知识点数 0</div>
<hr>
<div class="study_0" id="machine_study_name_0">知识机器0</div>
<button class="study_0" id="machine_study_buy_0" onclick="get_machine_study(0)">知识机器购买</button>
<div class="study_0" id="machine_study_describe_0">知识机器描述</div>
<div class="study_0" id="machine_study_number_0">0</div>
<hr>
<div class="study_1" id="machine_study_name_1">知识机器1</div>
<button class="study_1" id="machine_study_buy_1" onclick="get_machine_study(0)">知识机器购买</button>
<div class="study_1" id="machine_study_describe_1">知识机器描述</div>
<div class="study_1" id="machine_study_number_1">0</div>
<hr>
<div>科技</div>
</div>
</body>
</html>