質問編集履歴

10

追記 2018/03/13

2018/03/13 10:32

投稿

nosonosolife
nosonosolife

スコア42

test CHANGED
File without changes
test CHANGED
@@ -555,3 +555,75 @@
555
555
  ```
556
556
 
557
557
  これでも揃ってしまうことがあります。
558
+
559
+ 【追記 2018/03/13】
560
+
561
+ 以下のように変更してみたのですが、
562
+
563
+ ```javascript
564
+
565
+ var slipPosY = [0, 0, 0];
566
+
567
+ function slotStop(i) {
568
+
569
+ //省略
570
+
571
+ slipPosY[i] = 0;
572
+
573
+ //省略
574
+
575
+ }
576
+
577
+ function slotMove() {
578
+
579
+ //省略
580
+
581
+ for (var i = 0, stopCount = 0; i < reelNum; i++) {
582
+
583
+ if (!reelStopFlg[i] || reelposY[i] % iconHeight){
584
+
585
+ //省略
586
+
587
+ } else {
588
+
589
+ if(winFlg && winIconArray[i][(reelposY[i] / iconHeight)+stopLineArray[stopLineId][i]] != 1 ||
590
+
591
+ stopCount == reelNum-1 && !winFlg && !adjust) {
592
+
593
+ if(slipPosY[i] < (iconHeight*3)){
594
+
595
+ adjust = slotAdjust();
596
+
597
+ slipPosY[i] += iconHeight;
598
+
599
+ reelposY[i] += reelMoveSpeedY;
600
+
601
+ if (reelposY[i] > 0) reelposY[i] -= reelHeight;
602
+
603
+ $('.wrapper').eq(i).css("top", reelposY[i] + "px");
604
+
605
+ }else{
606
+
607
+ stopCount++;
608
+
609
+ }
610
+
611
+ }else{
612
+
613
+ stopCount++;
614
+
615
+ }
616
+
617
+ }
618
+
619
+ //省略
620
+
621
+ }
622
+
623
+ }
624
+
625
+
626
+
627
+ ```
628
+
629
+ これでもダメでした。

9

追記 2018/03/12

2018/03/13 10:32

投稿

nosonosolife
nosonosolife

スコア42

test CHANGED
File without changes
test CHANGED
@@ -465,3 +465,93 @@
465
465
  ```
466
466
 
467
467
  時々止まってしまったり、ボタンを押したときにリールが止まらないことがあります。
468
+
469
+ 【追記 2018/03/12】
470
+
471
+ 以下のような関数を作って、
472
+
473
+ ```javascript
474
+
475
+
476
+
477
+ function slotAdjust(reelId) {
478
+
479
+ var hitIcon = [[0, 0, 0],[0, 0, 0],[0, 0, 0]];
480
+
481
+ for (var i = 0; i < reelNum; i++) {
482
+
483
+ for (var j = 0; j < reelNum; j++) {
484
+
485
+ hitIcon[i][j] = ((-reelposY[i] / iconHeight) + j);
486
+
487
+ if (hitIcon[i][j] >= iconNum) {
488
+
489
+ hitIcon[i][j] -= iconNum;
490
+
491
+ }
492
+
493
+ }
494
+
495
+ }
496
+
497
+
498
+
499
+ for (var c = 0; c < stopLineNum; c++) {
500
+
501
+ if (iconArray[0][hitIcon[0][stopLineArray[c][0]]] == iconArray[1][hitIcon[1][stopLineArray[c][1]]] &&
502
+
503
+ iconArray[1][hitIcon[1][stopLineArray[c][1]]] == iconArray[2][hitIcon[2][stopLineArray[c][2]]]) {
504
+
505
+ return false;
506
+
507
+ }else{
508
+
509
+ return true;
510
+
511
+ }
512
+
513
+ }
514
+
515
+ }
516
+
517
+ ```
518
+
519
+ slotMove関数を以下のように変更してみたのですが、
520
+
521
+ ```javascript
522
+
523
+ //リール回転
524
+
525
+ function slotMove() {
526
+
527
+ //省略
528
+
529
+ var adjust = slotAdjust();
530
+
531
+ //省略
532
+
533
+ if (stopCount == reelNum) {
534
+
535
+ if(adjust){
536
+
537
+ $('#startbtn').css("pointer-events", "auto");
538
+
539
+ clearInterval(reelmoveAnime);
540
+
541
+ slotHits();
542
+
543
+ }else{
544
+
545
+ reelposY[i] += reelMoveSpeedY;
546
+
547
+ if (reelposY[i] > 0) reelposY[i] -= reelHeight;
548
+
549
+ $('.wrapper').eq(i).css("top", reelposY[i] + "px");
550
+
551
+ }
552
+
553
+ }
554
+
555
+ ```
556
+
557
+ これでも揃ってしまうことがあります。

8

2018/03/12 02:38

投稿

nosonosolife
nosonosolife

スコア42

test CHANGED
File without changes
test CHANGED
@@ -446,7 +446,7 @@
446
446
 
