-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCopse.js
More file actions
393 lines (353 loc) · 11.7 KB
/
Copy pathCopse.js
File metadata and controls
393 lines (353 loc) · 11.7 KB
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
"use strict";
var Copse={};
(function () {
Copse.vars={}; // 储存变量
Copse.vars.attrs=[]; // 当前的所有属性
Copse.vars.buffs=[]; // 当前的所有状态
Copse.vars.length=0; // 已经完全走过的距离 重生的时候会重生到这里
Copse.vars.length_temp=0; // 当前的行进距离
Copse.vars.keys={}; // 关键事件变量
Copse.guis={}; // gui相关的东西
Copse.funs={}; // 功能
Copse.funs.addAttr=function(attrIn,valueIn) // 增加某一项属性
{
;
}
Copse.funs.reduceAttr=function(attrIn,valueIn) // 减少某一项属性
{
;
}
Copse.funs.addBuff=function(buffIn) // buff 相关操作
{
;
}
Copse.funs.removeBuff=function(buffIn)
{
;
}
Copse.funs.setLength=function(lIn) // 永久距离
{
Copse.vars.length=lIn;
}
Copse.funs.getLength=function()
{
return Copse.vars.length;
}
Copse.funs.setTempLength=function(lIn)
{
Copse.vars.length_temp=lIn;
}
Copse.funs.getTempLength=function()
{
return Copse.vars.length_temp;
}
Copse.funs.__attr_setAttributes=function(attrNodeIn,idIn,posIn)
{
attrNodeIn.setAttribute("style","margin:12px;display:inline;"+
"width:64px;max-width:64px;height:64px;max-height:64px;border:1px solid black;background-color:blue;");
attrNodeIn.setAttribute("class","gui_attr_node");
attrNodeIn.setAttribute("id",idIn);
attrNodeIn.innerText="attr node "+idIn;
}
Copse.funs.__infobox_moveup=function()
{
document.getElementById("gui_info_box").style["bottom"]="0px";
}
Copse.funs.__infobox_movedown=function()
{
document.getElementById("gui_info_box").style["bottom"]="-50px";
}
Copse.funs.__infobox_clicked=function()
{
document.getElementById("gui_info_box").style["display"]="none";
}
Copse.funs._initGUI=function() // 初始化界面
{
let body=document.getElementsByTagName("body")[0];
// 基础背景
let base=document.createElement("div");
base.setAttribute("style","position:fixed;top:0px;left:0px;"+
"width:100%;height:100%;background-color:yellow;"+
"font-family:楷体;font-size:32px;text-align:center;"+
"min-width:720px;min-height:600px;");
base.setAttribute("id","gui_base");
base.innerText="COPSE_GUI_BASE";
body.appendChild(base);
// 属性条目
let attr_money=document.createElement("div");
Copse.funs.__attr_setAttributes(attr_money,"gui_attr_node_money",0);
let attr_suply=document.createElement("div");
Copse.funs.__attr_setAttributes(attr_suply,"gui_attr_node_suply",1);
let attr_power=document.createElement("div");
Copse.funs.__attr_setAttributes(attr_power,"gui_attr_node_power",2);
// 属性栏
let attrs=document.createElement("div");
attrs.setAttribute("id","gui_buffs");
attrs.setAttribute("style","position:fixed;top:5%;left:10%;width:80%;height:72px;"+
"border:1px solid black;text-align:center;overflow:hidden");
attrs.innerText="attrs box";
attrs.appendChild(attr_money);
attrs.appendChild(attr_suply);
attrs.appendChild(attr_power);
base.appendChild(attrs);
// 状态栏
let buffs=document.createElement("div");
buffs.setAttribute("id","gui_buffs");
buffs.setAttribute("style","position:fixed;top:20%;left:15%;width:70%;height:64px;"+
"border:1px solid black;");
base.appendChild(buffs);
// 卡片
let card_box=document.createElement("div");
card_box.setAttribute("id","gui_card_box");
card_box.setAttribute("style","position:fixed;top:40%;"+
"width:100%;height:256px;border:1px solid black;"+
"vertical-align:center;text-align:center;background-color:white;");
base.appendChild(card_box);
let card=document.createElement("div");
card.setAttribute("id","gui_card");
card.setAttribute("style","width:256px;height:256px;border:1px solid black;"+
"background-color:green;margin:0 auto");
card_box.appendChild(card);
let card_caption=document.createElement("div");
card_caption.setAttribute("id","gui_card_caption");
card_caption.setAttribute("style","width:100%;height:64px;border:1px solid black");
card_caption.innerText="card caption";
card.appendChild(card_caption);
let card_content=document.createElement("div");
card_content.setAttribute("id","gui_card_content");
card_content.setAttribute("style","width:100%;height:128px;");
card_content.innerText="Card Content";
card.appendChild(card_content);
let card_ch1=document.createElement("div");
let card_ch2=document.createElement("div");
card_ch1.setAttribute("id","gui_card_ch1");
card_ch2.setAttribute("id","gui_card_ch2");
card_ch1.setAttribute("onclick","gui_ch1_clicked()");
card_ch2.setAttribute("onclick","gui_ch2_clicked()");
card_ch1.setAttribute("style","height:64px;width:100px;border:1px solid black;float:left;");
card_ch2.setAttribute("style","height:64px;width:100px;border:1px solid black;float:right;");
card_ch1.innerText="ch1";
card_ch2.innerText="ch2";
card.appendChild(card_ch1);
card.appendChild(card_ch2);
let info_box=document.createElement("div");
info_box.setAttribute("id","gui_info_box");
info_box.setAttribute("style","position:fixed;bottom:-50px;left:0px;height:100px;width:100%;background-color:green;");
info_box.setAttribute("onmouseover","Copse.funs.__infobox_moveup()");
info_box.setAttribute("onmouseout","Copse.funs.__infobox_movedown()");
info_box.setAttribute("onclick","Copse.funs.__infobox_clicked()");
info_box.innerText="INFO BOX";
base.appendChild(info_box);
// 注册组件
Copse.guis.base=base;
Copse.guis.attrs=attrs;
Copse.guis.attr_money=attr_money;
Copse.guis.attr_suply=attr_suply;
Copse.guis.attr_power=attr_power;
Copse.guis.buffs=buffs;
Copse.guis.card_caption=card_caption;
Copse.guis.card_content=card_content;
Copse.guis.card_ch1=card_ch1;
Copse.guis.card_ch2=card_ch2;
Copse.guis.info_box=info_box;
}
Copse.funs._initGame=function() // 初始化游戏
{
console.log("游戏初始化...\n"+Copse.infos.name+" "+Copse.infos.version);
// 加载所有基础信息
Copse.funs._initCards();console.log("卡片数据加载完成");
// 读取存档
Copse.funs._readSave();
console.log("存档加载完成");
// 加载GUI
Copse.funs._initGUI();
console.log("界面加载完成");
}
Copse.funs._writeSave=function() // 保存存档
{
localStorage.setItem("save",JSON.stringify(Copse.vars));
}
Copse.funs._readSave=function() // 从存档初始化
{
let save_get=localStorage.getItem("save");
if(save_get!=null) // 读取到存档了
{
Copse.vars=JSON.parse(save_get);
}
}
Copse.funs._clearSave=function() // 清空存档
{
localStorage.clear();
}
Copse.funs.registerCard=function(nameIn,cardIn)
{
Copse.consts.cards["C_"+nameIn]=cardIn;
}
Copse.funs.getCard=function(nameIn)
{
let ret=Copse.consts.cards["C_"+nameIn];
if(ret===undefined)
return Copse.funs.getCard("ERROR");
else
return ret;
}
Copse.funs._initCards=function() // 所有的卡片数据在这里
{
let ERROR=new Copse.classes.classCard();
ERROR.setCaption("错误卡片").setBGC("#300000")
.setContent("错误的卡片!");
let NULL=new Copse.classes.classCard();
NULL.setCaption("空卡").setBGC("gray")
.setContent("空卡片 没有任何作用");
let WIN=new Copse.classes.classCard();
WIN.setCaption("胜利").setBGC("green")
.setContent("你获胜了");
Copse.funs.registerCard("ERROR",ERROR);
Copse.funs.registerCard("NULL",NULL);
Copse.funs.registerCard("WIN",WIN);
}
Copse.funs.gui_showCard=function(cardIn,ifEvtIn)
{
Copse.guis.card_caption.innerText=cardIn.getCaption();
Copse.guis.card_content.innerText=cardIn.getContent();
Copse.guis.card_ch1.innerText=cardIn.getCh1();
Copse.guis.card_ch2.innerText=cardIn.getCh2();
if(ifEvtIn)
cardIn.getEvt() ();
}
Copse.consts={};
Copse.consts.max_length=0; // 最大距离
Copse.consts.places={};
Copse.consts.cards={};
Copse.classes={};
Copse.classes.classCard=function()
{
let card=this;
let caption="Card Caption";
let content="Card Content";
let bgc="white";
let c="black";
this.setCaption=function(captionIn)
{
caption=captionIn;
return card;
}
this.getCaption=function()
{
return caption;
}
this.setContent=function(contentIn)
{
content=contentIn;
return card;
}
this.getContent=function()
{
return content;
}
this.setBGC=function(cIn)
{
bgc=cIn;
return card;
}
this.getBGC=function(cIn)
{
return bgc;
}
this.setC=function(cIn)
{
this.c=cIn;
return card;
}
this.getC=function()
{
return c;
}
let evt=function(){}; // 当出现这张卡时一定会执行的东西
this.setEvt=function(evtIn)
{
evt=evtIn;
return card;
}
this.getEvt=function()
{
return evt;
}
let ch1="choice 1";
let ch2="choice 2";
let ch1_next="NULL";
let ch2_next="NULL";
this.setCh1=function(chIn)
{
ch1=chIn;
return card;
}
this.getCh1=function()
{
return ch1;
}
this.setCh2=function(chIn)
{
ch2=chIn;
return card;
}
this.getCh2=function()
{
return ch2;
}
}
Copse.classes.classEvt=function()
{
let name="Event";
let cards=[]; // 事件包含的卡片s
}
Copse.classes.classPlace=function()
{
let name="Place";
let locMax=100;
let locMin=0;
this.setName=function(nameIn)
{
name=nameIn;
}
this.getName=function()
{
return name;
}
this.setLocMax=function(locIn)
{
locMax=locIn;
}
this.getLocMax=function()
{
return locMax;
}
this.setLocMin=function(locIn)
{
locMin=locIn;
}
this.getLocMin=function()
{
return locMin;
}
let evtsOnEnter=[]; // 进入场景
let evtsOnLeave=[]; // 离开场景
let evtsOnDay=[]; // 白天
let evtsOnNight=[]; // 夜间
let evtsOnTime=[]; // 时间流逝
this.registerEvt=function(tagIn,evtIn)
{
return;
}
this.getEvts=function(tagIn)
{
return null;
}
}
Copse.infos={}; // 储存信息
Copse.infos.name="Copse";
Copse.infos.author="Firok";
Copse.infos.version="0.5.0";
Copse.infos.link="github.com/S2Lab/Copse";
Copse.funs._initGame(); // 初始化游戏
})();