このファイル: /home/web6047/www/cgi-bin/prj/20200515-RPG/基本的/20200620-ウィンドウ入力/20200814-パレット2/simple5 - snapshot 20200816.html
1
<html>
2
<head>
3
<meta content="text/html; charset=UTF-8" http-equiv="content-type">
4
<script>console.clear();</script>
5
<script>
6
function onloadx() {
7
app = new App();
8
9
}
10
class App {
11
constructor() {
12
this.chars = new Array();
13
14
15
this.scripts = {
16
"どうぐでかいふく" : function( m ) {
17
18
let char1 = m[ "だれの?" ].si;
19
let char2 = m[ "だれに?" ].si;
20
let propName = m[ "キャンプ" ].si.title;
21
let idx = m[ "どれ?" ].sn;
22
23
24
let dougu = char1[ propName ][ idx ];
25
26
if( char1 == char2 )
27
console.log( char1.title + "は" + dougu.title + "を使った!" );
28
else
29
console.log( char1.title + "は" + char2.title + "に" + dougu.title + "を使った!" );
30
31
char2.hp += dougu.add;
32
console.log( char2.title + "のHPが" + dougu.add + "ポイントかいふくした!" );
33
console.log( char2.title + "のHP : " + char2.hp );
34
35
36
char1[ propName ].splice( idx, 1 );
37
},
38
}
39
40
41
this.dougus = {
42
"なんこう" : {
43
title : "なんこう",
44
add : 30,
45
"キャンプ時メニュー" : {
46
type : "MS",
47
title : "どうする?",
48
items : [
49
{
50
type : "item_suru",
51
title : "つかう",
52
subMenus : [
53
{
54
type : "MS",
55
title : "だれに?",
56
items : this.chars,
57
},
58
],
59
script : this.scripts[ "どうぐでかいふく" ],
60
61
},
62
{
63
title : "わたす",
64
},
65
{
66
title : "すてる",
67
},
68
],
69
},
70
},
71
"とくべつなひやく" : {
72
title : "とくべつなひやく",
73
},
74
"どうぐ3" : {
75
title : "どうぐ3",
76
},
77
}
78
79
80
let char;
81
char = {
82
title : "c1",
83
hp : 100,
84
"どうぐ" : [
85
this.dougus[ "なんこう" ],
86
this.dougus[ "とくべつなひやく" ],
87
this.dougus[ "どうぐ3" ],
88
],
89
}
90
this.chars.push( char );
91
char = {
92
title : "c2",
93
hp : 100,
94
"どうぐ" : [
95
this.dougus[ "なんこう" ],
96
this.dougus[ "どうぐ3" ],
97
this.dougus[ "どうぐ3" ],
98
],
99
}
100
this.chars.push( char );
101
char = {
102
title : "c3",
103
hp : 100,
104
"どうぐ" : [
105
this.dougus[ "とくべつなひやく" ],
106
this.dougus[ "とくべつなひやく" ],
107
this.dougus[ "どうぐ3" ],
108
],
109
}
110
this.chars.push( char );
111
112
113
this.camp = {
114
type : "MS",
115
title : "キャンプ",
116
items : [
117
{
118
type : "item",
119
title : "どうぐ",
120
subMenus : [
121
{
122
type : "MS",
123
title : "だれの?",
124
items : this.chars,
125
},
126
{
127
type : "MS",
128
title : "どれ?",
129
}
130
],
131
},
132
{
133
title : "しらべる",
134
},
135
],
136
}
137
138
139
this.test();
140
}
141
142
143
144
async test() {
145
let context = "キャンプ";
146
147
while( 1 ) {
148
let menus = [ this.camp ];
149
let menusrc;
150
let i = 0;
151
let script;
152
while( menusrc = menus[ i ] ) {
153
154
155
if( menusrc.title == "どれ?" ) {
156
157
let char = menus[ i - 1 ].result.si;
158
let propName = menus[ i - 2 ].result.si.title;
159
menusrc.items = char[ propName ];
160
}
161
162
163
let menu = new Menu( menusrc );
164
let num = await menu.doit();
165
166
167
menus[ i ] = menu;
168
let selectedItem = menu.result.si;
169
170
171
if( selectedItem.type && selectedItem.type == "item_suru" ) {
172
script = selectedItem.script.bind( this );
173
}
174
175
176
177
if( selectedItem.subMenus ) {
178
menus.push( ...selectedItem.subMenus );
179
}
180
181
if( selectedItem[ context + "時メニュー" ] ) {
182
menus.push( selectedItem[ context + "時メニュー" ] );
183
}
184
185
i++;
186
}
187
188
189
if( ! script ) {
190
console.log( "error: undefined script." );
191
continue;
192
}
193
194
195
196
197
let m = new Object();
198
for( let i = 0; i < menus.length; i++ ) {
199
let menu = menus[ i ];
200
console.log( "\t", i, menu.ms.title, menu.result.si.title );
201
m[ menu.ms.title ] = menu.result;
202
}
203
script( m );
204
}
205
}
206
}
207
208
class Menu {
209
constructor( menusrc ) {
210
this.ms = menusrc;
211
}
212
doit() {
213
return new Promise(
214
function( tellOk ) {
215
console.log( "[" + this.ms.title + "]" );
216
for( let i = 0; i < this.ms.items.length; i++ ) {
217
let item = this.ms.items[ i ];
218
console.log( i, ":", item.title );
219
}
220
window.onkeydown = function( e ) {
221
let num = e.which - 48;
222
if( num < 0 || num > this.ms.items.length - 1 ) return;
223
this.result = {
224
si : this.ms.items[ num ],
225
sn : num,
226
};
227
tellOk();
228
}.bind( this );
229
}.bind( this )
230
);
231
}
232
}
233
234
235
</script>
236
<style>
237
</style>
238
</head>
239
<body onload="onloadx()"
240
onclick="location.reload()"
241
style = "
242
width : 90%;
243
height : 90%;
244
">
245
246
</body>
247
</html>