447
447
  for (var i = 0; i < iconNum; i++) {
448
448
 
449
- while (iconArray[0][stopLineArray[stopLineId][i]] != iconArray[1][stopLineArray[stopLineId][i]] &&
449
+ if (iconArray[0][stopLineArray[stopLineId][i]] != iconArray[1][stopLineArray[stopLineId][i]] &&
450
450
 
451
451
  iconArray[1][stopLineArray[stopLineId][i]] != iconArray[2][stopLineArray[stopLineId][i]]) {
452
452
 

7

追記 2018/03/10

2018/03/10 12:03

投稿

nosonosolife
nosonosolife

スコア42

test CHANGED
File without changes
test CHANGED
@@ -16,672 +16,452 @@
16
16
 
17
17
  【ソースコード】
18
18
 
19
- ```css
20
-
21
- #slotmachinebox {
22
-
23
- display: block;
24
-
25
- width: 460px;
26
-
27
- height: 390px;
28
-
29
- margin:0px auto;
30
-
31
- padding: 0;
32
-
33
- background-image: url(img/slotmainbg.png);
19
+ ```JavaScript
20
+
21
+ // 定数定義
22
+
23
+ var fps = 60; //FPS
24
+
25
+ var interval = 1 / fps * 1000;
26
+
27
+
28
+
29
+ var maxRand = 65536; //最大乱数
30
+
31
+ //11070
32
+
33
+ var configNum = 6; //設定数
34
+
35
+ var configTable = [
36
+
37
+ // 0:BIG 1:REG 2:コイン 3:スイカ 4:ベル 5:チェリー 6:リプレイ
38
+
39
+ [[0,99],[100,149],[150,299],[300,549],[550,869],[870,2539],[2540,4500]], //設定1
40
+
41
+ [[0,99],[100,149],[150,299],[300,549],[550,869],[870,2539],[2540,4500]], //設定2
42
+
43
+ [[0,99],[100,149],[150,299],[300,549],[550,869],[870,2539],[2540,4500]], //設定3
44
+
45
+ [[0,99],[100,149],[150,299],[300,549],[550,869],[870,2539],[2540,4500]], //設定4
46
+
47
+ [[0,99],[100,149],[150,299],[300,549],[550,869],[870,2539],[2540,4500]], //設定5
48
+
49
+ [[0,99],[100,149],[150,299],[300,549],[550,869],[870,2539],[2540,4500]] //設定6
50
+
51
+ ];
52
+
53
+
54
+
55
+ var iconNum = 21; //リールに表示する絵柄絵柄数
56
+
57
+ var iconWidth = 120; //絵柄の幅
58
+
59
+ var iconHeight = 60; //絵柄の高さ
60
+
61
+
62
+
63
+ var reelArray = new Array();
64
+
65
+ var reelNum = 3; //リール数
66
+
67
+ var reelMargin = 5;
68
+
69
+ var reelBaseX = 18;
70
+
71
+ var reelBaseY = 92;
72
+
73
+ var reelHeight = (iconHeight * iconNum); //リールの高さ
74
+
75
+ var reelMoveSpeedY = Math.floor(iconHeight / 3); //リール移動スピード
76
+
77
+
78
+
79
+ var iconArray = [//絵柄配列
80
+
81
+ [4, 5, 1, 3, 4, 6, 1, 3, 2, 6, 4, 3, 5, 6, 2, 5, 6, 4, 3, 0, 6],
82
+
83
+ [6, 4, 1, 3, 6, 5, 4, 5, 6, 4, 2, 3, 6, 0, 4, 3, 6, 1, 4, 2, 5],
84
+
85
+ [5, 3, 1, 4, 6, 3, 4, 0, 6, 3, 5, 6, 2, 3, 4, 6, 5, 0, 3, 4, 6]
86
+
87
+ ];
88
+
89
+ var stopLineArray = [[1,1,1],[0,0,0],[2,2,2],[0,1,2],[2,1,0]]; //停止ライン配列
90
+
91
+ var stopLineId = 0;
92
+
93
+
94
+
95
+ //変数定義
96
+
97
+ var configId = Math.floor(Math.random()*configNum); //設定を決める
98
+
99
+
100
+
101
+ var reelStopFlg = [null, null, null];
102
+
103
+ var reelposY = [0, 0, 0]; //リールの移動量
104
+
105
+
106
+
107
+ var winIconArray = [ //当たり絵柄配列
108
+
109
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
110
+
111
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
112
+
113
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
114
+
115
+ ];
116
+
117
+ var hitIcon = [
118
+
119
+ [0, 0, 0],
120
+
121
+ [0, 0, 0],
122
+
123
+ [0, 0, 0]
124
+
125
+ ];
126
+
127
+
128
+
129
+ // リール回転用
130
+
131
+ var reelmoveAnime;
132
+
133
+
134
+
135
+ addSlots();
136
+
137
+
138
+
139
+ function slotStart() {
140
+
141
+ reelStopFlg = [false, false, false];
142
+
143
+ winLottery();
144
+
145
+ reelmoveAnime = setInterval(slotMove, interval);
146
+
147
+ $('[id^=stopbtn]').css("pointer-events", "auto");
148
+
149
+ }
150
+
151
+
152
+
153
+ function slotStop(i) {
154
+
155
+ reelStopFlg[i] = true;
156
+
157
+ }
158
+
159
+
160
+
161
+ function winLottery() {
162
+
163
+ var iArray = [0,0,0];
164
+
165
+ var rand = Math.floor(Math.random()*maxRand);
166
+
167
+ for (var i = 0; i < configTable[configId].length; i++) {
168
+
169
+ if(configTable[configId][i][0] >= rand || rand <= configTable[configId][i][1]){
170
+
171
+ console.log("あたり");
172
+
173
+ iArray = [i,i,i];
174
+
175
+ wIcArrayRewrite(iArray);
176
+
177
+ break;
178
+
179
+ }
180
+
181
+ if(i == configTable[configId].length-1){
182
+
183
+ console.log("はずれ");
184
+
185
+ iArray[0] = Math.floor(Math.random()*configTable[configId].length);
186
+
187
+ iArray[1] = Math.floor(Math.random()*configTable[configId].length);
188
+
189
+ iArray[2] = Math.floor(Math.random()*configTable[configId].length);
190
+
191
+ wIcArrayRewrite(iArray);
192
+
193
+ }
194
+
195
+ }
196
+
197
+ }
198
+
199
+
200
+
201
+ function wIcArrayRewrite(iArray) {
202
+
203
+ for (var i = 0; i < reelNum; i++) {
204
+
205
+ for (var j = 0; j < iconNum; j++) {
206
+
207
+ if(iconArray[i][j] == iArray[i]){
208
+
209
+ winIconArray[i][j] = 1;
210
+
211
+ }else{
212
+
213
+ winIconArray[i][j] = 0;
214
+
215
+ }
216
+
217
+ }
218
+
219
+ }
220
+
221
+ }
222
+
223
+
224
+
225
+ //リール作成
226
+
227
+ function addSlots() {
228
+
229
+ reelStopFlg[i] = false;
230
+
231
+ for (var i = 0; i < reelNum; i++) {
232
+
233
+ $('.reel').eq(i).css("left", ((iconWidth + reelMargin) * i) + "px");
234
+
235
+ $('.wrapper').eq(i).css("height", reelHeight + "px");
236
+
237
+ $('.wrapper').eq(i).css("top", "-" + (iconHeight * Math.floor(Math.random()*iconNum)) + "px");
238
+
239
+ for (var j = 0; j < 24; j++) {
240
+
241
+ if (j < iconNum) {
242
+
243
+ $('.wrapper').eq(i).append("<li class='icon icon" + iconArray[i][j] +
244
+
245
+ "'>" + iconArray[i][j] + "</li>");
246
+
247
+ } else {
248
+
249
+ $('.wrapper').eq(i).append("<li class='icon icon" + iconArray[i][j - 21] +
250
+
251
+ "'>" + iconArray[i][j - 21] + "</li>");
252
+
253
+ }
254
+
255
+ }
256
+
257
+ }
258
+
259
+ }
260
+
261
+
262
+
263
+ //リール回転
264
+
265
+ function slotMove() {
266
+
267
+ for (var i = 0, stopCount = 0; i < reelNum; i++) {
268
+
269
+ if (!reelStopFlg[i] || reelposY[i] % iconHeight || winIconArray[i][(-reelposY[i] / iconHeight)+stopLineArray[stopLineId][i]] != 1) {
270
+
271
+ reelposY[i] += reelMoveSpeedY;
272
+
273
+ if (reelposY[i] > 0) reelposY[i] -= reelHeight;
274
+
275
+ $('.wrapper').eq(i).css("top", reelposY[i] + "px");
276
+
277
+ } else {
278
+
279
+ stopCount++;
280
+
281
+ }
282
+
283
+ if (stopCount == reelNum) {
284
+
285
+ $('#startbtn').css("pointer-events", "auto");
286
+
287
+ clearInterval(reelmoveAnime);
288
+
289
+ slotHits();
290
+
291
+ }
292
+
293
+ }
294
+
295
+ }
296
+
297
+
298
+
299
+ function slotHits() {
300
+
301
+ for (var i = 0; i < reelNum; i++) {
302
+
303
+ for (var j = 0; j < reelNum; j++) {
304
+
305
+ hitIcon[i][j] = ((-reelposY[i] / iconHeight) + j);
306
+
307
+ if (hitIcon[i][j] >= iconNum) {
308
+
309
+ hitIcon[i][j] -= iconNum;
310
+
311
+ }
312
+
313
+ }
314
+
315
+ }
316
+
317
+ if (iconArray[0][hitIcon[0][0]] == iconArray[1][hitIcon[1][0]] &&
318
+
319
+ iconArray[1][hitIcon[1][0]] == iconArray[2][hitIcon[2][0]]) {
320
+
321
+ $("#result").html("上段が揃いました");
322
+
323
+ } else if (iconArray[0][hitIcon[0][1]] == iconArray[1][hitIcon[1][1]] &&
324
+
325
+ iconArray[1][hitIcon[1][1]] == iconArray[2][hitIcon[2][1]]) {
326
+
327
+ $("#result").html("中段が揃いました");
328
+
329
+ } else if (iconArray[0][hitIcon[0][2]] == iconArray[1][hitIcon[1][2]] &&
330
+
331
+ iconArray[1][hitIcon[1][2]] == iconArray[2][hitIcon[2][2]]) {
332
+
333
+ $("#result").html("下段が揃いました");
334
+
335
+ } else if (iconArray[0][hitIcon[0][2]] == iconArray[1][hitIcon[1][1]] &&
336
+
337
+ iconArray[1][hitIcon[1][1]] == iconArray[2][hitIcon[2][0]]) {
338
+
339
+ $("#result").html("左斜めが揃いました");
340
+
341
+ } else if (iconArray[0][hitIcon[0][0]] == iconArray[1][hitIcon[1][1]] &&
342
+
343
+ iconArray[1][hitIcon[1][1]] == iconArray[2][hitIcon[2][2]]) {
344
+
345
+ $("#result").html("右斜めが揃いました");
346
+
347
+ } else {
348
+
349
+ $("#result").html("残念!!");
350
+
351
+ }
352
+
353
+ }
354
+
355
+
356
+
357
+ ```
358
+
359
+
360
+
361
+ もしお時間があればこちらの質問にも回答していただければ幸いです。
362
+
363
+ [https://teratail.com/questions/114846](https://teratail.com/questions/114846)
364
+
365
+
366
+
367
+ 【追記】
368
+
369
+ ご回答された方申し訳ありません。もう少し詳細な説明をするべきでした。
370
+
371
+
372
+
373
+ このスロットは、縦3つ・左右斜め3つのラインに絵柄を揃えるルールですので、画面上はこのようになっています。
374
+
375
+ [2][4][6]
376
+
377
+ [5][8][3]
378
+
379
+ [9][7][1]
380
+
381
+ ハズレの際の絵柄を決める部分はこうなっています。
382
+
383
+ ```javascript
384
+
385
+ iArray[0] = Math.floor(Math.random()*configTable[configId].length);
386
+
387
+ iArray[1] = Math.floor(Math.random()*configTable[configId].length);
388
+
389
+ iArray[2] = Math.floor(Math.random()*configTable[configId].length);
390
+
391
+ ```
392
+
393
+ その結果出力された乱数は例えば
394
+
395
+ iArray[1,3,5]
396
+
397
+ だとすると、中央のラインは揃いませんが、画面では
398
+
399
+ [2][2][2]
400
+
401
+ [1][3][5]
402
+
403
+ [4][8][7]
404
+
405
+ と、上ラインに2の絵柄が揃ってしまいます。
406
+
407
+ ※これは例ですので、実際のリールの配列とは違います
408
+
409
+
410
+
411
+ 乱数は中央ラインにしか対応しておらず、上下ライン・左右斜めラインが予期しない形で揃ってしまうことがあるので、それを解消したいというわけです。
412
+
413
+
414
+
415
+ 中央ラインだけ揃わないようにする方法は簡単ですが、これはリール配列の参照を行わないと実現できないと思うのですが、そのロジックが思いつきません。
416
+
417
+
418
+
419
+ 実際のコードは記載していただかなくても構いませんので、考え方のヒントやアドバイスなどを
420
+
421
+ よろしくお願い致します。
422
+
423
+ 【追記 2018/03/10】
424
+
425
+ この部分を
426
+
427
+ ```javascript
428
+
429
+ iArray[0] = Math.floor(Math.random()*configTable[configId].length);
430
+
431
+ iArray[1] = Math.floor(Math.random()*configTable[configId].length);
432
+
433
+ iArray[2] = Math.floor(Math.random()*configTable[configId].length);
434
+
435
+ ```
436
+
437
+ こうしてみたのですが、
438
+
439
+ ```JavaScript
440
+
441
+ var stopLineArray = [[1,1,1],[0,0,0],[2,2,2],[0,1,2],[2,1,0]]; //停止ライン配列
442
+
443
+
444
+
445
+ stopLineId = Math.floor(Math.random()*stopLineArray.length);
446
+
447
+ for (var i = 0; i < iconNum; i++) {
448
+
449
+ while (iconArray[0][stopLineArray[stopLineId][i]] != iconArray[1][stopLineArray[stopLineId][i]] &&
450
+
451
+ iconArray[1][stopLineArray[stopLineId][i]] != iconArray[2][stopLineArray[stopLineId][i]]) {
452
+
453
+ iArray[0] = iconArray[0][stopLineArray[stopLineId][i]];
454
+
455
+ iArray[1] = iconArray[1][stopLineArray[stopLineId][i]];
456
+
457
+ iArray[2] = iconArray[2][stopLineArray[stopLineId][i]];
458
+
459
+ break;
460
+
461
+ }
34
462
 
35
463
  }
36
464
 
37
-
38
-
39
- #slotmachinebox #reelbox {
40
-
41
- position: absolute;
42
-
43
- top: 64px;
44
-
45
- left: 30px;
46
-
47
- display: block;
48
-
49
- overflow: hidden;
50
-
51
- width: 430px;
52
-
53
- height: 194px;
54
-
55
- margin: 0;
56
-
57
- padding: 0;
58
-
59
- }
60
-
61
-
62
-
63
- #slotmachinebox #reelbox .reel {
64
-
65
- position: absolute;
66
-
67
- z-index: 1;
68
-
69
- display: block;
70
-
71
- overflow: hidden;
72
-
73
- width: 120px;
74
-
75
- height: 180px;
76
-
77
- margin-top: 5px;
78
-
79
- margin-left: 15px;
80
-
81
- padding: 0;
82
-
83
- }
84
-
85
-
86
-
87
- #slotmachinebox #reelbox .reel0{
88
-
89
- top: 0px;
90
-
91
- left: 10px;
92
-
93
- }
94
-
95
-
96
-
97
- #slotmachinebox #reelbox .reel1{
98
-
99
- top: 0px;
100
-
101
- left: 137px;
102
-
103
- }
104
-
105
-
106
-
107
- #slotmachinebox #reelbox .reel2{
108
-
109
- top: 0px;
110
-
111
- left: 274px;
112
-
113
- }
114
-
115
-
116
-
117
- #slotmachinebox #reelbox .wrapper{
118
-
119
- list-style:none outside;
120
-
121
- position: absolute;
122
-
123
- top: 0px;
124
-
125
- left: 0px;
126
-
127
- width: 120px;
128
-
129
- margin: 0;
130
-
131
- padding: 0;
132
-
133
- }
134
-
135
- #slotmachinebox #reelbox .wrapper .icon0,
136
-
137
- #slotmachinebox #reelbox .wrapper .icon1,
138
-
139
- #slotmachinebox #reelbox .wrapper .icon2,
140
-
141
- #slotmachinebox #reelbox .wrapper .icon3,
142
-
143
- #slotmachinebox #reelbox .wrapper .icon4,
144
-
145
- #slotmachinebox #reelbox .wrapper .icon5,
146
-
147
- #slotmachinebox #reelbox .wrapper .icon6,
148
-
149
- #slotmachinebox #reelbox .wrapper .icon7,
150
-
151
- #slotmachinebox #reelbox .wrapper .icon8,
152
-
153
- #slotmachinebox #reelbox .wrapper .icon9,
154
-
155
- #slotmachinebox #reelbox .wrapper .icon10,
156
-
157
- #slotmachinebox #reelbox .wrapper .icon11,
158
-
159
- #slotmachinebox #reelbox .wrapper .icon12,
160
-
161
- #slotmachinebox #reelbox .wrapper .icon13,
162
-
163
- #slotmachinebox #reelbox .wrapper .icon14 {
164
-
165
- display: block;
166
-
167
- width: 120px;
168
-
169
- height: 60px;
170
-
171
- margin: 0;
172
-
173
- padding: 0;
174
-
175
- //text-indent: -10000px;
176
-
177
- background-image: url(img/sloticons.png);
178
-
179
- }
180
-
181
-
182
-
183
- #slotmachinebox #reelbox .wrapper .icon0{
184
-
185
- background-position: 0 0px;
186
-
187
- }
188
-
189
-
190
-
191
- #slotmachinebox #reelbox .wrapper .icon1{
192
-
193
- background-position: 0 -60px;
194
-
195
- }
196
-
197
-
198
-
199
- #slotmachinebox #reelbox .wrapper .icon2{
200
-
201
- background-position: 0 -120px;
202
-
203
- }
204
-
205
-
206
-
207
- #slotmachinebox #reelbox .wrapper .icon3{
208
-
209
- background-position: 0 -180px;
210
-
211
- }
212
-
213
-
214
-
215
- #slotmachinebox #reelbox .wrapper .icon4{
216
-
217
- background-position: 0 -240px;
218
-
219
- }
220
-
221
-
222
-
223
- #slotmachinebox #reelbox .wrapper .icon5{
224
-
225
- background-position: 0 -300px;
226
-
227
- }
228
-
229
-
230
-
231
- #slotmachinebox #reelbox .wrapper .icon6{
232
-
233
- background-position: 0 -360px;
234
-
235
- }
236
-
237
465
  ```
238
466
 
239
- ```JavaScript
240
-
241
- // 定数定義
242
-
243
- var fps = 60; //FPS
244
-
245
- var interval = 1 / fps * 1000;
246
-
247
-
248
-
249
- var maxRand = 65536; //最大乱数
250
-
251
- //11070
252
-
253
- var configNum = 6; //設定数
254
-
255
- var configTable = [
256
-
257
- // 0:BIG 1:REG 2:コイン 3:スイカ 4:ベル 5:チェリー 6:リプレイ
258
-
259
- [[0,99],[100,149],[150,299],[300,549],[550,869],[870,2539],[2540,4500]], //設定1
260
-
261
- [[0,99],[100,149],[150,299],[300,549],[550,869],[870,2539],[2540,4500]], //設定2
262
-
263
- [[0,99],[100,149],[150,299],[300,549],[550,869],[870,2539],[2540,4500]], //設定3
264
-
265
- [[0,99],[100,149],[150,299],[300,549],[550,869],[870,2539],[2540,4500]], //設定4
266
-
267
- [[0,99],[100,149],[150,299],[300,549],[550,869],[870,2539],[2540,4500]], //設定5
268
-
269
- [[0,99],[100,149],[150,299],[300,549],[550,869],[870,2539],[2540,4500]] //設定6
270
-
271
- ];
272
-
273
-
274
-
275
- var iconNum = 21; //リールに表示する絵柄絵柄数
276
-
277
- var iconWidth = 120; //絵柄の幅
278
-
279
- var iconHeight = 60; //絵柄の高さ
280
-
281
-
282
-
283
- var reelArray = new Array();
284
-
285
- var reelNum = 3; //リール数
286
-
287
- var reelMargin = 5;
288
-
289
- var reelBaseX = 18;
290
-
291
- var reelBaseY = 92;
292
-
293
- var reelHeight = (iconHeight * iconNum); //リールの高さ
294
-
295
- var reelMoveSpeedY = Math.floor(iconHeight / 3); //リール移動スピード
296
-
297
-
298
-
299
- var iconArray = [//絵柄配列
300
-
301
- [4, 5, 1, 3, 4, 6, 1, 3, 2, 6, 4, 3, 5, 6, 2, 5, 6, 4, 3, 0, 6],
302
-
303
- [6, 4, 1, 3, 6, 5, 4, 5, 6, 4, 2, 3, 6, 0, 4, 3, 6, 1, 4, 2, 5],
304
-
305
- [5, 3, 1, 4, 6, 3, 4, 0, 6, 3, 5, 6, 2, 3, 4, 6, 5, 0, 3, 4, 6]
306
-
307
- ];
308
-
309
- var stopLineArray = [[1,1,1],[0,0,0],[2,2,2],[0,1,2],[2,1,0]]; //停止ライン配列
310
-
311
- var stopLineId = 0;
312
-
313
-
314
-
315
- //変数定義
316
-
317
- var configId = Math.floor(Math.random()*configNum); //設定を決める
318
-
319
-
320
-
321
- var reelStopFlg = [null, null, null];
322
-
323
- var reelposY = [0, 0, 0]; //リールの移動量
324
-
325
-
326
-
327
- var winIconArray = [ //当たり絵柄配列
328
-
329
- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
330
-
331
- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
332
-
333
- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
334
-
335
- ];
336
-
337
- var hitIcon = [
338
-
339
- [0, 0, 0],
340
-
341
- [0, 0, 0],
342
-
343
- [0, 0, 0]
344
-
345
- ];
346
-
347
-
348
-
349
- // リール回転用
350
-
351
- var reelmoveAnime;
352
-
353
-
354
-
355
- addSlots();
356
-
357
-
358
-
359
- function slotStart() {
360
-
361
- reelStopFlg = [false, false, false];
362
-
363
- winLottery();
364
-
365
- reelmoveAnime = setInterval(slotMove, interval);
366
-
367
- $('[id^=stopbtn]').css("pointer-events", "auto");
368
-
369
- }
370
-
371
-
372
-
373
- function slotStop(i) {
374
-
375
- reelStopFlg[i] = true;
376
-
377
- }
378
-
379
-
380
-
381
- function winLottery() {
382
-
383
- var iArray = [0,0,0];
384
-
385
- var rand = Math.floor(Math.random()*maxRand);
386
-
387
- for (var i = 0; i < configTable[configId].length; i++) {
388
-
389
- if(configTable[configId][i][0] >= rand || rand <= configTable[configId][i][1]){
390
-
391
- console.log("あたり");
392
-
393
- iArray = [i,i,i];
394
-
395
- wIcArrayRewrite(iArray);
396
-
397
- break;
398
-
399
- }
400
-
401
- if(i == configTable[configId].length-1){
402
-
403
- console.log("はずれ");
404
-
405
- iArray[0] = Math.floor(Math.random()*configTable[configId].length);
406
-
407
- iArray[1] = Math.floor(Math.random()*configTable[configId].length);
408
-
409
- iArray[2] = Math.floor(Math.random()*configTable[configId].length);
410
-
411
- wIcArrayRewrite(iArray);
412
-
413
- }
414
-
415
- }
416
-
417
- }
418
-
419
-
420
-
421
- function wIcArrayRewrite(iArray) {
422
-
423
- for (var i = 0; i < reelNum; i++) {
424
-
425
- for (var j = 0; j < iconNum; j++) {
426
-
427
- if(iconArray[i][j] == iArray[i]){
428
-
429
- winIconArray[i][j] = 1;
430
-
431
- }else{
432
-
433
- winIconArray[i][j] = 0;
434
-
435
- }
436
-
437
- }
438
-
439
- }
440
-
441
- }
442
-
443
-
444
-
445
- //リール作成
446
-
447
- function addSlots() {
448
-
449
- reelStopFlg[i] = false;
450
-
451
- for (var i = 0; i < reelNum; i++) {
452
-
453
- $('.reel').eq(i).css("left", ((iconWidth + reelMargin) * i) + "px");
454
-
455
- $('.wrapper').eq(i).css("height", reelHeight + "px");
456
-
457
- $('.wrapper').eq(i).css("top", "-" + (iconHeight * Math.floor(Math.random()*iconNum)) + "px");
458
-
459
- for (var j = 0; j < 24; j++) {
460
-
461
- if (j < iconNum) {
462
-
463
- $('.wrapper').eq(i).append("<li class='icon icon" + iconArray[i][j] +
464
-
465
- "'>" + iconArray[i][j] + "</li>");
466
-
467
- } else {
468
-
469
- $('.wrapper').eq(i).append("<li class='icon icon" + iconArray[i][j - 21] +
470
-
471
- "'>" + iconArray[i][j - 21] + "</li>");
472
-
473
- }
474
-
475
- }
476
-
477
- }
478
-
479
- }
480
-
481
-
482
-
483
- //リール回転
484
-
485
- function slotMove() {
486
-
487
- for (var i = 0, stopCount = 0; i < reelNum; i++) {
488
-
489
- if (!reelStopFlg[i] || reelposY[i] % iconHeight || winIconArray[i][(-reelposY[i] / iconHeight)+stopLineArray[stopLineId][i]] != 1) {
490
-
491
- reelposY[i] += reelMoveSpeedY;
492
-
493
- if (reelposY[i] > 0) reelposY[i] -= reelHeight;
494
-
495
- $('.wrapper').eq(i).css("top", reelposY[i] + "px");
496
-
497
- } else {
498
-
499
- stopCount++;
500
-
501
- }
502
-
503
- if (stopCount == reelNum) {
504
-
505
- $('#startbtn').css("pointer-events", "auto");
506
-
507
- clearInterval(reelmoveAnime);
508
-
509
- slotHits();
510
-
511
- }
512
-
513
- }
514
-
515
- }
516
-
517
-
518
-
519
- function slotHits() {
520
-
521
- for (var i = 0; i < reelNum; i++) {
522
-
523
- for (var j = 0; j < reelNum; j++) {
524
-
525
- hitIcon[i][j] = ((-reelposY[i] / iconHeight) + j);
526
-
527
- if (hitIcon[i][j] >= iconNum) {
528
-
529
- hitIcon[i][j] -= iconNum;
530
-
531
- }
532
-
533
- }
534
-
535
- }
536
-
537
- if (iconArray[0][hitIcon[0][0]] == iconArray[1][hitIcon[1][0]] &&
538
-
539
- iconArray[1][hitIcon[1][0]] == iconArray[2][hitIcon[2][0]]) {
540
-
541
- $("#result").html("上段が揃いました");
542
-
543
- } else if (iconArray[0][hitIcon[0][1]] == iconArray[1][hitIcon[1][1]] &&
544
-
545
- iconArray[1][hitIcon[1][1]] == iconArray[2][hitIcon[2][1]]) {
546
-
547
- $("#result").html("中段が揃いました");
548
-
549
- } else if (iconArray[0][hitIcon[0][2]] == iconArray[1][hitIcon[1][2]] &&
550
-
551
- iconArray[1][hitIcon[1][2]] == iconArray[2][hitIcon[2][2]]) {
552
-
553
- $("#result").html("下段が揃いました");
554
-
555
- } else if (iconArray[0][hitIcon[0][2]] == iconArray[1][hitIcon[1][1]] &&
556
-
557
- iconArray[1][hitIcon[1][1]] == iconArray[2][hitIcon[2][0]]) {
558
-
559
- $("#result").html("左斜めが揃いました");
560
-
561
- } else if (iconArray[0][hitIcon[0][0]] == iconArray[1][hitIcon[1][1]] &&
562
-
563
- iconArray[1][hitIcon[1][1]] == iconArray[2][hitIcon[2][2]]) {
564
-
565
- $("#result").html("右斜めが揃いました");
566
-
567
- } else {
568
-
569
- $("#result").html("残念!!");
570
-
571
- }
572
-
573
- }
574
-
575
-
576
-
577
- ```
578
-
579
- ```html
580
-
581
- <html>
582
-
583
- <body>
584
-
585
- <div id="result"></div>
586
-
587
- <div id="slotmachinebox">
588
-
589
- <div id="reelbox">
590
-
591
- <div class="reel reel0">
592
-
593
- <ul class="wrapper">
594
-
595
- </ul>
596
-
597
- </div>
598
-
599
- <div class="reel reel1">
600
-
601
- <ul class="wrapper">
602
-
603
- </ul>
604
-
605
- </div>
606
-
607
- <div class="reel reel2">
608
-
609
- <ul class="wrapper">
610
-
611
- </ul>
612
-
613
- </div>
614
-
615
- </div>
616
-
617
- </div>
618
-
619
- </body>
620
-
621
- </html>
622
-
623
- ```
624
-
625
-
626
-
627
- お時間あればこちの質問にも回答してただければ幸いです。
467
+ 時々止まってまったり、ボタンを押したときにリール止まことがあります。
628
-
629
- [https://teratail.com/questions/114846](https://teratail.com/questions/114846)
630
-
631
-
632
-
633
- 【追記】
634
-
635
- ご回答された方申し訳ありません。もう少し詳細な説明をするべきでした。
636
-
637
-
638
-
639
- このスロットは、縦3つ・左右斜め3つのラインに絵柄を揃えるルールですので、画面上はこのようになっています。
640
-
641
- [2][4][6]
642
-
643
- [5][8][3]
644
-
645
- [9][7][1]
646
-
647
- ハズレの際の絵柄を決める部分はこうなっています。
648
-
649
- ```javascript
650
-
651
- iArray[0] = Math.floor(Math.random()*configTable[configId].length);
652
-
653
- iArray[1] = Math.floor(Math.random()*configTable[configId].length);
654
-
655
- iArray[2] = Math.floor(Math.random()*configTable[configId].length);
656
-
657
- ```
658
-
659
- その結果出力された乱数は例えば
660
-
661
- iArray[1,3,5]
662
-
663
- だとすると、中央のラインは揃いませんが、画面では
664
-
665
- [2][2][2]
666
-
667
- [1][3][5]
668
-
669
- [4][8][7]
670
-
671
- と、上ラインに2の絵柄が揃ってしまいます。
672
-
673
- ※これは例ですので、実際のリールの配列とは違います
674
-
675
-
676
-
677
- 乱数は中央ラインにしか対応しておらず、上下ライン・左右斜めラインが予期しない形で揃ってしまうことがあるので、それを解消したいというわけです。
678
-
679
-
680
-
681
- 中央ラインだけ揃わないようにする方法は簡単ですが、これはリール配列の参照を行わないと実現できないと思うのですが、そのロジックが思いつきません。
682
-
683
-
684
-
685
- 実際のコードは記載していただかなくても構いませんので、考え方のヒントやアドバイスなどを
686
-
687
- よろしくお願い致します。

6

2018/03/10 11:19

投稿

nosonosolife
nosonosolife

スコア42

test CHANGED
File without changes
test CHANGED
File without changes

5

2018/03/09 11:13

投稿

nosonosolife
nosonosolife

スコア42

test CHANGED
File without changes
test CHANGED
@@ -678,7 +678,7 @@
678
678
 
679
679
 
680
680
 
681
- これはリール配列の参照を行わないと実現できないと思うのですが、そのロジックが思いつきません。
681
+ 中央ラインだけ揃わないようにする方法は簡単ですが、これはリール配列の参照を行わないと実現できないと思うのですが、そのロジックが思いつきません。
682
682
 
683
683
 
684
684
 

4

2018/03/09 07:50

投稿

nosonosolife
nosonosolife

スコア42

test CHANGED
File without changes
test CHANGED
@@ -627,3 +627,61 @@
627
627
  もしお時間があればこちらの質問にも回答していただければ幸いです。
628
628
 
629
629
  [https://teratail.com/questions/114846](https://teratail.com/questions/114846)
630
+
631
+
632
+
633
+ 【追記】
634
+
635
+ ご回答された方申し訳ありません。もう少し詳細な説明をするべきでした。
636
+
637
+
638
+
639
+ このスロットは、縦3つ・左右斜め3つのラインに絵柄を揃えるルールですので、画面上はこのようになっています。
640
+
641
+ [2][4][6]
642
+
643
+ [5][8][3]
644
+
645
+ [9][7][1]
646
+
647
+ ハズレの際の絵柄を決める部分はこうなっています。
648
+
649
+ ```javascript
650
+
651
+ iArray[0] = Math.floor(Math.random()*configTable[configId].length);
652
+
653
+ iArray[1] = Math.floor(Math.random()*configTable[configId].length);
654
+
655
+ iArray[2] = Math.floor(Math.random()*configTable[configId].length);
656
+
657
+ ```
658
+
659
+ その結果出力された乱数は例えば
660
+
661
+ iArray[1,3,5]
662
+
663
+ だとすると、中央のラインは揃いませんが、画面では
664
+
665
+ [2][2][2]
666
+
667
+ [1][3][5]
668
+
669
+ [4][8][7]
670
+
671
+ と、上ラインに2の絵柄が揃ってしまいます。
672
+
673
+ ※これは例ですので、実際のリールの配列とは違います
674
+
675
+
676
+
677
+ 乱数は中央ラインにしか対応しておらず、上下ライン・左右斜めラインが予期しない形で揃ってしまうことがあるので、それを解消したいというわけです。
678
+
679
+
680
+
681
+ これはリール配列の参照を行わないと実現できないと思うのですが、そのロジックが思いつきません。
682
+
683
+
684
+
685
+ 実際のコードは記載していただかなくても構いませんので、考え方のヒントやアドバイスなどを
686
+
687
+ よろしくお願い致します。

3

2018/03/09 07:45

投稿

nosonosolife
nosonosolife

スコア42

test CHANGED
File without changes
test CHANGED
@@ -621,3 +621,9 @@
621
621
  </html>
622
622
 
623
623
  ```
