質問編集履歴
2
誤字の訂正
test
CHANGED
File without changes
|
test
CHANGED
@@ -438,7 +438,7 @@
|
|
438
438
|
|
439
439
|
|
440
440
|
|
441
|
-
追記致しました。このようなjsのファイルがありました。とりあえずPHPに
|
441
|
+
追記致しました。このようなjsのファイルがありました。とりあえずPHPに値
|
442
442
|
|
443
443
|
持って来られてるかの確認でPHPファイルでechoを出してみたところNotice: Undefined index: win_count in~
|
444
444
|
|
1
追記
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Ajax
|
1
|
+
Ajaxでjsからphpに値をPOSTしたい
|
test
CHANGED
@@ -10,7 +10,387 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
|
13
|
-
```
|
13
|
+
``` JS
|
14
|
+
|
15
|
+
let stepY_count = 0;
|
16
|
+
|
17
|
+
let stepX_count = 0;
|
18
|
+
|
19
|
+
let step_count = 0;
|
20
|
+
|
21
|
+
let meet_count = 0;
|
22
|
+
|
23
|
+
let sum_count = 0;
|
24
|
+
|
25
|
+
let win_count = 0;
|
26
|
+
|
27
|
+
let appear_count = 0;
|
28
|
+
|
29
|
+
let revel_count = 1;
|
30
|
+
|
31
|
+
let stage;
|
32
|
+
|
33
|
+
let kazan = -1;
|
34
|
+
|
35
|
+
let mori = 2;
|
36
|
+
|
37
|
+
let heichi = 1;
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
class Enemy {
|
42
|
+
|
43
|
+
constructor (name) {
|
44
|
+
|
45
|
+
this.name = name;
|
46
|
+
|
47
|
+
}
|
48
|
+
|
49
|
+
ene1() {
|
50
|
+
|
51
|
+
this.rand1 = 1 + Math.floor(Math.random()*100);
|
52
|
+
|
53
|
+
}
|
54
|
+
|
55
|
+
appear() {
|
56
|
+
|
57
|
+
$("#result_area").append('<div>「' + enemy1.name + 'が現れた!」</div>');
|
58
|
+
|
59
|
+
}
|
60
|
+
|
61
|
+
}
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
const enemy1 = new Enemy('デーモン');
|
66
|
+
|
67
|
+
enemy1.ene1();
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
class Yusha extends Enemy {
|
72
|
+
|
73
|
+
status1() {
|
74
|
+
|
75
|
+
this.number1 = 70;
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
status2() {
|
80
|
+
|
81
|
+
this.number2 = 50;
|
82
|
+
|
83
|
+
}
|
84
|
+
|
85
|
+
win() {
|
86
|
+
|
87
|
+
$("#result_area").append('<div>「勝った」</div>');
|
88
|
+
|
89
|
+
}
|
90
|
+
|
91
|
+
lose() {
|
92
|
+
|
93
|
+
$("#result_area").append('<div>「負けた」</div>');
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
defeat() {
|
98
|
+
|
99
|
+
$("#defeat_count").html("倒した敵の数:" + win_count);
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
process1() {
|
104
|
+
|
105
|
+
$("#before,#left,#back,#right").prop("disabled",false);
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
process2() {
|
110
|
+
|
111
|
+
$("#fight,#escape").prop("disabled",true);
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
const yusha = new Yusha('勇者');
|
120
|
+
|
121
|
+
yusha.status1();
|
122
|
+
|
123
|
+
yusha.status2();
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
$("#fight,#escape").prop("disabled",true);
|
128
|
+
|
129
|
+
$(function(){
|
130
|
+
|
131
|
+
$('#before,#back,#left,#right').off('click');
|
132
|
+
|
133
|
+
$("#before,#back,#left,#right").on( 'click',() => {
|
134
|
+
|
135
|
+
//スタートが押されたら初期化
|
136
|
+
|
137
|
+
$("#start").on('click',() => {
|
138
|
+
|
139
|
+
$("#result_area,#log_date").empty();
|
140
|
+
|
141
|
+
$("#revel").html("LV:0");
|
142
|
+
|
143
|
+
$("#stepY").html("歩数Y:0");
|
144
|
+
|
145
|
+
$("#stepX").html("歩数X:0");
|
146
|
+
|
147
|
+
$("#defeat_count").html("倒した敵の数:0");
|
148
|
+
|
149
|
+
$("#appear_average").html("敵出現平均歩数:0");
|
150
|
+
|
151
|
+
stepY_count = 0;
|
152
|
+
|
153
|
+
stepX_count = 0;
|
154
|
+
|
155
|
+
step_count = 0;
|
156
|
+
|
157
|
+
meet_count = 0;
|
158
|
+
|
159
|
+
sum_count = 0;
|
160
|
+
|
161
|
+
win_count = 0;
|
162
|
+
|
163
|
+
appear_count = 0;
|
164
|
+
|
165
|
+
revel_count = 1;
|
166
|
+
|
167
|
+
$("#image").attr("src","images/heichi.jpeg");
|
168
|
+
|
169
|
+
yusha.process1();
|
170
|
+
|
171
|
+
yusha.process2();
|
172
|
+
|
173
|
+
});
|
174
|
+
|
175
|
+
//ダンジョン切り替え
|
176
|
+
|
177
|
+
step_count++;
|
178
|
+
|
179
|
+
if ((step_count % 6 === 0) || (step_count % 7 === 0)|| (step_count % 8 === 0)|| (step_count % 9 === 0)){
|
180
|
+
|
181
|
+
$("#image").attr("src","images/mori.jpeg");
|
182
|
+
|
183
|
+
stage = mori;
|
184
|
+
|
185
|
+
}
|
186
|
+
|
187
|
+
else if ((step_count % 10 === 0) || (step_count % 11 === 0) || (step_count % 12 === 0)){
|
188
|
+
|
189
|
+
$("#image").attr("src","images/kazan.jpeg");
|
190
|
+
|
191
|
+
stage = kazan;
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
else {
|
196
|
+
|
197
|
+
$("#image").attr("src","images/heichi.jpeg");
|
198
|
+
|
199
|
+
stage = heichi;
|
200
|
+
|
201
|
+
}
|
202
|
+
|
203
|
+
//乱数生成
|
204
|
+
|
205
|
+
let randnum =1 + Math.floor(Math.random()*3 + stage);
|
206
|
+
|
207
|
+
meet_count++;
|
208
|
+
|
209
|
+
sum_count++;
|
210
|
+
|
211
|
+
//乱数と歩数が同じなら戦闘開始
|
212
|
+
|
213
|
+
if (randnum === meet_count){
|
214
|
+
|
215
|
+
$("#fight,#escape").prop("disabled",false);
|
216
|
+
|
217
|
+
$("#before,#left,#back,#right").prop("disabled",true);
|
218
|
+
|
219
|
+
appear_count++;
|
220
|
+
|
221
|
+
$("#log_date").append("<div>" + sum_count + "歩目</div>");
|
222
|
+
|
223
|
+
enemy1.appear()
|
224
|
+
|
225
|
+
$("#image").attr("src","images/enemy.jpeg");
|
226
|
+
|
227
|
+
let average = sum_count / appear_count;
|
228
|
+
|
229
|
+
let rounding_average = average.toFixed(0);
|
230
|
+
|
231
|
+
$("#appear_average").html("敵出現平均歩数:" + rounding_average);
|
232
|
+
|
233
|
+
//戦うボタンが押されたら
|
234
|
+
|
235
|
+
$("#fight").off('click');
|
236
|
+
|
237
|
+
$("#fight").on('click',() => {
|
238
|
+
|
239
|
+
enemy1.ene1();
|
240
|
+
|
241
|
+
let win_or_lose = enemy1.rand1;
|
242
|
+
|
243
|
+
if (win_or_lose <= ( yusha.number1 + revel_count)){
|
244
|
+
|
245
|
+
yusha.win();
|
246
|
+
|
247
|
+
$("#image").attr("src","images/win.jpeg");
|
248
|
+
|
249
|
+
yusha.process1();
|
250
|
+
|
251
|
+
yusha.process2();
|
252
|
+
|
253
|
+
win_count++;
|
254
|
+
|
255
|
+
yusha.defeat();
|
256
|
+
|
257
|
+
if (win_count % 10 === 0){
|
258
|
+
|
259
|
+
revel_count++;
|
260
|
+
|
261
|
+
$("#revel").html("LV:" + revel_count);
|
262
|
+
|
263
|
+
}
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
if (win_or_lose >= ( yusha.number1 + revel_count + 1)){
|
268
|
+
|
269
|
+
yusha.lose();
|
270
|
+
|
271
|
+
$("#image").attr("src","images/lose.jpeg");
|
272
|
+
|
273
|
+
yusha.process1();
|
274
|
+
|
275
|
+
yusha.process2();
|
276
|
+
|
277
|
+
}
|
278
|
+
|
279
|
+
});
|
280
|
+
|
281
|
+
//逃げるボタンが押されたら
|
282
|
+
|
283
|
+
$("#escape").off('click');
|
284
|
+
|
285
|
+
$("#escape").on('click',() => {
|
286
|
+
|
287
|
+
enemy1.ene1();
|
288
|
+
|
289
|
+
let escape_result = enemy1.rand1;;
|
290
|
+
|
291
|
+
if (escape_result <= 0){
|
292
|
+
|
293
|
+
$("#result_area").append('<div>「逃げられた」</div>');
|
294
|
+
|
295
|
+
yusha.process1();
|
296
|
+
|
297
|
+
yusha.process2();
|
298
|
+
|
299
|
+
}
|
300
|
+
|
301
|
+
if (escape_result >= 1){
|
302
|
+
|
303
|
+
$("#result_area").append('<div>「逃げられない」</div>');
|
304
|
+
|
305
|
+
enemy1.ene1();
|
306
|
+
|
307
|
+
let end_result = enemy1.rand1;;
|
308
|
+
|
309
|
+
if (end_result <= ( yusha.number2 - revel_count)){
|
310
|
+
|
311
|
+
yusha.lose();
|
312
|
+
|
313
|
+
$("#result_area").append('<div>「' + yusha.name + 'は死んでしまった」</div>');
|
314
|
+
|
315
|
+
$("#image").attr("src","images/lose.jpeg");
|
316
|
+
|
317
|
+
yusha.process1();
|
318
|
+
|
319
|
+
yusha.process2();
|
320
|
+
|
321
|
+
}
|
322
|
+
|
323
|
+
if (end_result >= ( yusha.number2 - revel_count - 1)){
|
324
|
+
|
325
|
+
$("#image").attr("src","images/win.jpeg");
|
326
|
+
|
327
|
+
yusha.win();
|
328
|
+
|
329
|
+
$("#result_area").append('<div>「歩く方向を押してください」」</div>');
|
330
|
+
|
331
|
+
yusha.process1();
|
332
|
+
|
333
|
+
yusha.process2();
|
334
|
+
|
335
|
+
win_count++;
|
336
|
+
|
337
|
+
yusha.defeat();
|
338
|
+
|
339
|
+
if (win_count % 10 === 0){
|
340
|
+
|
341
|
+
revel_count++;
|
342
|
+
|
343
|
+
$("#revel").html("LV:" + revel_count);
|
344
|
+
|
345
|
+
}
|
346
|
+
|
347
|
+
}
|
348
|
+
|
349
|
+
}
|
350
|
+
|
351
|
+
});
|
352
|
+
|
353
|
+
}
|
354
|
+
|
355
|
+
//歩数が乱数を超えたら
|
356
|
+
|
357
|
+
if (randnum < meet_count){
|
358
|
+
|
359
|
+
meet_count = 0;
|
360
|
+
|
361
|
+
}
|
362
|
+
|
363
|
+
});
|
364
|
+
|
365
|
+
});
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
//歩数Y,Xをカウント、出力
|
370
|
+
|
371
|
+
$(function(){
|
372
|
+
|
373
|
+
$("#before,#back").on( 'click',() => {
|
374
|
+
|
375
|
+
stepY_count++;
|
376
|
+
|
377
|
+
$("#stepY").html("歩数Y:" + stepY_count);
|
378
|
+
|
379
|
+
});
|
380
|
+
|
381
|
+
$("#left,#right").on( 'click',() => {
|
382
|
+
|
383
|
+
stepX_count++;
|
384
|
+
|
385
|
+
$("#stepX").html("歩数X:" + stepX_count);
|
386
|
+
|
387
|
+
});
|
388
|
+
|
389
|
+
});
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
|
14
394
|
|
15
395
|
//非同期通信
|
16
396
|
|
@@ -18,6 +398,8 @@
|
|
18
398
|
|
19
399
|
$("#ranking").on("click",function(){
|
20
400
|
|
401
|
+
alert("a");
|
402
|
+
|
21
403
|
$.ajax({
|
22
404
|
|
23
405
|
type: "POST",
|
@@ -32,6 +414,8 @@
|
|
32
414
|
|
33
415
|
});
|
34
416
|
|
417
|
+
|
418
|
+
|
35
419
|
```
|
36
420
|
|
37
421
|
|
@@ -50,6 +434,14 @@
|
|
50
434
|
|
51
435
|
?>
|
52
436
|
|
53
|
-
|
54
|
-
|
55
437
|
```
|
438
|
+
|
439
|
+
|
440
|
+
|
441
|
+
追記致しました。このようなjsのファイルがありました。とりあえずPHPにataiga
|
442
|
+
|
443
|
+
持って来られてるかの確認でPHPファイルでechoを出してみたところNotice: Undefined index: win_count in~
|
444
|
+
|
445
|
+
Notice: Undefined index: step_count in ~
|
446
|
+
|
447
|
+
というエラーが出ています。
|