1
1
import 'phaser' ;
2
2
import { } from 'rxjs' ;
3
- import { cover , rotateTips , isHit , Vec2 , CONSTANT , arrDisorder } from '../../Public/jonny/core' ;
3
+ import { cover , rotateTips , isHit , Vec2 , CONSTANT , arrDisorder } from '../../Public/jonny/core' ;
4
4
import { Button , ButtonMusic , ButtonExit , SellingGold , Gold , SuccessBtn , TryAginListenBtn } from '../../Public/jonny/components' ;
5
5
import { Game23Data , Assets } from '../../interface/Game23' ;
6
6
import { Basin } from "../../Public/jonny/game23/Basin" ;
@@ -18,7 +18,7 @@ var goldValue: number = 3; //金币的值
18
18
19
19
export default class Game23PlayScene extends Phaser . Scene {
20
20
private ccData : Array < Game23Data > = [ ] ;
21
- private rightTimes :number = 0 ; //正确的次数
21
+ private rightTimes : number = 0 ; //正确的次数
22
22
private times : number = 0 ; //次数
23
23
24
24
//静态开始
@@ -31,9 +31,9 @@ export default class Game23PlayScene extends Phaser.Scene {
31
31
//静态结束
32
32
33
33
//动态开始
34
- private toys :Array < Toy > = [ ] ; //玩具
35
- private basins :Array < Basin > = [ ] ; //盆
36
- private civa :Shooter ;
34
+ private toys : Array < Toy > = [ ] ; //玩具
35
+ private basins : Array < Basin > = [ ] ; //盆
36
+ private civa : Shooter ;
37
37
private tipsParticlesEmitter : TipsParticlesEmitter ;
38
38
private sellingGold : SellingGold ;
39
39
@@ -169,21 +169,22 @@ export default class Game23PlayScene extends Phaser.Scene {
169
169
let offsetY = 337 - 145 ;
170
170
let ccDataClone = this . ccData . concat ( this . ccData ) ;
171
171
ccDataClone = arrDisorder ( ccDataClone ) ;
172
- ccDataClone . forEach ( ( v , i ) => {
172
+ ccDataClone . forEach ( ( v , i ) => {
173
173
let initX = 136 ;
174
174
let initY = 145 ;
175
- let _ix = i % 5 ;
176
- let _iy = Math . floor ( i / 5 ) ;
177
- let x = initX + offsetX * _ix ;
178
- let y = initY + offsetY * _iy ;
179
- let toy = new Toy ( this , x , y , v . questionContent , v . questionContent ) . init ( ) ;
175
+ let _ix = i % 5 ;
176
+ let _iy = Math . floor ( i / 5 ) ;
177
+ let x = initX + offsetX * _ix ;
178
+ let y = initY + offsetY * _iy ;
179
+ let toy = new Toy ( this , x , y , v . questionContent , v . questionContent ) . init ( ) ;
180
180
this . toys . push ( toy ) ;
181
181
this . layer1 . add ( toy ) ;
182
182
} ) ;
183
183
184
184
//创建盆
185
- this . ccData . forEach ( ( v , i ) => {
186
- let basin = new Basin ( this , v . questionContent ) . init ( ) ;
185
+ console . log ( index ) ;
186
+ this . ccData . forEach ( ( v , i ) => {
187
+ let basin = new Basin ( this , v . questionContent ) . init ( ) ;
187
188
this . basins . push ( basin ) ;
188
189
this . layer2 . add ( basin ) ;
189
190
} )
@@ -197,51 +198,102 @@ export default class Game23PlayScene extends Phaser.Scene {
197
198
*/
198
199
private async gameStart ( ) {
199
200
let that = this ;
200
- let toyPointerDown = function ( toy :Toy ) {
201
+ let toyPointerDown = function ( toy : Toy ) {
201
202
this . checkoutResult ( toy )
202
- . then ( async value => { //正确
203
- console . log ( value ) ;
204
- that . rightTimes += value ;
205
- if ( value === 1 && that . rightTimes === 1 ) {
206
- toy . disableInteractive ( ) ;
207
- that . audioPlay ( "successMp3" ) ;
208
- await that . basins [ index ] . move ( toy . x ) ;
209
- that . audioPlay ( toy . name + "Sound" ) ;
210
- toy . isRight ( that . rightTimes , that . basins [ index ] ) ;
211
- } else if ( value === 1 && that . rightTimes === 2 ) {
212
- toy . disableInteractive ( ) ;
213
- that . audioPlay ( "successMp3" ) ;
214
- await that . basins [ index ] . move ( toy . x ) ;
215
- that . audioPlay ( toy . name + "Sound" ) ;
216
- toy . isRight ( that . rightTimes , that . basins [ index ] ) ;
217
- } else if ( value === 0 ) {
218
- toy . isWrong ( ) ;
219
- }
220
- } )
203
+ . then ( async ( value : number ) => { //正确
204
+ console . log ( value ) ;
205
+ that . rightTimes += value ;
206
+ that . disableToys ( true ) ;
207
+ if ( value === 1 && that . rightTimes === 1 ) { //当回答正确,且射击次数为1
208
+ //toy.disableInteractive();
209
+ //that.disableToys(true);
210
+ that . audioPlay ( "successMp3" ) ;
211
+ await that . basins [ index ] . move ( toy . x ) ;
212
+ that . audioPlay ( toy . name + "Sound" ) ;
213
+ await toy . isRight ( that . rightTimes , that . basins [ index ] ) ;
214
+ that . disableToys ( false ) ;
215
+ } else if ( value === 1 && that . rightTimes === 2 ) { //当回答正确,且射击次数为2
216
+ //that.disableToys(true);
217
+ that . audioPlay ( "successMp3" ) ;
218
+ await that . basins [ index ] . move ( toy . x ) ;
219
+ that . audioPlay ( toy . name + "Sound" ) ;
220
+ await toy . isRight ( that . rightTimes , that . basins [ index ] ) ;
221
+ await that . basins [ index ] . moveLeft ( ) ;
222
+ console . log ( index ) ;
223
+ if ( index === 2 || index === 3 ) {
224
+ await that . basins [ index ] . moveRight ( ) ;
225
+ } else if ( index === 4 ) {
226
+ await that . basins [ index ] . moveCenter ( ) ;
227
+ }
228
+ that . isRight ( ) ;
229
+ } else if ( value === 0 ) {
230
+ await toy . isWrong ( ) ;
231
+ that . isWrong ( ) ;
232
+ }
233
+ } )
221
234
}
222
235
223
- let toyShow :Promise < number > [ ] = this . toys . map ( ( toy , i ) => {
224
- let delay = 300 * i ;
225
- toy . on ( "pointerdown" , toyPointerDown . bind ( this , toy ) ) ;
236
+ let toyShow : Promise < number > [ ] = this . toys . map ( ( toy , i ) => {
237
+ let delay = 300 * i ;
238
+ toy . on ( "pointerdown" , toyPointerDown . bind ( this , toy ) ) ;
226
239
return toy . show ( delay ) ;
227
240
} )
228
241
229
242
await Promise . all ( toyShow ) ;
230
243
this . basins [ index ] . show ( ) ;
244
+ this . audioPlay ( this . basins [ index ] . name + "Sound" ) ;
245
+ //this.nextTopic();
246
+ }
247
+
248
+ /**
249
+ * 激活或禁止所有玩具的输入事件
250
+ */
251
+ private disableToys ( yes : boolean ) {
252
+ if ( yes ) {
253
+ this . toys . forEach ( toy => {
254
+ toy . disableInteractive ( ) ;
255
+ } ) ;
256
+ } else if ( ! yes ) {
257
+ this . toys . forEach ( toy => {
258
+ toy . setInteractive ( ) ;
259
+ } ) ;
260
+ }
261
+
262
+ }
263
+
264
+ /**
265
+ * 下一题
266
+ */
267
+ private nextTopic ( ) {
268
+ console . log ( index ) ;
269
+ index += 1 ;
270
+ if ( index > this . ccData . length - 1 ) {
271
+ window . location . href = CONSTANT . INDEX_URL ;
272
+ }
273
+ this . rightTimes = 0 ;
274
+ this . disableToys ( false )
275
+ this . basins [ index ] . show ( ) ;
276
+ this . audioPlay ( this . basins [ index ] . name + "Sound" ) ;
277
+ }
231
278
232
-
279
+ /**
280
+ * 换一道题
281
+ */
282
+ private async changeTopic ( ) {
283
+ await this . basins [ index ] . hide ( ) ;
284
+ this . nextTopic ( ) ;
233
285
}
234
286
235
287
/**
236
288
* 判断做题结果是否正确
237
289
*/
238
- private checkoutResult ( toy :Toy ) : Promise < number > {
239
- let answer :boolean = toy . name === this . basins [ index ] . name ;
240
- console . log ( toy . name , this . basins [ index ] . name ) ;
290
+ private checkoutResult ( toy : Toy ) : Promise < number > {
291
+ let answer : boolean = toy . name === this . basins [ index ] . name ;
292
+ console . log ( toy . name , this . basins [ index ] . name ) ;
241
293
return new Promise ( resolve => {
242
- if ( answer ) {
294
+ if ( answer ) {
243
295
resolve ( 1 ) ;
244
- } else {
296
+ } else {
245
297
resolve ( 0 ) ;
246
298
}
247
299
} ) ;
@@ -286,10 +338,6 @@ export default class Game23PlayScene extends Phaser.Scene {
286
338
287
339
}
288
340
289
-
290
-
291
-
292
-
293
341
/**
294
342
* 正确的结果处理
295
343
*/
@@ -299,14 +347,16 @@ export default class Game23PlayScene extends Phaser.Scene {
299
347
callback : ( ) => {
300
348
this . sellingGold . golds . destroy ( ) ;
301
349
this . setGoldValue ( 3 ) ;
302
- this . nextRound ( ) ;
350
+ ;
351
+ this . nextTopic ( ) ;
303
352
}
304
353
} ) ;
305
354
this . sellingGold . golds . setDepth ( 6 ) ;
306
355
this . tipsParticlesEmitter . success ( ( ) => {
307
356
this . sellingGold . goodJob ( 3 ) ;
308
357
} )
309
358
}
359
+ nextFuc ( ) ;
310
360
}
311
361
312
362
/**
@@ -332,9 +382,7 @@ export default class Game23PlayScene extends Phaser.Scene {
332
382
* 重置开始状态
333
383
*/
334
384
private resetStart ( ) {
335
-
336
- this . successBtn . setAlpha ( 0 ) ;
337
- this . successBtn . interactive = true ;
385
+ this . disableToys ( false ) ;
338
386
}
339
387
340
388
/**
@@ -343,7 +391,7 @@ export default class Game23PlayScene extends Phaser.Scene {
343
391
private ohNo ( ) {
344
392
this . setGoldValue ( - 1 ) ;
345
393
this . tipsParticlesEmitter . error (
346
- this . nextRound ,
394
+ this . changeTopic ,
347
395
this . resetStart
348
396
)
349
397
if ( goldValue === 0 ) {
@@ -358,7 +406,7 @@ export default class Game23PlayScene extends Phaser.Scene {
358
406
* 下一道题
359
407
*/
360
408
private nextRound ( ) : void {
361
- index += 1 ;
409
+ // index += 1;
362
410
if ( index > this . ccData . length - 1 ) {
363
411
window . location . href = CONSTANT . INDEX_URL ;
364
412
}
@@ -369,14 +417,13 @@ export default class Game23PlayScene extends Phaser.Scene {
369
417
} ) ;
370
418
}
371
419
372
-
420
+
373
421
374
422
/**
375
423
* 设置金币的动作
376
424
*/
377
425
private setGoldValue ( value : number ) {
378
426
goldValue += value ;
379
-
380
427
this . gold . setText ( goldValue ) ;
381
428
}
382
429
0 commit comments