-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
2195 lines (1924 loc) · 64.8 KB
/
index.html
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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<title>Symbol Typing Quest</title>
<meta name="description" content="This is a typing game using the Symbol blockchain.
This is a submission to the NEMTUS Hackathon 2022.
Created by @kurikou02
https://twitter.com/kurikou02
<br>
NEMTUS Hackathon 2022:https://hackathon-2022.nemtus.com/
MusMus:https://musmus.main.jp
" />
<style>*, *:before, *:after {
box-sizing: border-box;
}
html {
font-size: 13px;
}
body {
font-family: Avenir, "Open Sans", "Helvetica Neue", Helvetica, Arial, Verdana, Roboto, "游ゴシック", "Yu Gothic", "游ゴシック体", "YuGothic", "ヒラギノ角ゴ Pro W3", "Hiragino Kaku Gothic Pro", "Meiryo UI", "メイリオ", Meiryo, "MS Pゴシック", "MS PGothic", sans-serif;
color: #444;
background-color: hsl(0, 0%, 96%);
}
h1 {
font-size: 1.8rem;
}
</style>
</head>
<body>
<h1>Symbol Typing Quest</h1>
<p>This is a typing game using the Symbol blockchain.
This is a submission to the NEMTUS Hackathon 2022.
Created by @kurikou02
https://twitter.com/kurikou02
<br>
NEMTUS Hackathon 2022:https://hackathon-2022.nemtus.com/
MusMus:https://musmus.main.jp
</p>
<script src="https://cdn.jsdelivr.net/gh/phinajs/[email protected]/build/phina.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/howler.js" defer></script>
<script src="https://xembook.github.io/nem2-browserify/symbol-sdk-1.0.3.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@8"></script>
<script src="https://cdn.jsdelivr.net/npm/promise-polyfill"></script>
<script>/*
* Runstant
* 思いたったらすぐ開発. プログラミングに革命を...
*/
phina.globalize();
var SCREEN_WIDTH = 649; // default 640
var SCREEN_HEIGHT = 960; // default 960
var PIECE_SIZE = 80;
var PIECE_SIZE_HALF = PIECE_SIZE/2;
var MARGIN = 160;
var GAME_MODE = {
nomal : 1,
hard : 2
};
// アセット
var ASSETS = {
// 画像
image: {
'title_bg': 'https://cdn.jsdelivr.net/gh/kurikou02/symbol_game_asset@main/image/title-back.png',
'game_bg':'https://cdn.jsdelivr.net/gh/kurikou02/symbol_game_asset@main/image/game_background01.png',
'result_bg': 'https://cdn.jsdelivr.net/gh/kurikou02/symbol_game_asset@main/image/result_bg2.png',
'gameover_bg': 'https://cdn.jsdelivr.net/gh/kurikou02/symbol_game_asset@main/image/gamover_bg2.png',
'boss': 'https://github.com/kurikou02/symbol_game_asset/blob/main/test/Hatchet_Avatar_CircleCrop_200px.png?raw=true',
'Hatchet': 'https://cdn.jsdelivr.net/gh/kurikou02/symbol_game_asset@main/image/boss_Hatchet_Avatar.png',
'Jaguar': 'https://cdn.jsdelivr.net/gh/kurikou02/symbol_game_asset@main/image/boss_Jaguar_Avatar.png',
'Gimre': 'https://cdn.jsdelivr.net/gh/kurikou02/symbol_game_asset@main/image/boss_Gimre_Avatar.png',
'bullet': 'https://github.com/kurikou02/symbol_game_asset/blob/main/test/Hatchet_Avatar_CircleCrop_200px.png?raw=true',
'shuriken': 'https://cdn.jsdelivr.net/gh/kurikou02/symbol_game_asset@main/image/shuriken02.png',
'ono': 'https://cdn.jsdelivr.net/gh/kurikou02/symbol_game_asset@main/image/ono.png',
'beam': 'https://cdn.jsdelivr.net/gh/kurikou02/symbol_game_asset@main/image/beam.png',
'Bomb':'https://cdn.jsdelivr.net/gh/kurikou02/symbol_game_asset@main/image/Bomb.png',
},
sound:{
// 入力文字OK時
'ok':'https://cdn.jsdelivr.net/gh/kurikou02/symbol_game_asset@main/sound/shot01.mp3',
// 入力文字NG時
'ng':'https://cdn.jsdelivr.net/gh/kurikou02/symbol_game_asset@main/sound/cncl01.mp3',
// 敵味方へのダメージ効果音
'damage':'https://cdn.jsdelivr.net/gh/kurikou02/symbol_game_asset@main/sound/boss_damage.mp3',
// ボス撃破時
'ko':'https://cdn.jsdelivr.net/gh/kurikou02/symbol_game_asset@main/sound/boss_ko.mp3',
// ゲーム開始音
'system01':'https://cdn.jsdelivr.net/gh/kurikou02/symbol_game_asset@main/sound/system01.mp3',
// 1単語クリア
'word_clear':'https://cdn.jsdelivr.net/gh/kurikou02/symbol_game_asset@main/sound/word_clear.mp3',
// 時間切れ
'timeout':'https://cdn.jsdelivr.net/gh/kurikou02/symbol_game_asset@main/sound/timeout.mp3',
// ゲームオーバー
'game_clear':'https://cdn.jsdelivr.net/gh/kurikou02/symbol_game_asset@main/sound/game_clear.mp3',
// ゲームクリア
'game_over':'https://cdn.jsdelivr.net/gh/kurikou02/symbol_game_asset@main/sound/game_over.mp3',
// ボム発動
'bomb_sound':'https://cdn.jsdelivr.net/gh/kurikou02/symbol_game_asset@main/sound/bomb.mp3',
// 戦闘BGM
'bgm':'https://cdn.jsdelivr.net/gh/kurikou02/symbol_game_asset@main/sound/Pirate_bgm.mp3',
},
font:{
'Rajdhani-bold':'https://cdn.jsdelivr.net/gh/kurikou02/symbol_game_asset@main/font/Rajdhani/Rajdhani-Bold.ttf',
'Rajdhani-light':'https://cdn.jsdelivr.net/gh/kurikou02/symbol_game_asset@main/font/Rajdhani/Rajdhani-Light.ttf',
'Rajdhani-medium':'https://cdn.jsdelivr.net/gh/kurikou02/symbol_game_asset@main/font/Rajdhani/Rajdhani-Medium.ttf',
'Rajdhani':'https://cdn.jsdelivr.net/gh/kurikou02/symbol_game_asset@main/font/Rajdhani/Rajdhani-Regular.ttf',
},
};
// ゲーム設定保持
var SETTINGS = {
mode: 1,
stage: 1,
player_address: '',
bomb_mosaic: 0,
bomb_use_count: 0,
reward_mosaic: 0,
isDemo: false,
isReplay: false,
}
// 単語リストのCSV
var WORDS_LIST_EASY = [];
var WORDS_LIST_HARD = [];
// スコア保持
var clear_time = 0;
var total_score = 0;
var total_miss = 0;
/*
* Symbolクラス
*/
phina.define("MySymbolClass", {
// 初期化
init: function() {
xym = require("/node_modules/symbol-sdk");
const node = 'https://sym-test-01.opening-line.jp:3001';
const repo = new xym.RepositoryFactoryHttp(node,xym.NetworkType.TEST_NET);
const restrictionRepo = repo.createRestrictionAccountRepository();
const transactionHttp = repo.createTransactionRepository();
const accountHttp = repo.createAccountRepository();
const epochAdjustment = 1637848847;
// 送金元送金元プライベートキー(ゲーム用テストアカウントで固定)
const privateKey = '83192D535D0A98001AE352DB2E73534DF653B501BA2BF2F3B07EAB2DF89245CB';
const publicKey = '983FC65B0F29540E77847ADD6AF22C16DE98A2AEFC20F1C7D23867B17CEF3324';
const fromAddress = 'TDEAUFR5ED25QUUGPO7M6SXVSD6OSUEDFPAAL5A';
// デモユーザのアドレス
const demoUserAddress = 'TBS6OAC3ZM66ZVSXNURUQGOYT6AVA4MFXUVS3EI';
// モザイクID
const bombMosaicId = '0A88CF92907753CC';
const rewadMosaicId = '1B5DB759234E38F2';
const xymMosaicId = new xym.MosaicId('46BE9BC0626F9B1A');
const xymDivisibility = 6;
this.xym = xym;
this.accountHttp = accountHttp;
this.transactionHttp = transactionHttp;
this.epochAdjustment = epochAdjustment;
this.privateKey = privateKey;
this.publicKey = publicKey;
this.fromAddress = fromAddress;
this.demoUserAddress = demoUserAddress;
this.bombMosaicId = bombMosaicId;
this.rewadMosaicId = rewadMosaicId;
},
// アドレス取得
getAddress: function(rawAddress){
return this.xym.Address.createFromRawAddress(rawAddress);
},
// 回収可能モザイクの生成
createRevokableMosaic: function() {
console.log('---- createRevokableMosaic -----');
//
// block1
//
const networkType = this.xym.NetworkType.TEST_NET;
const account = this.xym.Account.createFromPrivateKey(this.privateKey, networkType);
// モザイク設定
const isSupplyMutable = true;
const isTransferable = false; // 転送不可にする
const isRestrictable = true;
const isRevokable = true; // 回収可能フラグ
const nonce = this.xym.MosaicNonce.createRandom();
const mosaicDefinitionTransaction = this.xym.MosaicDefinitionTransaction.create(
this.xym.Deadline.create(this.epochAdjustment),
nonce,
this.xym.MosaicId.createFromNonce(nonce, account.address),
this.xym.MosaicFlags.create(isSupplyMutable, isTransferable, isRestrictable, isRevokable),
0, // divisibility(可分性)
this.xym.UInt64.fromUint(500000), // duration(期間)
networkType,
);
//
// block2
//
const delta = 1000;
const mosaicSupplyChangeTransaction = this.xym.MosaicSupplyChangeTransaction.create(
this.xym.Deadline.create(epochAdjustment),
mosaicDefinitionTransaction.mosaicId,
this.xym.MosaicSupplyChangeAction.Increase,
this.xym.UInt64.fromUint(delta * Math.pow(10, 0)),
networkType,
);
//
// block3
//
const aggregateTransaction = this.xym.AggregateTransaction.createComplete(
this.xym.Deadline.create(epochAdjustment),
[
mosaicDefinitionTransaction.toAggregate(account.publicAccount),
mosaicSupplyChangeTransaction.toAggregate(account.publicAccount),
],
networkType,
[],
this.xym.UInt64.fromUint(2000000),
);
// replace with meta.networkGenerationHash (nodeUrl + '/node/info')
const networkGenerationHash =
'7FCCD304802016BEBBCD342A332F91FF1F3BB5E902988B352697BE245F48E836';
const signedTransaction = account.sign(
aggregateTransaction,
networkGenerationHash,
);
// replace with node endpoint
const nodeUrl = 'https://sym-test-06.opening-line.jp:3001';
const repositoryFactory = new this.xym.RepositoryFactoryHttp(nodeUrl, networkType);
const transactionHttp = repositoryFactory.createTransactionRepository();
transactionHttp.announce(signedTransaction).subscribe(
(x) => console.log(x),
(err) => console.error(err),
);
},
// モザイクの回収!
mosaicRevokable: function(targetAddress){
console.log('---- mosaic Revokable -----');
const networkType = this.xym.NetworkType.TEST_NET;
const account = this.xym.Account.createFromPrivateKey(this.privateKey, networkType);
const amount = 1;
const mosaicSupplyRevocationTransaction = this.xym.MosaicSupplyRevocationTransaction.create(
this.xym.Deadline.create(this.epochAdjustment),
this.xym.Address.createFromRawAddress(targetAddress),
new this.xym.Mosaic(new this.xym.MosaicId(this.bombMosaicId), this.xym.UInt64.fromUint(amount)),
networkType,
this.xym.UInt64.fromUint(1000000)
);
const aggregateTransaction = this.xym.AggregateTransaction.createComplete(
this.xym.Deadline.create(this.epochAdjustment),
[
mosaicSupplyRevocationTransaction.toAggregate(account.publicAccount)
],
networkType,
[],
this.xym.UInt64.fromUint(2000000));
// replace with meta.networkGenerationHash (nodeUrl + '/node/info')
const networkGenerationHash =
'7FCCD304802016BEBBCD342A332F91FF1F3BB5E902988B352697BE245F48E836';
const signedTransaction = account.sign(
aggregateTransaction,
networkGenerationHash);
// トランザクション発行
this.announce(signedTransaction);
},
// XYM送金!
sendXym: function( trgetAddress, amount, msg ){
console.log('---- send Xym -----');
// トランザクション作成
const account = this.xym.Account.createFromPrivateKey(this.privateKey, this.xym.NetworkType.TEST_NET);
const transferTransaction = this.xym.TransferTransaction.create(
this.xym.Deadline.create(this.epochAdjustment),
this.xym.Address.createFromRawAddress(trgetAddress),
[new this.xym.Mosaic (new this.xym.MosaicId('3A8416DB2D53B6C8'),this.xym.UInt64.fromUint(amount * Math.pow(10, 6)))],
this.xym.PlainMessage.create(msg),
this.xym.NetworkType.TEST_NET,
this.xym.UInt64.fromUint(100000)
);
// 署名
const networkGenerationHash =
'7FCCD304802016BEBBCD342A332F91FF1F3BB5E902988B352697BE245F48E836';
const signedTransaction = account.sign(
transferTransaction,
networkGenerationHash);
// 発行
this.announce(signedTransaction);
},
// クリア証明トークンと賞金の送付!!
sendClearReward: function( trgetAddress, msg ){
console.log('---- send Xym and ClearReward -----');
// トランザクション作成
const account = this.xym.Account.createFromPrivateKey(this.privateKey, this.xym.NetworkType.TEST_NET);
const transferTransaction = this.xym.TransferTransaction.create(
this.xym.Deadline.create(this.epochAdjustment),
this.xym.Address.createFromRawAddress(trgetAddress),
[
new this.xym.Mosaic (
new this.xym.MosaicId('3A8416DB2D53B6C8'),
this.xym.UInt64.fromUint(10 * Math.pow(10, 6 ))
),
new this.xym.Mosaic (
new this.xym.MosaicId(this.rewadMosaicId),
this.xym.UInt64.fromUint(1)
),
],
this.xym.PlainMessage.create(msg),
this.xym.NetworkType.TEST_NET,
this.xym.UInt64.fromUint(100000)
);
// 署名
const networkGenerationHash =
'7FCCD304802016BEBBCD342A332F91FF1F3BB5E902988B352697BE245F48E836';
const signedTransaction = account.sign(
transferTransaction,
networkGenerationHash);
// 発行
this.announce(signedTransaction);
},
// BOMBモザイク送信!
sendBombMosaic: function( trgetAddress, amount, msg ){
console.log('---- send Bomb Mosaic -----');
// トランザクション作成
const account = this.xym.Account.createFromPrivateKey(this.privateKey, this.xym.NetworkType.TEST_NET);
const transferTransaction = this.xym.TransferTransaction.create(
this.xym.Deadline.create(this.epochAdjustment),
this.xym.Address.createFromRawAddress(trgetAddress),
[new this.xym.Mosaic (new this.xym.MosaicId(this.bombMosaicId),this.xym.UInt64.fromUint(amount))],
this.xym.PlainMessage.create(msg),
this.xym.NetworkType.TEST_NET,
this.xym.UInt64.fromUint(100000)
);
// 署名
const networkGenerationHash =
'7FCCD304802016BEBBCD342A332F91FF1F3BB5E902988B352697BE245F48E836';
const signedTransaction = account.sign(
transferTransaction,
networkGenerationHash);
// 発行
this.announce(signedTransaction);
},
// トランザクションの発行
announce: function( signedTransaction ){
const nodeUrl = 'https://sym-test-06.opening-line.jp:3001';
const repositoryFactory = new this.xym.RepositoryFactoryHttp(nodeUrl, this.xym.NetworkType.TEST_NET);
const transactionHttp = repositoryFactory.createTransactionRepository();
transactionHttp.announce(signedTransaction).subscribe(
(x) => console.log(x),
(err) => console.error(err));
},
});
/*
* タイトルシーン
*/
phina.define('TitleScene', {
superClass: 'DisplayScene',
/**
* @constructor
*/
init: function() {
this.superInit();
// 共通パラメータ初期化
SETTINGS.stage = 1;
SETTINGS.bomb_mosaic = 0;
SETTINGS.bomb_use_count = 0;
total_score = 0;
total_miss = 0;
clear_time = 0;
// symbol クラス生成
var symbol = MySymbolClass();
this.symbol = symbol;
// 背景グループ
var bgGroup = DisplayElement().addChildTo(this);
this.bgGroup = bgGroup;
// 背景画像追加
(2).times(function(i) {
Sprite('title_bg').addChildTo(bgGroup)
.setPosition(this.gridX.center(), this.gridY.center())
.setSize(SCREEN_WIDTH, SCREEN_HEIGHT)
}, this);
// ラベル定義
this.fromJSON({
children: {
// タイトル
titleLabel: {
className: 'Label',
text: 'Symbol Typing Quest',
fontSize: 50,
x: this.gridX.center(),
y: this.gridY.span(2.5),
fontFamily:'Rajdhani-bold',
fill: 'white',
align: 'center',
},
// ゲーム説明
descriptionLabel: {
className: 'Label',
text: 'This is a typing game using the Symbol blockchain.\n' +
'Please type in the address of the testnet.\n' +
'\nDon\'t worry If you don\'t have an Symbol address, \n You can play in trial mode!',
fontSize: 28,
x: this.gridX.center(),
y: this.gridY.span(5),
fontFamily:'Rajdhani',
fill: 'white',
align: 'center',
},
// 入力フォームの説明
inputLabel: {
className: 'Label',
text: 'Please Input Your Symbol Address(Only TestNet)',
fontSize: 24,
x: this.gridX.center(),
y: this.gridY.span(8.2),
fontFamily:'Rajdhani',
fill: 'white',
align: 'center',
},
// ユーザ向けメッセージ
messageLabel: {
className: 'Label',
text: '',
fontSize: 20,
x: this.gridX.center(),
y: this.gridY.span(9.5),
align: 'center',
fontFamily:'Rajdhani',
fill: 'white',
},
},
});
// Symbolアドレス入力フォームセット
this.input = this.createInput(SCREEN_WIDTH*0.6,this.gridX.span(2),this.gridY.span(7), '');
// アドレス読み取りボタン
var GetAddressButton = Button({
width: 80, // 横サイズ
height:40, // 縦サイズ
text: "Go", // 表示文字
fontSize: 24, // 文字サイズ
fontColor: 'white', // 文字色
cornerRadius: 10, // 角丸み
fill: '#170a29', // ボタン色
stroke: '#977bff', // 枠色
strokeWidth: 5, // 枠太さ
}).addChildTo(this).setPosition(this.gridX.span(13.2), this.gridY.span(7.5));
// ノーマルモードプレイボタン
var PlayNomalButton = Button({
width: 400, // 横サイズ
height:60, // 縦サイズ
text: "Normal", // 表示文字
fontSize: 24, // 文字サイズ
fontColor: 'white', // 文字色
cornerRadius: 10, // 角丸み
fill: '#170a29', // ボタン色
stroke: '#a9a9a9', // 枠色
strokeWidth: 5, // 枠太さ
}).addChildTo(this).setPosition(this.gridX.center(), this.gridY.span(11));
//PlayNomalButton.hide(); // 初期状態は非表示
this.PlayNomalButton = PlayNomalButton;
// ハードモードプレイボタン
var PlayHardButton = Button({
width: 400, // 横サイズ
height:60, // 縦サイズ
text: "Hard", // 表示文字
fontSize: 24, // 文字サイズ
fontColor: 'white', // 文字色
cornerRadius: 10, // 角丸み
fill: '#170a29', // ボタン色
stroke: '#a9a9a9', // 枠色
strokeWidth: 5, // 枠太さ
}).addChildTo(this).setPosition(this.gridX.center(), this.gridY.span(12.5));
//PlayHardButton.hide(); // 初期状態は非表示
this.PlayHardButton = PlayHardButton;
// デモプレイボタン
var DemoModeButton = Button({
width: 400, // 横サイズ
height:60, // 縦サイズ
text: "Trial Mode", // 表示文字
fontSize: 24, // 文字サイズ
fontColor: 'white', // 文字色
cornerRadius: 10, // 角丸み
fill: '#170a29', // ボタン色
stroke: '#977bff', // 枠色
strokeWidth: 5, // 枠太さ
}).addChildTo(this).setPosition(this.gridX.center(), this.gridY.span(14));
this.DemoModeButton = DemoModeButton;
// TEST用ボタン
var testButton = Button({
width: 400, // 横サイズ
height:60, // 縦サイズ
text: "TEST", // 表示文字
fontSize: 24, // 文字サイズ
fontColor: 'white', // 文字色
cornerRadius: 10, // 角丸み
fill: 'skyblue', // ボタン色
}).addChildTo(this).setPosition(this.gridX.center(), this.gridY.span(1));
this.testButton = testButton;
this.testButton.hide();
// ワードリスト読み込み
// 汚い書き方だけどグローバル変数で受ける
this.read_csv('https://cdn.jsdelivr.net/gh/kurikou02/symbol_game_asset@main/data/SymbolWords.csv');
// this参照を保持
var self = this;
// リプレイ判定
// リプレイ時はアドレス入力と認証をスキップ
if( SETTINGS.isReplay ){
// リプレイフラグ落とす
SETTINGS.isReplay = false;
// デモモードでリプレイの場合
if( SETTINGS.isDemo ){
//デモ設定反映
SETTINGS.player_address = symbol.demoUserAddress;
}else{
// アドレス情報問い合わせ
address = symbol.getAddress(SETTINGS.player_address);
symbol.accountHttp.getAccountInfo(address).subscribe(
(accountInfo) => {
// 成功時処理
resolv(accountInfo, address, self);
},
(err) => {
console.error(err)
reject(self);
},
);
}
}else{
// 違う場合はプレイヤアドレスもデモフラグも初期化
SETTINGS.player_address = '';
SETTINGS.isDemo = false;
SETTINGS.mode = GAME_MODE.nomal;
}
// ++++++++++++++++++++++++++++
// イベント処理
// ++++++++++++++++++++++++++++
// Symbolアドレスチェック成功時処理
var resolv = this.onSymbolAddressSuccess;
var reject = this.onSymbolAddressError;
// Symbolアドレス取得ボタン押下時
GetAddressButton.onclick = function(){
// 空なら何もしない
if( !self.input.value ){
return;
}
// アドレス情報問い合わせ
address = symbol.getAddress(self.input.value);
symbol.accountHttp.getAccountInfo(address).subscribe(
(accountInfo) => {
// 成功時処理
resolv(accountInfo, address, self);
},
(err) => {
console.error(err)
reject(self);
},
);
}
// ノーマルモードボタン押下時
PlayNomalButton.onclick = function(){
if( !SETTINGS.player_address ) return;
if( SETTINGS.isDemo ) return;
SoundManager.play('system01');
SETTINGS.isDemo = false;
// 難易度難易度ノーマル設定
SETTINGS.mode = GAME_MODE.nomal;
// 入力フォーム削除してゲーム画面へ
self.input.remove();
self.exit();
}
// ハードモードボタン押下時
PlayHardButton.onclick = function(){
if( !SETTINGS.player_address ) return;
if( SETTINGS.isDemo ) return;
SoundManager.play('system01');
SETTINGS.isDemo = false;
// 難易度ハード設定
SETTINGS.mode = GAME_MODE.hard;
// 入力フォーム削除してゲーム画面へ
self.input.remove();
self.exit();
}
// デモモードボタン押下時
DemoModeButton.onclick = function(){
if( SETTINGS.isDemo == false && SETTINGS.player_address ) return;
SoundManager.play('system01');
// 入力フォーム削除
self.input.remove();
//デモ設定反映
SETTINGS.player_address = symbol.demoUserAddress;
SETTINGS.isDemo = true;
self.exit();
}
// テストボタン押下時
testButton.onclick = function(){
//console.log('回収モザイク生成!');
//symbol.createRevokableMosaic();
//console.log('モザイク回収!');
//symbol.mosaicRevokable(symbol.demoUserAddress);
}
// スマホからのアクセスならごめんなさい表示
if( this.isSmartPhone() ){
Swal.fire({
title: 'Sorry!',
text: 'This game is only supported on PC.'
});
}
},
// Symbolアドレス認証成功
onSymbolAddressSuccess: function(accountInfo, address, self){
console.log('get addressInfo resolved');
console.log(accountInfo);
// 初期化
SETTINGS.bomb_mosaic = 0;
SETTINGS.reward_mosaic = 0;
// モザイクチェック
var bomb = 0;
var reward= 0;
for(i = 0 ; i < accountInfo.mosaics.length ; i++){
var id = accountInfo.mosaics[i].id.toHex();
var amount = accountInfo.mosaics[i].amount.compact();
// ボムモザイク
if( id == self.symbol.bombMosaicId ){
console.log('Bomb Mosaic count -> ' + amount );
bomb = amount;
SETTINGS.bomb_mosaic = amount;
break;
}
}
// プレイヤー情報保持
SETTINGS.player_address = accountInfo.address.address;
// ラベル更新
self.messageLabel.text = 'Symbol Address Check OK\n' +
'[ ' + SETTINGS.player_address + ' ]\n' +
'BOMB Mosaic count:' + bomb;
// ボタン更新
self.PlayNomalButton.stroke = '#977bff';
self.PlayHardButton.stroke = '#977bff';
self.DemoModeButton.stroke = '#a9a9a9';
//
SETTINGS.isDemo = false;
},
// Symbolアドレス認証失敗
onSymbolAddressError: function(self){
console.log('アドレスチェックNG!!');
// ラベル表示
self.messageLabel.text = 'Address check failed.\n' +
'Please make sure that the address you entered is correct.';
SETTINGS.player_address = '';
// ボタン更新
self.PlayNomalButton.stroke = '#a9a9a9';
self.PlayHardButton.stroke = '#a9a9a9';
},
// アドレス入力フォーム生成
createInput: function(w, l, t, v){
// DOM操作
let dom = this.baseDom;
// 回答用input要素生成
let input = document.createElement('input');
// input要素にtext属性付与
input.getAttribute('text');
// input要素にtext属性付与
input.getAttribute('value');
// スタイルを設定
let s = input.style;
s.width = `${w}px`;
s.height = '45px';
s.position = 'absolute';
s.margin = '8px';
s.left = l + 'px';
s.top = t + 'px';
s.fontSize = '32px';
s.backgroundColor = 'while';
s.color = 'Gray';
s.border = '2px solid Gray';
dom.appendChild(input);
s.overflowY = 'hidden';
s.value = v;
s.visibility = 'hideen';
// 参照のために返す
return input;
},
// CSV読み込み
read_csv: function(dataPath) {
const request = new XMLHttpRequest(); // HTTPでファイルを読み込む
request.addEventListener('load', (event) => { // ロードさせ実行
const response = event.target.responseText; // 受け取ったテキストを返す
this.set_words_list(response); //csv_arrayの関数を実行
});
request.open('GET', dataPath, true); // csvのパスを指定
request.send();
},
// CSVから単語リストを生成する
set_words_list: function(data) {
const dataString = data.split('\n'); //改行で分割
for (let i = 1; i < dataString.length; i++) { //あるだけループ
values = dataString[i].split(',');
// 難易度フラグに応じて分類
switch (values[2]){
case "0":
WORDS_LIST_EASY.push(values[0]);
WORDS_LIST_HARD.push(values[0]);
break;
case "1":
WORDS_LIST_EASY.push(values[0]);
break;
case "2":
WORDS_LIST_HARD.push(values[0]);
break;
}
}
},
// スマホアクセスの判定
isSmartPhone: function() {
// UserAgentからのスマホ判定
if (navigator.userAgent.match(/iPhone|Android.+Mobile/)) {
return true;
} else {
return false;
}
}
});
/*
* メインシーン01
*/
phina.define("Scene01", {
superClass: 'DisplayScene',
// 初期化
init: function() {
// 親クラス初期化
this.superInit();
// symbol クラス生成
const symbol = MySymbolClass();
this.symbol = symbol;
// 背景グループ
var bgGroup = DisplayElement().addChildTo(this);
this.bgGroup = bgGroup;
// 背景追加
(2).times(function(i) {
Sprite('game_bg').addChildTo(bgGroup)
.setPosition(this.gridX.center(), this.gridY.center())
.setSize(SCREEN_WIDTH, SCREEN_HEIGHT)
}, this);
// ワードラベルの座標
var wordLabel_Y = 14;
// 難易度表記用
var modeLabeltext = ( SETTINGS.mode == GAME_MODE.nomal ) ? 'Mode: Normal' : 'Mode:Hard';
// ラベルとか
this.fromJSON({
children: {
// 入力キーワードラベル
wordLabel:{
className: 'Label',
text: '***',
x: this.gridX.span(8),
y: this.gridX.span(wordLabel_Y),
fontFamily: 'Rajdhani-bold',
fontSize: 60,
fill:'white',
align: 'center',
},
// キーボード入力判定ラベル
inputLabel:{
className: 'Label',
text: '***',
x: this.gridX.span(8),
y: this.gridX.span(wordLabel_Y + 1.5),
fontFamily: 'Rajdhani-medium',
fontSize: 40,
fill:'white',
align: 'center',
},
// スコア
scoreLabel: {
className: 'Label',
text: 'Score:',
x: this.gridX.span(2),
y: this.gridX.span(1),
fontFamily: 'Rajdhani',
align: 'left',
fill:'white',
},
// ミス数
missLabel: {
className: 'Label',
text: 'Miss:',
x: this.gridX.span(7),
y: this.gridX.span(1),
fontFamily: 'Rajdhani',
align: 'left',
fill:'white',
},
// 経過時間
timeLabel: {
className: 'Label',
text: 'Time:' + clear_time,
x: this.gridX.span(12),
y: this.gridX.span(1),
fontFamily: 'Rajdhani',
align: 'left',
fill:'white',
},
// 難易度
modeLabel: {
className: 'Label',
text: modeLabeltext,
x: this.gridX.span(12),
y: this.gridX.span(2),
fontFamily: 'Rajdhani',
fontSize: 24,
align: 'left',
fill:'white',
},
// 今のステージ
stageLabel: {
className: 'Label',
text: 'Stage*',
x: this.gridX.center(),
y: this.gridX.span(2.2),
align: 'center',
fontSize: 32,
fill:'white',
fontFamily: 'Rajdhani',
},
// ボス名
enemyLabel: {
className: 'Label',
text: 'BOSS:',
x: this.gridX.center(),
y: this.gridX.span(3.2),
align: 'center',
fontSize: 48,
fill:'#B429F9',
fontFamily: 'Rajdhani-bold',
},
// Bombモザイク残数
bombMosaicLabel: {
className: 'Label',
text: 'Bomb',
x: this.gridX.span(1.5),
y: this.gridX.span(20),
align: 'left',
fontSize: 24,
fill:'white',
fontFamily: 'Rajdhani-bold',
},
// Bomb説明ラベル
bombDescriptionLabel: {
className: 'Label',
text: '',
x: this.gridX.span(9),
y: this.gridX.span(20),
align: 'left',
fontSize: 18,
fill:'white',
fontFamily: 'Rajdhani',
},
// プレイヤのアドレス
addressLabel: {
className: 'Label',
text: 'PlayerID:' + SETTINGS.player_address,
x: this.gridX.span(1),
y: this.gridX.span(22.5),
align: 'left',
fontSize: 18,
fill:'white',
},
// MISS表示
missTypeLabel: {
className: 'Label',
text: 'MISS!',
x: this.gridX.center(),
y: this.gridX.span(18),
align: 'center',
fontSize: 48,
fill:'#B429F9',
fontFamily: 'Rajdhani-bold',
alpha: 0,
},
},
});
// UIのレイヤ分け
this.gameLayer = DisplayElement().addChildTo(this);
this.enemyGroup = DisplayElement().addChildTo(this);
this.uiLayer = DisplayElement().addChildTo(this);
this.bombLayer = DisplayElement().addChildTo(this);
//
// UI関係ラベル
//
// スコア
this.score = 0;
this.scoreLabel.text = 'score:' + this.score;
this.scoreLabel.addChildTo(this.uiLayer);