624
+
625
+
626
+
627
+ もしお時間があればこちらの質問にも回答していただければ幸いです。
628
+
629
+ [https://teratail.com/questions/114846](https://teratail.com/questions/114846)

2

2018/03/08 20:00

投稿

nosonosolife
nosonosolife

スコア42

test CHANGED
File without changes
test CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  それ以外はハズレで、3つのリールとも乱数で適当に選んだ絵柄に止まるのですが、
8
8
 
9
- 時々ハズレの場合でもたまたま横3つ・左右斜3つに絵柄が揃ってしまうことがあります。
9
+ 時々ハズレの場合でも意図しない形で横3つ・左右斜3つに絵柄が揃ってしまうことがあります。
10
10
 
11
11
  ハズレの際は絵柄が全く揃わないようにするにはどの様な乱数の決め方やチェックを行えばいいでしょうか。
12
12
 

1

2018/03/08 19:52

投稿

nosonosolife
nosonosolife

スコア42

test CHANGED
File without changes
test CHANGED
@@ -621,13 +621,3 @@
621
621
  </html>
622
622
 
623
623
  ```
624
-
625
- 【追記】
626
-
627
- リールの移動速度を遅くしたらどうなるのかと思い、
628
-
629
- reelMoveSpeedY = Math.floor(iconHeight / 10)
630
-
631
- と変更して試して見たのですが、それでも1つだけ止まらない事がありました。
632
-
633
- 恐らくストップボタンを押すタイミングが関係しているのではないかと思います。