Commit 912c2a58 authored by 范雪寒's avatar 范雪寒

fix: bugs

parent 3acf5050
No preview for this file type
{
"ver": "2.0.1",
"uuid": "64769aad-08a2-4b33-8fbb-6a6ba01f53f2",
"downloadMode": 0,
"duration": 3.474286,
"subMetas": {}
}
\ No newline at end of file
......@@ -40,19 +40,22 @@
},
{
"__id__": 34
},
{
"__id__": 54
}
],
"_active": true,
"_components": [
{
"__id__": 54
"__id__": 59
},
{
"__id__": 55
"__id__": 60
}
],
"_prefab": {
"__id__": 56
"__id__": 61
},
"_opacity": 255,
"_color": {
......@@ -1959,6 +1962,175 @@
"fileId": "f9qrJyDh5P1oErn3FfsNL7",
"sync": false
},
{
"__type__": "cc.Node",
"_name": "res",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_children": [
{
"__id__": 55
}
],
"_active": true,
"_components": [],
"_prefab": {
"__id__": 58
},
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 0,
"height": 0
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0,
0,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": ""
},
{
"__type__": "cc.Node",
"_name": "match",
"_objFlags": 0,
"_parent": {
"__id__": 54
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 56
}
],
"_prefab": {
"__id__": 57
},
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 0,
"height": 0
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0,
0,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": ""
},
{
"__type__": "cc.AudioSource",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 55
},
"_enabled": true,
"_clip": {
"__uuid__": "64769aad-08a2-4b33-8fbb-6a6ba01f53f2"
},
"_volume": 1,
"_mute": false,
"_loop": false,
"_firstlyEnabled": true,
"playOnLoad": false,
"preload": false,
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__uuid__": "4839576b-7c74-49ab-aa3e-8eeec631d7c0"
},
"fileId": "24pM39t0xAcpeV3Rbf7iK5",
"sync": false
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__uuid__": "4839576b-7c74-49ab-aa3e-8eeec631d7c0"
},
"fileId": "28B+az6rRACpZT/KUohVaz",
"sync": false
},
{
"__type__": "cc.Widget",
"_name": "",
......
......@@ -17,7 +17,10 @@
"__id__": 2
},
{
"__id__": 168
"__id__": 172
},
{
"__id__": 185
}
],
"_active": false,
......@@ -81,19 +84,19 @@
"__id__": 7
},
{
"__id__": 151
"__id__": 154
}
],
"_active": true,
"_components": [
{
"__id__": 165
"__id__": 169
},
{
"__id__": 166
"__id__": 170
},
{
"__id__": 167
"__id__": 171
}
],
"_prefab": null,
......@@ -354,19 +357,22 @@
"__id__": 112
},
{
"__id__": 126
"__id__": 127
},
{
"__id__": 141
"__id__": 142
},
{
"__id__": 148
"__id__": 149
},
{
"__id__": 151
}
],
"_active": true,
"_components": [
{
"__id__": 150
"__id__": 153
}
],
"_prefab": null,
......@@ -4725,10 +4731,10 @@
"__id__": 121
},
{
"__id__": 122
"__id__": 123
},
{
"__id__": 124
"__id__": 125
}
],
"_active": true,
......@@ -5162,7 +5168,11 @@
},
"_children": [],
"_active": true,
"_components": [],
"_components": [
{
"__id__": 122
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
......@@ -5211,6 +5221,38 @@
"groupIndex": 0,
"_id": "0bfyX/nTdPJIpfRKUryv4/"
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 121
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_spriteFrame": {
"__uuid__": "961b4c40-b93f-4af5-af66-e3683eb2b5b6"
},
"_type": 0,
"_sizeMode": 1,
"_fillType": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_atlas": null,
"_id": "06teYaEQRIa5GjLPZjiTIu"
},
{
"__type__": "cc.Node",
"_name": "faceBlue",
......@@ -5222,7 +5264,7 @@
"_active": true,
"_components": [
{
"__id__": 123
"__id__": 124
}
],
"_prefab": null,
......@@ -5278,7 +5320,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 122
"__id__": 123
},
"_enabled": true,
"_materials": [
......@@ -5316,7 +5358,7 @@
"_active": false,
"_components": [
{
"__id__": 125
"__id__": 126
}
],
"_prefab": null,
......@@ -5372,7 +5414,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 124
"__id__": 125
},
"_enabled": true,
"_materials": [
......@@ -5416,19 +5458,19 @@
},
"_children": [
{
"__id__": 127
"__id__": 128
},
{
"__id__": 133
"__id__": 134
},
{
"__id__": 135
"__id__": 136
},
{
"__id__": 137
"__id__": 138
},
{
"__id__": 139
"__id__": 140
}
],
"_active": true,
......@@ -5486,17 +5528,17 @@
"_name": "life_red",
"_objFlags": 0,
"_parent": {
"__id__": 126
"__id__": 127
},
"_children": [
{
"__id__": 128
"__id__": 129
}
],
"_active": true,
"_components": [
{
"__id__": 132
"__id__": 133
}
],
"_prefab": null,
......@@ -5552,17 +5594,17 @@
"_name": "mask",
"_objFlags": 0,
"_parent": {
"__id__": 127
"__id__": 128
},
"_children": [
{
"__id__": 129
"__id__": 130
}
],
"_active": true,
"_components": [
{
"__id__": 131
"__id__": 132
}
],
"_prefab": null,
......@@ -5618,13 +5660,13 @@
"_name": "prograssbar",
"_objFlags": 0,
"_parent": {
"__id__": 128
"__id__": 129
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 130
"__id__": 131
}
],
"_prefab": null,
......@@ -5680,7 +5722,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 129
"__id__": 130
},
"_enabled": true,
"_materials": [
......@@ -5712,7 +5754,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 128
"__id__": 129
},
"_enabled": true,
"_materials": [
......@@ -5732,7 +5774,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 127
"__id__": 128
},
"_enabled": true,
"_materials": [
......@@ -5764,13 +5806,13 @@
"_name": "dice_bg",
"_objFlags": 0,
"_parent": {
"__id__": 126
"__id__": 127
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 134
"__id__": 135
}
],
"_prefab": null,
......@@ -5826,7 +5868,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 133
"__id__": 134
},
"_enabled": true,
"_materials": [
......@@ -5858,13 +5900,13 @@
"_name": "faceFrame",
"_objFlags": 0,
"_parent": {
"__id__": 126
"__id__": 127
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 136
"__id__": 137
}
],
"_prefab": null,
......@@ -5920,7 +5962,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 135
"__id__": 136
},
"_enabled": true,
"_materials": [
......@@ -5952,13 +5994,13 @@
"_name": "faceRed",
"_objFlags": 0,
"_parent": {
"__id__": 126
"__id__": 127
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 138
"__id__": 139
}
],
"_prefab": null,
......@@ -6014,7 +6056,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 137
"__id__": 138
},
"_enabled": true,
"_materials": [
......@@ -6046,13 +6088,13 @@
"_name": "effect",
"_objFlags": 0,
"_parent": {
"__id__": 126
"__id__": 127
},
"_children": [],
"_active": false,
"_components": [
{
"__id__": 140
"__id__": 141
}
],
"_prefab": null,
......@@ -6108,7 +6150,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 139
"__id__": 140
},
"_enabled": true,
"_materials": [
......@@ -6152,13 +6194,13 @@
},
"_children": [
{
"__id__": 142
"__id__": 143
}
],
"_active": false,
"_components": [
{
"__id__": 147
"__id__": 148
}
],
"_prefab": null,
......@@ -6214,20 +6256,20 @@
"_name": "Background",
"_objFlags": 512,
"_parent": {
"__id__": 141
"__id__": 142
},
"_children": [
{
"__id__": 143
"__id__": 144
}
],
"_active": true,
"_components": [
{
"__id__": 145
"__id__": 146
},
{
"__id__": 146
"__id__": 147
}
],
"_prefab": null,
......@@ -6283,13 +6325,13 @@
"_name": "Label",
"_objFlags": 512,
"_parent": {
"__id__": 142
"__id__": 143
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 144
"__id__": 145
}
],
"_prefab": null,
......@@ -6345,7 +6387,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 143
"__id__": 144
},
"_enabled": true,
"_materials": [
......@@ -6378,7 +6420,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 142
"__id__": 143
},
"_enabled": true,
"_materials": [
......@@ -6410,7 +6452,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 142
"__id__": 143
},
"_enabled": true,
"alignMode": 0,
......@@ -6437,7 +6479,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 141
"__id__": 142
},
"_enabled": true,
"_normalMaterial": null,
......@@ -6510,7 +6552,7 @@
"__uuid__": "29158224-f8dd-4661-a796-1ffab537140e"
},
"_N$target": {
"__id__": 142
"__id__": 143
},
"_id": "72uh6FFMhPZJXe9I3tJ4Qt"
},
......@@ -6525,7 +6567,7 @@
"_active": true,
"_components": [
{
"__id__": 149
"__id__": 150
}
],
"_prefab": null,
......@@ -6581,7 +6623,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 148
"__id__": 149
},
"_enabled": true,
"alignMode": 2,
......@@ -6603,6 +6645,100 @@
"_originalHeight": 0,
"_id": "9fr0grwX5J57n69Cqpwnin"
},
{
"__type__": "cc.Node",
"_name": "yourturn",
"_objFlags": 0,
"_parent": {
"__id__": 7
},
"_children": [],
"_active": false,
"_components": [
{
"__id__": 152
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 584,
"height": 235
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0,
0,
0,
0,
0,
0,
1,
2,
2,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": "beNbXPSUZO3JERirbadq6E"
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 151
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_spriteFrame": {
"__uuid__": "eeb8a1d1-4858-4241-8733-38b1cff4c7cf"
},
"_type": 0,
"_sizeMode": 1,
"_fillType": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_atlas": null,
"_id": "fc8448+HZJqqhlGZue2Lzm"
},
{
"__type__": "cc.Widget",
"_name": "",
......@@ -6639,13 +6775,19 @@
},
"_children": [
{
"__id__": 152
"__id__": 155
},
{
"__id__": 158
}
],
"_active": true,
"_active": false,
"_components": [
{
"__id__": 164
"__id__": 167
},
{
"__id__": 168
}
],
"_prefab": null,
......@@ -6701,20 +6843,16 @@
"_name": "bg",
"_objFlags": 0,
"_parent": {
"__id__": 151
"__id__": 154
},
"_children": [
{
"__id__": 153
}
],
"_children": [],
"_active": true,
"_components": [
{
"__id__": 162
"__id__": 156
},
{
"__id__": 163
"__id__": 157
}
],
"_prefab": null,
......@@ -6766,27 +6904,86 @@
"_id": "9cjbtB0sNCsLMdza0zrJ8B"
},
{
"__type__": "cc.Node",
"_name": "bg",
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"_parent": {
"__id__": 152
"node": {
"__id__": 155
},
"_children": [
"_enabled": true,
"_materials": [
{
"__id__": 154
},
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_spriteFrame": {
"__uuid__": "a23235d1-15db-4b95-8439-a2e005bfff91"
},
"_type": 0,
"_sizeMode": 0,
"_fillType": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_atlas": null,
"_id": "60jQo7aKpO+755Gs2kdTZQ"
},
{
"__type__": "cc.Widget",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 155
},
"_enabled": true,
"alignMode": 2,
"_target": null,
"_alignFlags": 45,
"_left": 0,
"_right": 0,
"_top": 0,
"_bottom": 0,
"_verticalCenter": 0,
"_horizontalCenter": 0,
"_isAbsLeft": true,
"_isAbsRight": true,
"_isAbsTop": true,
"_isAbsBottom": true,
"_isAbsHorizontalCenter": true,
"_isAbsVerticalCenter": true,
"_originalWidth": 100,
"_originalHeight": 100,
"_id": "3c8tUAlc9PQoBjysSDbTCd"
},
{
"__type__": "cc.Node",
"_name": "labelBg",
"_objFlags": 0,
"_parent": {
"__id__": 154
},
"_children": [
{
"__id__": 157
"__id__": 159
},
{
"__id__": 162
}
],
"_active": true,
"_components": [
{
"__id__": 160
"__id__": 165
},
{
"__id__": 161
"__id__": 166
}
],
"_prefab": null,
......@@ -6842,16 +7039,16 @@
"_name": "labelLoss",
"_objFlags": 0,
"_parent": {
"__id__": 153
"__id__": 158
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 155
"__id__": 160
},
{
"__id__": 156
"__id__": 161
}
],
"_prefab": null,
......@@ -6907,7 +7104,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 154
"__id__": 159
},
"_enabled": true,
"_materials": [
......@@ -6939,7 +7136,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 154
"__id__": 159
},
"_enabled": true,
"alignMode": 1,
......@@ -6966,16 +7163,16 @@
"_name": "labelWin",
"_objFlags": 0,
"_parent": {
"__id__": 153
"__id__": 158
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 158
"__id__": 163
},
{
"__id__": 159
"__id__": 164
}
],
"_prefab": null,
......@@ -7031,7 +7228,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 157
"__id__": 162
},
"_enabled": true,
"_materials": [
......@@ -7063,7 +7260,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 157
"__id__": 162
},
"_enabled": true,
"alignMode": 1,
......@@ -7090,7 +7287,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 153
"__id__": 158
},
"_enabled": true,
"_materials": [
......@@ -7122,7 +7319,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 153
"__id__": 158
},
"_enabled": true,
"alignMode": 2,
......@@ -7144,44 +7341,12 @@
"_originalHeight": 0,
"_id": "e8w4Lw+2VNObnuwPQ1d2O8"
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 152
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_spriteFrame": {
"__uuid__": "a23235d1-15db-4b95-8439-a2e005bfff91"
},
"_type": 0,
"_sizeMode": 0,
"_fillType": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_atlas": null,
"_id": "60jQo7aKpO+755Gs2kdTZQ"
},
{
"__type__": "cc.Widget",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 152
"__id__": 154
},
"_enabled": true,
"alignMode": 2,
......@@ -7199,36 +7364,77 @@
"_isAbsBottom": true,
"_isAbsHorizontalCenter": true,
"_isAbsVerticalCenter": true,
"_originalWidth": 100,
"_originalHeight": 100,
"_id": "3c8tUAlc9PQoBjysSDbTCd"
"_originalWidth": 0,
"_originalHeight": 0,
"_id": "38i+Ag8ZBHWY+hWxjSeIa4"
},
{
"__type__": "cc.Widget",
"__type__": "cc.Button",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 151
"__id__": 154
},
"_enabled": true,
"alignMode": 2,
"_target": null,
"_alignFlags": 45,
"_left": 0,
"_right": 0,
"_top": 0,
"_bottom": 0,
"_verticalCenter": 0,
"_horizontalCenter": 0,
"_isAbsLeft": true,
"_isAbsRight": true,
"_isAbsTop": true,
"_isAbsBottom": true,
"_isAbsHorizontalCenter": true,
"_isAbsVerticalCenter": true,
"_originalWidth": 0,
"_originalHeight": 0,
"_id": "38i+Ag8ZBHWY+hWxjSeIa4"
"_normalMaterial": null,
"_grayMaterial": null,
"duration": 0.1,
"zoomScale": 1.2,
"clickEvents": [],
"_N$interactable": true,
"_N$enableAutoGrayEffect": false,
"_N$transition": 0,
"transition": 0,
"_N$normalColor": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_N$pressedColor": {
"__type__": "cc.Color",
"r": 211,
"g": 211,
"b": 211,
"a": 255
},
"pressedColor": {
"__type__": "cc.Color",
"r": 211,
"g": 211,
"b": 211,
"a": 255
},
"_N$hoverColor": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"hoverColor": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_N$disabledColor": {
"__type__": "cc.Color",
"r": 124,
"g": 124,
"b": 124,
"a": 255
},
"_N$normalSprite": null,
"_N$pressedSprite": null,
"pressedSprite": null,
"_N$hoverSprite": null,
"hoverSprite": null,
"_N$disabledSprite": null,
"_N$target": null,
"_id": "9bSBBJ8ORHaKrvJv70h0XL"
},
{
"__type__": "cc.Canvas",
......@@ -7295,12 +7501,6 @@
"__id__": 1
},
"_children": [
{
"__id__": 169
},
{
"__id__": 171
},
{
"__id__": 173
},
......@@ -7312,6 +7512,12 @@
},
{
"__id__": 179
},
{
"__id__": 181
},
{
"__id__": 183
}
],
"_active": true,
......@@ -7369,13 +7575,13 @@
"_name": "落子",
"_objFlags": 0,
"_parent": {
"__id__": 168
"__id__": 172
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 170
"__id__": 174
}
],
"_prefab": null,
......@@ -7431,7 +7637,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 169
"__id__": 173
},
"_enabled": true,
"_clip": {
......@@ -7450,13 +7656,13 @@
"_name": "正确",
"_objFlags": 0,
"_parent": {
"__id__": 168
"__id__": 172
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 172
"__id__": 176
}
],
"_prefab": null,
......@@ -7512,7 +7718,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 171
"__id__": 175
},
"_enabled": true,
"_clip": {
......@@ -7531,13 +7737,13 @@
"_name": "失败",
"_objFlags": 0,
"_parent": {
"__id__": 168
"__id__": 172
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 174
"__id__": 178
}
],
"_prefab": null,
......@@ -7593,7 +7799,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 173
"__id__": 177
},
"_enabled": true,
"_clip": {
......@@ -7612,13 +7818,13 @@
"_name": "错误弹回",
"_objFlags": 0,
"_parent": {
"__id__": 168
"__id__": 172
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 176
"__id__": 180
}
],
"_prefab": null,
......@@ -7674,7 +7880,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 175
"__id__": 179
},
"_enabled": true,
"_clip": {
......@@ -7693,13 +7899,13 @@
"_name": "进度条升高",
"_objFlags": 0,
"_parent": {
"__id__": 168
"__id__": 172
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 178
"__id__": 182
}
],
"_prefab": null,
......@@ -7755,7 +7961,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 177
"__id__": 181
},
"_enabled": true,
"_clip": {
......@@ -7774,13 +7980,13 @@
"_name": "胜利",
"_objFlags": 0,
"_parent": {
"__id__": 168
"__id__": 172
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 180
"__id__": 184
}
],
"_prefab": null,
......@@ -7836,7 +8042,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 179
"__id__": 183
},
"_enabled": true,
"_clip": {
......@@ -7849,5 +8055,258 @@
"playOnLoad": false,
"preload": false,
"_id": "dbccc2jl1Lw6v0V1Jts0W8"
},
{
"__type__": "cc.Node",
"_name": "nodes",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_children": [
{
"__id__": 186
},
{
"__id__": 188
}
],
"_active": true,
"_components": [],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 0,
"height": 0
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
-327.507,
-307.694,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": "6c/o2REGNNmIqMKaQvJKah"
},
{
"__type__": "cc.Node",
"_name": "light",
"_objFlags": 0,
"_parent": {
"__id__": 185
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 187
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 95,
"height": 95
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
-170.747,
-97.32,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": "b5/gThiGlNm4NZRYBzwYQo"
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 186
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_spriteFrame": {
"__uuid__": "003d9202-6c8b-4161-9866-fd33e95c843c"
},
"_type": 0,
"_sizeMode": 1,
"_fillType": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_atlas": null,
"_id": "1axoRCh9RDnqm//Vc+f2nn"
},
{
"__type__": "cc.Node",
"_name": "star",
"_objFlags": 0,
"_parent": {
"__id__": 185
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 189
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 174,
"height": 169
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
159.674,
-89.744,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": "0fWbpUGHlF0rvwnhw2gGl9"
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 188
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_spriteFrame": {
"__uuid__": "1f2bd6e5-dfe4-4b37-a62b-c9031bc01d99"
},
"_type": 0,
"_sizeMode": 1,
"_fillType": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_atlas": null,
"_id": "3evuefar1Ko6Mg4PWqq/28"
}
]
\ No newline at end of file
import { asyncDelay, asyncPlayDragonBoneAnimation, asyncTweenTo, onHomeworkFinish, RandomInt } from "../script/util";
import {
asyncDelay,
asyncPlayDragonBoneAnimation,
asyncTweenTo,
onHomeworkFinish,
RandomInt,
} from "../script/util";
import { MyCocosSceneComponent } from "../script/MyCocosSceneComponent";
import { NetworkHelper } from "../script/NetworkHelper";
import { GameServer } from "../script/Server";
......@@ -7,671 +13,865 @@ const { ccclass, property } = cc._decorator;
@ccclass
export default class SceneComponent extends MyCocosSceneComponent {
@property(cc.Prefab)
loadingLayerPrefab = null;
addPreloadImage() {
// TODO 根据自己的配置预加载图片资源
// this._imageResList.push({ url: this.data.pic_url });
}
addPreloadAudio() {
// TODO 根据自己的配置预加载音频资源
this._audioResList.push({ url: this.data.gameStartAudio });
this._audioResList.push({ url: this.data.gameLoadingAudio });
this._audioResList.push({ url: this.data.waitingWheel });
this._audioResList.push({ url: this.data.waitingPiece });
this._audioResList.push({ url: this.data.waitingTurn });
}
addPreloadAnima() {
}
onLoadEnd() {
// TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考
this.initData();
this.initView();
this.initListener();
}
_status = {
Red: 0,
Blue: 0,
letter: '',
current: 'Blue'
};
playerId;
isRoomOwner;
server: GameServer;
networkHelper: NetworkHelper;
async initData() {
this.networkHelper = new NetworkHelper();
this.initNetworkListener();
this.playerId = await this.networkHelper.init('op_16', 2);
const room = this.networkHelper.room;
if (this.playerId == room.roomInfo.owner) {
console.log('房主');
this.isRoomOwner = true;
this.server = new GameServer(2, this.networkHelper);
await this.networkHelper.startFrameSync();
this.server.addPlayer({
uuid: this.playerId,
isAI: false
});
this.server.startMatch();
}
}
initView() {
this.initBg();
this.initLoadingLayer();
this.initPiece();
}
initBg() {
const canvas = cc.find('Canvas');
const bgImg = cc.find('Canvas/bgImg');
bgImg.scale = Math.max(canvas.width / bgImg.width, canvas.height / bgImg.height);
const bg = cc.find('Canvas/bg');
bg.scale = Math.min(canvas.width / bg.width, canvas.height / bg.height);
const chessBoardBg = cc.find('Canvas/bg/chessBoard/bg');
const offsetX = chessBoardBg.width * chessBoardBg.scaleX / 2 + (canvas.width - chessBoardBg.width * chessBoardBg.scaleX) / 4;
const lifeblue = cc.find('Canvas/bg/Lifeblue');
lifeblue.x = -offsetX;
const lifered = cc.find('Canvas/bg/Lifered');
lifered.x = offsetX;
}
loadingLayer;
initLoadingLayer() {
const loadingLayerBase = cc.find('Canvas/bg/loadingLayerBase');
const loadingLayerNode = cc.instantiate(this.loadingLayerPrefab);
loadingLayerBase.addChild(loadingLayerNode);
this.loadingLayer = loadingLayerNode.getComponent('LoadingLayer');
this.loadingLayer.setMaxPlayerNumber(2);
this.loadingLayer.onLoadFinished(() => {
this.playAudioByUrl(this.data.gameStartAudio);
});
this.playAudioByUrl(this.data.gameLoadingAudio);
}
blinkTheDice() {
const dice = cc.find('Canvas/bg/chessBoard/diceBg/hatBlink');
cc.tween(dice)
.set({ opacity: 0 })
.to(0.3, { opacity: 255 })
.to(0.3, { opacity: 0 })
.union()
.repeatForever()
.start();
}
stopBlinkTheDice() {
const dice = cc.find('Canvas/bg/chessBoard/diceBg/hatBlink');
dice.stopAllActions();
}
greyDice() {
const dice = cc.find('Canvas/bg/chessBoard/diceBg/dice');
dice.color = cc.color(150, 150, 150);
}
stopGreyDice() {
const dice = cc.find('Canvas/bg/chessBoard/diceBg/dice');
dice.color = cc.color(255, 255, 255);
}
initPiece() {
const offsetX = { Red: -45, Blue: 45 };
const offsetY = { Red: -90, Blue: -90 };
const board = cc.find('Canvas/bg/chessBoard/boardItems');
const pieceNodeRed = cc.find(`Canvas/bg/chessBoard/pieceRed`)
const startIdxRed = this._status['Red'];
const boardNodeRed = board.children[startIdxRed];
pieceNodeRed.x = boardNodeRed.x + offsetX.Red;
pieceNodeRed.y = boardNodeRed.y + offsetY.Red;
const pieceNodeBlue = cc.find(`Canvas/bg/chessBoard/pieceBlue`)
const startIdxBlue = this._status['Blue'];
const boardNodeBlue = board.children[startIdxBlue];
pieceNodeBlue.x = boardNodeBlue.x + offsetX.Blue;
pieceNodeBlue.y = boardNodeBlue.y + offsetY.Blue;
}
initListener() {
const btn = cc.find('Canvas/bg/New Button');
btn.on('click', async () => {
const idx = RandomInt(6);
await this.rollTheDice(idx);
this._status.letter = ['A', 'B', 'C', 'D', 'E', 'F'][idx];
});
const dice = cc.find('Canvas/bg/chessBoard/diceBg/dice');
dice.on('click', () => {
if (this._status.letter != '') {
return;
}
const playerMe = this.allPlayerList.find(player => player.uuid == this.playerId);
if (this._status.current == playerMe.color) {
this.networkHelper.sendFrame({
type: 'roll',
uuid: playerMe.uuid
});
}
});
const pieceBlue = cc.find('Canvas/bg/chessBoard/pieceBlue');
this.addPieceTouchEventListener(pieceBlue, 'Blue');
const pieceRed = cc.find('Canvas/bg/chessBoard/pieceRed');
this.addPieceTouchEventListener(pieceRed, 'Red');
const coolCat = cc.find('Canvas/bg/tree/catBase/cat');
const catBtn = cc.find('Canvas/bg/tree/catBase/catBtn');
catBtn.on('click', async () => {
asyncPlayDragonBoneAnimation(coolCat, 'begin');
const playerMe = this.allPlayerList.find(player => player.uuid == this.playerId);
if (playerMe.color == this._status.current) {
if (this._status.letter == '') {
await this.playAudioByUrl(this.data.waitingWheel);
} else {
await this.playAudioByUrl(this.data.waitingPiece);
}
} else {
await this.playAudioByUrl(this.data.waitingTurn);
}
asyncPlayDragonBoneAnimation(coolCat, 'normal');
});
}
addPieceTouchEventListener(node: cc.Node, color) {
node.on(cc.Node.EventType.TOUCH_START, (event: cc.Event.EventTouch) => {
const playerMe = this.allPlayerList.find(player => player.uuid == this.playerId);
if (playerMe.color != this._status.current) {
this.blinkPiece(node);
return;
}
if (this._status.current != color) {
this.blinkPiece(node);
return;
}
if (this._status.letter == '') {
this.blinkPiece(node);
return;
}
if (node['cantMove']) {
return;
}
this.stopRollPiece(node);
node['touchStartPos'] = {
nodeX: node.x,
nodeY: node.y,
touchX: event.getLocation().x,
touchY: event.getLocation().y
};
@property(cc.Prefab)
loadingLayerPrefab = null;
addPreloadImage() {
// TODO 根据自己的配置预加载图片资源
// this._imageResList.push({ url: this.data.pic_url });
}
addPreloadAudio() {
// TODO 根据自己的配置预加载音频资源
this._audioResList.push({ url: this.data.gameStartAudio });
this._audioResList.push({ url: this.data.gameLoadingAudio });
this._audioResList.push({ url: this.data.waitingWheel });
this._audioResList.push({ url: this.data.waitingPiece });
this._audioResList.push({ url: this.data.waitingTurn });
}
addPreloadAnima() {}
onLoadEnd() {
// TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考
this.initData();
this.initView();
this.initListener();
}
_status = {
Red: 0,
Blue: 0,
letter: "",
current: "Blue",
};
playerId;
isRoomOwner;
server: GameServer;
networkHelper: NetworkHelper;
async initData() {
this.networkHelper = new NetworkHelper();
this.initNetworkListener();
do {
this.playerId = await this.networkHelper.init("op_16", 2);
if (this.playerId === null) {
console.log("onDestroy");
this.networkHelper.onDestroy();
}
console.log("this.playerId = " + this.playerId);
} while (this.playerId === null);
const room = this.networkHelper.room;
if (this.playerId == room.roomInfo.owner) {
console.log("房主");
this.isRoomOwner = true;
this.server = new GameServer(2, this.networkHelper);
await this.networkHelper.startFrameSync();
this.server.addPlayer({
uuid: this.playerId,
isAI: false,
});
this.server.startMatch();
}
}
initView() {
this.initBg();
this.initLoadingLayer();
this.initPiece();
}
initBg() {
const canvas = cc.find("Canvas");
const bgImg = cc.find("Canvas/bgImg");
bgImg.scale = Math.max(
canvas.width / bgImg.width,
canvas.height / bgImg.height
);
const bg = cc.find("Canvas/bg");
bg.scale = Math.min(canvas.width / bg.width, canvas.height / bg.height);
const chessBoardBg = cc.find("Canvas/bg/chessBoard/bg");
const offsetX =
(chessBoardBg.width * chessBoardBg.scaleX) / 2 +
(canvas.width - chessBoardBg.width * chessBoardBg.scaleX) / 4;
const lifeblue = cc.find("Canvas/bg/Lifeblue");
lifeblue.x = -offsetX;
const lifered = cc.find("Canvas/bg/Lifered");
lifered.x = offsetX;
}
loadingLayer;
initLoadingLayer() {
const loadingLayerBase = cc.find("Canvas/bg/loadingLayerBase");
const loadingLayerNode = cc.instantiate(this.loadingLayerPrefab);
loadingLayerBase.addChild(loadingLayerNode);
this.loadingLayer = loadingLayerNode.getComponent("LoadingLayer");
this.loadingLayer.setMaxPlayerNumber(2);
this.loadingLayer.onLoadFinished(() => {
this.playAudioByUrl(this.data.gameStartAudio);
});
this.playAudioByUrl(this.data.gameLoadingAudio);
}
blinkTheDice() {
const dice = cc.find("Canvas/bg/chessBoard/diceBg/hatBlink");
cc.tween(dice)
.set({ opacity: 0 })
.to(0.2, { opacity: 255 })
.to(0.2, { opacity: 0 })
.union()
.repeatForever()
.start();
cc.find("Canvas/bg/chessBoard/diceBg").children.forEach((node) => {
cc.tween(node)
.set({ scale: 1 })
.to(0.2, { scale: 1.1 })
.to(0.2, { scale: 1.0 })
.union()
.repeatForever()
.start();
});
const dice = cc.find("Canvas/bg/chessBoard/diceBg/dice");
dice["canClick"] = true;
}
stopBlinkTheDice() {
const dice = cc.find("Canvas/bg/chessBoard/diceBg/hatBlink");
dice.stopAllActions();
cc.find("Canvas/bg/chessBoard/diceBg").children.forEach((node) => {
node.stopAllActions();
node.scale = 1;
node.opacity = 255;
});
const dice = cc.find("Canvas/bg/chessBoard/diceBg/dice");
dice["canClick"] = false;
}
greyDice() {
cc.find("Canvas/bg/chessBoard/diceBg").children.forEach((node) => {
node.color = cc.color(150, 150, 150);
});
}
stopGreyDice() {
cc.find("Canvas/bg/chessBoard/diceBg").children.forEach((node) => {
node.color = cc.color(255, 255, 255);
});
}
initPiece() {
const offsetX = { Red: -45, Blue: 45 };
const offsetY = { Red: -90, Blue: -90 };
const board = cc.find("Canvas/bg/chessBoard/boardItems");
const pieceNodeRed = cc.find(`Canvas/bg/chessBoard/pieceRed`);
const startIdxRed = this._status["Red"];
const boardNodeRed = board.children[startIdxRed];
pieceNodeRed.x = boardNodeRed.x + offsetX.Red;
pieceNodeRed.y = boardNodeRed.y + offsetY.Red;
const pieceNodeBlue = cc.find(`Canvas/bg/chessBoard/pieceBlue`);
const startIdxBlue = this._status["Blue"];
const boardNodeBlue = board.children[startIdxBlue];
pieceNodeBlue.x = boardNodeBlue.x + offsetX.Blue;
pieceNodeBlue.y = boardNodeBlue.y + offsetY.Blue;
}
initListener() {
const btn = cc.find("Canvas/bg/New Button");
btn.on("click", async () => {
const idx = RandomInt(6);
await this.rollTheDice(idx);
console.log("汪汪汪 194");
this._status.letter = ["A", "B", "C", "D", "E", "F"][idx];
});
const dice = cc.find("Canvas/bg/chessBoard/diceBg/dice");
dice.on("click", () => {
if (this._status.letter != "") {
return;
}
if (!dice["canClick"]) {
return;
}
const playerMe = this.allPlayerList.find(
(player) => player.uuid == this.playerId
);
if (this._status.current == playerMe.color) {
this.networkHelper.sendFrame({
type: "roll",
uuid: playerMe.uuid,
});
node.on(cc.Node.EventType.TOUCH_MOVE, (event: cc.Event.EventTouch) => {
const playerMe = this.allPlayerList.find(player => player.uuid == this.playerId);
if (playerMe.color != this._status.current) {
return;
}
if (this._status.current != color) {
return;
}
if (this._status.letter == '') {
return;
}
if (node['cantMove']) {
return;
}
const pos = event.getLocation();
const touchStartPos = node['touchStartPos'];
const worldNodePos = node.parent.convertToWorldSpaceAR(cc.v2(touchStartPos.nodeX, touchStartPos.nodeY));
const nodePos = node.parent.convertToNodeSpaceAR(cc.v2(
worldNodePos.x + pos.x - touchStartPos.touchX,
worldNodePos.y + pos.y - touchStartPos.touchY,
))
node.setPosition(nodePos);
}
});
const pieceBlue = cc.find("Canvas/bg/chessBoard/pieceBlue");
this.addPieceTouchEventListener(pieceBlue, "Blue");
const pieceRed = cc.find("Canvas/bg/chessBoard/pieceRed");
this.addPieceTouchEventListener(pieceRed, "Red");
const coolCat = cc.find("Canvas/bg/tree/catBase/cat");
const catBtn = cc.find("Canvas/bg/tree/catBase/catBtn");
catBtn.on("click", async () => {
asyncPlayDragonBoneAnimation(coolCat, "begin");
const playerMe = this.allPlayerList.find(
(player) => player.uuid == this.playerId
);
if (playerMe.color == this._status.current) {
if (this._status.letter == "") {
await this.playAudioByUrl(this.data.waitingWheel);
} else {
await this.playAudioByUrl(this.data.waitingPiece);
}
} else {
await this.playAudioByUrl(this.data.waitingTurn);
}
asyncPlayDragonBoneAnimation(coolCat, "normal");
});
}
addPieceTouchEventListener(node: cc.Node, color) {
node.on(cc.Node.EventType.TOUCH_START, (event: cc.Event.EventTouch) => {
const playerMe = this.allPlayerList.find(
(player) => player.uuid == this.playerId
);
if (playerMe.color != this._status.current) {
this.blinkPiece(node);
return;
}
if (this._status.current != color) {
this.blinkPiece(node);
return;
}
if (this._status.letter == "") {
this.blinkPiece(node);
return;
}
if (node["cantMove"]) {
this.blinkPiece(node);
return;
}
this.stopRollPiece(node);
node["touchStartPos"] = {
nodeX: node.x,
nodeY: node.y,
touchX: event.getLocation().x,
touchY: event.getLocation().y,
};
node.zIndex = 1;
this.showStars(node);
});
node.on(cc.Node.EventType.TOUCH_MOVE, (event: cc.Event.EventTouch) => {
const playerMe = this.allPlayerList.find(
(player) => player.uuid == this.playerId
);
if (playerMe.color != this._status.current) {
return;
}
if (this._status.current != color) {
return;
}
if (this._status.letter == "") {
return;
}
if (node["cantMove"]) {
return;
}
const pos = event.getLocation();
const touchStartPos = node["touchStartPos"];
const worldNodePos = node.parent.convertToWorldSpaceAR(
cc.v2(touchStartPos.nodeX, touchStartPos.nodeY)
);
const nodePos = node.parent.convertToNodeSpaceAR(
cc.v2(
worldNodePos.x + pos.x - touchStartPos.touchX,
worldNodePos.y + pos.y - touchStartPos.touchY
)
);
node.setPosition(nodePos);
});
node.on(cc.Node.EventType.TOUCH_END, async (event: cc.Event.EventTouch) => {
const playerMe = this.allPlayerList.find(
(player) => player.uuid == this.playerId
);
if (playerMe.color != this._status.current) {
return;
}
if (this._status.current != color) {
return;
}
if (this._status.letter == "") {
return;
}
if (node["cantMove"]) {
return;
}
if (this.checkNodeInRightBlock(node, color)) {
const idx = this.getNextRightIdx();
const playerMe = this.allPlayerList.find(
(player) => player.uuid == this.playerId
);
this.networkHelper.sendFrame({
type: "right",
idx: idx,
uuid: playerMe.uuid,
color: playerMe.color,
});
node.on(cc.Node.EventType.TOUCH_END, async (event: cc.Event.EventTouch) => {
const playerMe = this.allPlayerList.find(player => player.uuid == this.playerId);
if (playerMe.color != this._status.current) {
return;
}
if (this._status.current != color) {
return;
}
if (this._status.letter == '') {
return;
}
if (node['cantMove']) {
return;
}
if (this.checkNodeInRightBlock(node, color)) {
const idx = this.getNextRightIdx();
const playerMe = this.allPlayerList.find(player => player.uuid == this.playerId);
this.networkHelper.sendFrame({
type: 'right',
idx: idx,
uuid: playerMe.uuid,
color: playerMe.color
});
} else {
node['cantMove'] = true;
const playerMe = this.allPlayerList.find(player => player.uuid == this.playerId);
this.networkHelper.sendFrame({
type: 'wrong',
uuid: playerMe.uuid,
color: playerMe.color
});
}
} else {
node["cantMove"] = true;
const playerMe = this.allPlayerList.find(
(player) => player.uuid == this.playerId
);
this.networkHelper.sendFrame({
type: "wrong",
uuid: playerMe.uuid,
color: playerMe.color,
});
}
blinkPiece(node) {
node.stopAllActions();
cc.tween(node)
.set({ scale: 1 })
.to(0.05, { scale: 1.05 })
.to(0.05, { scale: 1 })
.start();
}
rollPiece(node: cc.Node) {
node.stopAllActions();
cc.tween(node)
.set({ scale: 1, angle: 0 })
.to(0.1, { angle: -10 })
.to(0.2, { angle: 10 })
.to(0.1, { angle: 0 })
.delay(1)
.union()
.repeatForever()
.start();
const board = cc.find('Canvas/bg/chessBoard/boardItems');
board.children.forEach((child: cc.Node, idx, list) => {
cc.tween(child)
.set({ scale: 1.34 })
.delay(idx * 0.1)
.to(0.1, { scale: 1.5 })
.to(0.1, { scale: 1.34 })
.delay(list.length * 0.2 - idx * 0.2)
.start();
});
}
stopRollPiece(node) {
node.scale = 1;
node.angle = 0;
node.stopAllActions();
}
rollPieceOnce(node: cc.Node) {
node.stopAllActions();
cc.tween(node)
.set({ scale: 1, angle: 0 })
.to(0.1, { angle: -10 })
.to(0.2, { angle: 10 })
.to(0.1, { angle: 0 })
.start();
}
getRightBlock() {
const board = cc.find('Canvas/bg/chessBoard/boardItems');
const startIdx = this._status[this._status.current];
for (let i = startIdx + 1; i < board.children.length; i++) {
const targetNode = board.children[i];
const itemData = targetNode.getComponent('ItemData');
if (itemData.letter.toLowerCase() == this._status.letter.toLowerCase()) {
return targetNode;
}
}
});
}
blinkPiece(node) {
node.stopAllActions();
cc.tween(node)
.set({ scale: 1 })
.to(0.05, { scale: 1.05 })
.to(0.05, { scale: 1 })
.start();
}
rollPiece(node: cc.Node) {
node.stopAllActions();
cc.tween(node)
.set({ scale: 1, angle: 0 })
.to(0.1, { angle: -10 })
.to(0.2, { angle: 10 })
.to(0.1, { angle: 0 })
.delay(1)
.union()
.repeatForever()
.start();
const board = cc.find("Canvas/bg/chessBoard/boardItems");
board.children.forEach((child: cc.Node, idx, list) => {
cc.tween(child)
.set({ scale: 1.34 })
.delay(idx * 0.1)
.to(0.1, { scale: 1.5 })
.to(0.1, { scale: 1.34 })
.delay(list.length * 0.2 - idx * 0.2)
.start();
});
}
stopRollPiece(node) {
node.scale = 1;
node.angle = 0;
node.stopAllActions();
}
rollPieceOnce(node: cc.Node) {
node.stopAllActions();
cc.tween(node)
.set({ scale: 1, angle: 0 })
.to(0.1, { angle: -10 })
.to(0.2, { angle: 10 })
.to(0.1, { angle: 0 })
.start();
}
getRightBlock() {
const board = cc.find("Canvas/bg/chessBoard/boardItems");
const startIdx = this._status[this._status.current];
console.log("startIdx = " + JSON.stringify(startIdx));
for (let i = startIdx + 1; i < board.children.length; i++) {
const targetNode = board.children[i];
const itemData = targetNode.getComponent("ItemData");
if (itemData.letter.toLowerCase() == this._status.letter.toLowerCase()) {
return targetNode;
}
}
return null;
}
getNextRightIdx() {
const board = cc.find("Canvas/bg/chessBoard/boardItems");
const startIdx = this._status[this._status.current];
for (let i = startIdx + 1; i < board.children.length; i++) {
const targetNode = board.children[i];
const itemData = targetNode.getComponent("ItemData");
if (itemData.letter.toLowerCase() == this._status.letter.toLowerCase()) {
return i;
}
}
return -1;
}
checkNodeInRightBlock(node, color) {
const board = cc.find("Canvas/bg/chessBoard/boardItems");
const startIdx = this._status[color];
for (let i = startIdx + 1; i < board.children.length; i++) {
const targetNode = board.children[i];
const itemData = targetNode.getComponent("ItemData");
if (itemData.letter.toLowerCase() == this._status.letter.toLowerCase()) {
if (targetNode.getBoundingBox().intersects(node.getBoundingBox())) {
return true;
}
return null;
}
getNextRightIdx() {
const board = cc.find('Canvas/bg/chessBoard/boardItems');
const startIdx = this._status[this._status.current];
for (let i = startIdx + 1; i < board.children.length; i++) {
const targetNode = board.children[i];
const itemData = targetNode.getComponent('ItemData');
if (itemData.letter.toLowerCase() == this._status.letter.toLowerCase()) {
return i;
}
return false;
}
}
return false;
}
showStars(node) {
cc.tween(node)
.delay(0.07)
.call(() => {
const light = cc.instantiate(cc.find("nodes/light"));
light.parent = node.parent;
cc.tween(light)
.set({
x: node.x + RandomInt(200) - 100,
y: node.y + 50,
scale: 0,
})
.by(
1,
{
y: 200 + RandomInt(200) - 100,
scale: 0.7 + 0.3 * Math.random(),
},
{ easing: "cubicOut" }
)
.removeSelf()
.start();
})
.union()
.repeatForever()
.start();
}
async pieceFindRightBlock(rightBlock, idx) {
const board = cc.find("Canvas/bg/chessBoard/boardItems");
const color = this._status.current;
const piece = cc.find(`Canvas/bg/chessBoard/piece${color}`);
const prograssbar = cc.find(
`Canvas/bg/Life${color.toLowerCase()}/life_${color.toLowerCase()}/mask/prograssbar`
);
const mask = cc.find(
`Canvas/bg/Life${color.toLowerCase()}/life_${color.toLowerCase()}/mask`
);
const targetHeight =
(idx / (board.children.length - 2)) * prograssbar.height;
const offsetX = { Red: -45, Blue: 45 };
const offsetY = { Red: -90, Blue: -90 };
console.log("汪汪汪 450");
this._status[color] = idx;
await this.playLocalAudio("正确");
piece.zIndex = 1;
this.showStars(piece);
await asyncTweenTo(piece, 1, {
x: rightBlock.x + offsetX[color],
y: rightBlock.y + offsetY[color],
});
for (let i = 0; i < 20; i++) {
const star = cc.instantiate(cc.find("nodes/star"));
star.parent = piece.parent;
cc.tween(star)
.set({
x: piece.x,
y: piece.y + 50,
scale: 0,
})
.to(
0.5,
{
x: piece.x + RandomInt(400) - 200,
y: piece.y + 50 + RandomInt(400) - 200,
scale: 0.3 + 0.2 * Math.random(),
angle: RandomInt(720),
},
{ easing: "cubicOut" }
)
.removeSelf()
.start();
}
piece.stopAllActions();
await this.playLocalAudio("落子");
piece.zIndex = 0;
const effectNode = cc.find(`Canvas/bg/Life${color.toLowerCase()}/effect`);
effectNode.active = true;
asyncTweenTo(mask, 1, { height: targetHeight }, { easing: "cubicInOut" });
this.playLocalAudio("进度条升高");
await asyncPlayDragonBoneAnimation(effectNode, "normal", 1);
effectNode.active = false;
}
updateStatus(status = null) {
if (status) {
console.log("汪汪汪 497");
this._status = JSON.parse(JSON.stringify(status));
}
const playerMe = this.allPlayerList.find(
(player) => player.uuid == this.playerId
);
if (playerMe.color == this._status.current) {
this.stopGreyDice();
if (this._status.letter == "") {
this.showYourTurn();
this.blinkTheDice();
} else {
this.stopBlinkTheDice();
this.rollPiece(this.getCurrentPiece());
}
} else {
this.greyDice();
}
const blueFrame = cc.find("Canvas/bg/Lifeblue/faceFrame");
const redFrame = cc.find("Canvas/bg/Lifered/faceFrame");
let blinkFrame: cc.Node, stopBlinkFrame: cc.Node;
if (this._status.current == "Red") {
blinkFrame = redFrame;
stopBlinkFrame = blueFrame;
} else {
blinkFrame = blueFrame;
stopBlinkFrame = redFrame;
}
blinkFrame.stopAllActions();
cc.tween(blinkFrame)
.set({ opacity: 100 })
.to(1.5, { opacity: 255 }, { easing: "cubicOut" })
.to(1.5, { opacity: 100 }, { easing: "cubicIn" })
.union()
.repeatForever()
.start();
stopBlinkFrame.stopAllActions();
stopBlinkFrame.opacity = 0;
}
getCurrentPiece() {
if (this._status.current == "Red") {
return cc.find("Canvas/bg/chessBoard/pieceRed");
} else {
return cc.find("Canvas/bg/chessBoard/pieceBlue");
}
}
changeSide() {
if (this._status.current == "Red") {
this._status.current = "Blue";
} else {
this._status.current = "Red";
}
}
showYourTurn() {
return new Promise((resolve, reject) => {
const yourTurn = cc.find("Canvas/bg/yourturn");
yourTurn.active = true;
cc.tween(yourTurn)
.set({ opacity: 0, scale: 5 })
.to(1, { opacity: 255, scale: 2 })
.delay(0.5)
.to(0.5, { opacity: 0 })
.call(() => {
resolve();
})
.start();
});
}
async pieceGoBack(node) {
const touchStartPos = node["touchStartPos"];
if (!touchStartPos) {
return;
}
this.playLocalAudio("错误弹回");
await asyncTweenTo(
node,
0.7,
{ x: touchStartPos.nodeX, y: touchStartPos.nodeY },
{ easing: "cubicOut" }
);
node.stopAllActions();
}
allPlayerList;
initNetworkListener() {
this.networkHelper.on("playerJoin", (event) => {
if (this.server) {
this.server.onPlayerJoin(event);
}
cc.log("playerJoin" + JSON.stringify(event));
});
this.networkHelper.on("playerLeave", (event) => {
cc.log("playerLeave" + JSON.stringify(event));
});
this.networkHelper.on("playerOffLine", (event) => {
cc.log("playerOffLine" + JSON.stringify(event));
});
this.networkHelper.on("gameStart", (event) => {});
this.networkHelper.on("frameEvent", (event) => {
event.data.frame.items.forEach(async (item) => {
if (this.server) {
this.server.onFrameEvent(item.data);
}
return -1;
}
checkNodeInRightBlock(node, color) {
const board = cc.find('Canvas/bg/chessBoard/boardItems');
const startIdx = this._status[color];
for (let i = startIdx + 1; i < board.children.length; i++) {
const targetNode = board.children[i];
const itemData = targetNode.getComponent('ItemData');
if (itemData.letter.toLowerCase() == this._status.letter.toLowerCase()) {
if (targetNode.getBoundingBox().intersects(node.getBoundingBox())) {
return true;
}
return false
if (item.data.type == "SERVER_allPlayerInfo") {
console.log(
"SERVER_allPlayerInfo: " + JSON.stringify(item.data.playerData)
);
item.data.playerData.forEach((player) => {
if (!this.allPlayerList) {
this.allPlayerList = [];
}
}
return false
}
async pieceFindRightBlock(rightBlock, idx) {
const board = cc.find('Canvas/bg/chessBoard/boardItems');
const color = this._status.current;
const piece = cc.find(`Canvas/bg/chessBoard/piece${color}`);
const prograssbar = cc.find(`Canvas/bg/Life${color.toLowerCase()}/life_${color.toLowerCase()}/mask/prograssbar`);
const mask = cc.find(`Canvas/bg/Life${color.toLowerCase()}/life_${color.toLowerCase()}/mask`);
const targetHeight = (idx / (board.children.length - 2)) * prograssbar.height;
const offsetX = { Red: -45, Blue: 45 };
const offsetY = { Red: -90, Blue: -90 };
this._status[color] = idx;
await this.playLocalAudio('正确');
await asyncTweenTo(piece, 1, { x: rightBlock.x + offsetX[color], y: rightBlock.y + offsetY[color] });
await this.playLocalAudio('落子');
const effectNode = cc.find(`Canvas/bg/Life${color.toLowerCase()}/effect`);
effectNode.active = true;
asyncTweenTo(mask, 1, { height: targetHeight }, { easing: 'cubicInOut' });
this.playLocalAudio('进度条升高');
await asyncPlayDragonBoneAnimation(effectNode, 'normal', 1);
effectNode.active = false;
}
updateStatus(status = null) {
if (status) {
this._status = status;
}
const playerMe = this.allPlayerList.find(player => player.uuid == this.playerId);
if (playerMe.color == this._status.current) {
this.stopGreyDice();
if (this._status.letter == '') {
this.blinkTheDice();
} else {
this.stopBlinkTheDice();
this.rollPiece(this.getCurrentPiece());
if (
!this.allPlayerList.find(
(listPlayer) => listPlayer.uuid == player.uuid
)
) {
this.allPlayerList.push({
uuid: player.uuid,
name: player.name,
color: player.color,
headUrl: player.headUrl,
});
}
} else {
this.greyDice();
}
const blueFrame = cc.find('Canvas/bg/Lifeblue/faceFrame');
const redFrame = cc.find('Canvas/bg/Lifered/faceFrame');
let blinkFrame: cc.Node, stopBlinkFrame: cc.Node;
if (this._status.current == 'Red') {
blinkFrame = redFrame;
stopBlinkFrame = blueFrame;
} else {
blinkFrame = blueFrame;
stopBlinkFrame = redFrame;
}
blinkFrame.stopAllActions();
cc.tween(blinkFrame)
.set({ opacity: 100 })
.to(1.5, { opacity: 255 }, { easing: 'cubicOut' })
.to(1.5, { opacity: 100 }, { easing: 'cubicIn' })
.union()
.repeatForever()
.start();
stopBlinkFrame.stopAllActions();
stopBlinkFrame.opacity = 0;
}
getCurrentPiece() {
if (this._status.current == 'Red') {
return cc.find('Canvas/bg/chessBoard/pieceRed');
} else {
return cc.find('Canvas/bg/chessBoard/pieceBlue');
this.loadPlayerHeadImage();
this.loadingLayer.addPlayer(
player.name,
player.uuid == this.playerId,
player.headUrl,
player.uuid
);
});
} else if (item.data.type == "SERVER_updateStatus") {
await asyncDelay(3);
console.log(
"SERVER_updateStatus: " + JSON.stringify(item.data.status)
);
this.updateStatus(item.data.status);
} else if (item.data.type == "SERVER_playerRoll") {
console.log("SERVER_playerRoll: " + JSON.stringify(item.data));
const status = this._status;
console.log("汪汪汪 647");
status.letter = item.data.letter;
console.log("status.letter = " + status.letter);
console.log("item.data.letter = " + item.data.letter);
const idx = ["A", "B", "C", "D", "E", "F"].findIndex(
(letter) => letter == status.letter
);
const pieceRed = cc.find("Canvas/bg/chessBoard/pieceRed");
const pieceBlue = cc.find("Canvas/bg/chessBoard/pieceBlue");
pieceRed["cantMove"] = true;
pieceBlue["cantMove"] = true;
this.stopBlinkTheDice();
console.log("status1 = " + JSON.stringify(status));
await this.rollTheDice(idx);
pieceRed["cantMove"] = false;
pieceBlue["cantMove"] = false;
console.log("status2 = " + JSON.stringify(status));
console.log("this._status = " + JSON.stringify(this._status));
this.updateStatus(status);
console.log("status = " + JSON.stringify(status));
console.log("this._status = " + JSON.stringify(this._status));
} else if (item.data.type == "SERVER_playerRight") {
console.log("SERVER_playerRight: " + JSON.stringify(item.data));
console.log("this._status = " + JSON.stringify(this._status));
const rightBlock = this.getRightBlock();
console.log(rightBlock);
const idx = this.getNextRightIdx();
console.log(idx);
await this.pieceFindRightBlock(rightBlock, idx);
this._status.letter = "";
console.log("汪汪汪672");
this.changeSide();
this.updateStatus();
} else if (item.data.type == "SERVER_playerWrong") {
console.log("SERVER_playerWrong: " + JSON.stringify(item.data));
const node = cc.find(
`Canvas/bg/chessBoard/piece${this._status.current}`
);
const playerMe = this.allPlayerList.find(
(player) => player.uuid == this.playerId
);
if (playerMe.color == this._status.current) {
await this.pieceGoBack(node);
} else {
this.rollPieceOnce(node);
}
node["cantMove"] = false;
console.log("汪汪汪 691");
this._status.letter = "";
this.changeSide();
this.updateStatus();
} else if (item.data.type == "SERVER_playerWin") {
console.log("SERVER_playerWin: " + JSON.stringify(item.data));
const node = cc.find(
`Canvas/bg/chessBoard/piece${this._status.current}`
);
const playerMe = this.allPlayerList.find(
(player) => player.uuid == this.playerId
);
const board = cc.find("Canvas/bg/chessBoard/boardItems");
const idx = board.children.length;
const rightBlock = board.children[idx - 1];
await this.pieceFindRightBlock(rightBlock, idx);
if (playerMe.color == this._status.current) {
this.showWin();
} else {
this.showLoss();
}
}
}
changeSide() {
if (this._status.current == 'Red') {
this._status.current = 'Blue';
});
});
}
showWin() {
cc.find("Canvas/endBg").active = true;
const bg = cc.find("Canvas/endBg/bg");
cc.tween(bg).to(1, { opacity: 100 }).start();
const loss = cc.find("Canvas/endBg/labelBg/labelLoss");
loss.active = false;
this.playLocalAudio("胜利");
}
showLoss() {
cc.find("Canvas/endBg").active = true;
const bg = cc.find("Canvas/endBg/bg");
cc.tween(bg).to(1, { opacity: 100 }).start();
const win = cc.find("Canvas/endBg/labelBg/labelWin");
win.active = false;
this.playLocalAudio("失败");
}
loadPlayerHeadImage() {
const red = cc.find("Canvas/bg/Lifered/faceRed");
const blue = cc.find("Canvas/bg/Lifeblue/faceBlue");
this.allPlayerList.forEach((player) => {
this.getSpriteFrimeByUrl(player.headUrl, (sf) => {
if (player.color == "Red") {
red.getComponent(cc.Sprite).spriteFrame = sf;
} else {
this._status.current = 'Red';
}
}
async pieceGoBack(node) {
const touchStartPos = node['touchStartPos'];
if (!touchStartPos) {
return;
blue.getComponent(cc.Sprite).spriteFrame = sf;
}
this.playLocalAudio('错误弹回');
await asyncTweenTo(node, 0.7, { x: touchStartPos.nodeX, y: touchStartPos.nodeY }, { easing: 'cubicOut' });
}
allPlayerList;
initNetworkListener() {
this.networkHelper.on('playerJoin', (event) => {
if (this.server) {
this.server.onPlayerJoin(event);
}
cc.log("playerJoin" + JSON.stringify(event));
});
this.networkHelper.on('playerLeave', (event) => {
cc.log("playerLeave" + JSON.stringify(event));
});
this.networkHelper.on('gameStart', (event) => {
});
this.networkHelper.on('frameEvent', (event) => {
event.data.frame.items.forEach(async item => {
if (this.server) {
this.server.onFrameEvent(item.data);
}
if (item.data.type == 'SERVER_allPlayerInfo') {
console.log('SERVER_allPlayerInfo: ' + JSON.stringify(item.data.playerData));
item.data.playerData.forEach(player => {
if (!this.allPlayerList) {
this.allPlayerList = [];
}
if (!this.allPlayerList.find(listPlayer => listPlayer.uuid == player.uuid)) {
this.allPlayerList.push({
uuid: player.uuid,
name: player.name,
color: player.color,
headUrl: player.headUrl
});
}
this.loadPlayerHeadImage();
this.loadingLayer.addPlayer(
player.name,
player.uuid == this.playerId,
player.headUrl,
player.uuid
);
})
} else if (item.data.type == 'SERVER_updateStatus') {
console.log('SERVER_updateStatus: ' + JSON.stringify(item.data.status));
this.updateStatus(item.data.status);
} else if (item.data.type == 'SERVER_playerRoll') {
console.log('SERVER_playerRoll: ' + JSON.stringify(item.data));
const status = this._status;
status.letter = item.data.letter;
const idx = ['A', 'B', 'C', 'D', 'E', 'F'].findIndex(letter => letter == status.letter);
await this.rollTheDice(idx);
this.updateStatus(status);
} else if (item.data.type == 'SERVER_playerRight') {
console.log('SERVER_playerRight: ' + JSON.stringify(item.data));
const rightBlock = this.getRightBlock();
const idx = this.getNextRightIdx();
this.pieceFindRightBlock(rightBlock, idx);
this._status.letter = '';
this.changeSide();
this.updateStatus();
} else if (item.data.type == 'SERVER_playerWrong') {
console.log('SERVER_playerWrong: ' + JSON.stringify(item.data));
const node = cc.find(`Canvas/bg/chessBoard/piece${this._status.current}`);
const playerMe = this.allPlayerList.find(player => player.uuid == this.playerId);
if (playerMe.color == this._status.current) {
await this.pieceGoBack(node);
} else {
this.rollPieceOnce(node);
}
node['cantMove'] = false;
this._status.letter = '';
this.changeSide();
this.updateStatus();
} else if (item.data.type == 'SERVER_playerWin') {
console.log('SERVER_playerWin: ' + JSON.stringify(item.data));
const node = cc.find(`Canvas/bg/chessBoard/piece${this._status.current}`);
const playerMe = this.allPlayerList.find(player => player.uuid == this.playerId);
const board = cc.find('Canvas/bg/chessBoard/boardItems');
const idx = board.children.length;
const rightBlock = board.children[idx - 1];
this.pieceFindRightBlock(rightBlock, idx);
if (playerMe.color == this._status.current) {
this.showWin();
} else {
this.showLoss();
}
}
});
});
}
showWin() {
const bg = cc.find('Canvas/endBg');
cc.tween(bg)
.to(1, { opacity: 255 })
.start();
const loss = cc.find('Canvas/endBg/bg/bg/labelLoss');
loss.active = false;
this.playLocalAudio('胜利');
}
showLoss() {
const bg = cc.find('Canvas/endBg');
cc.tween(bg)
.to(1, { opacity: 255 })
.start();
const win = cc.find('Canvas/endBg/bg/bg/labelWin');
win.active = false;
this.playLocalAudio('失败');
}
loadPlayerHeadImage() {
const red = cc.find('Canvas/bg/Lifered/faceRed');
const blue = cc.find('Canvas/bg/Lifeblue/faceBlue');
this.allPlayerList.forEach(player => {
this.getSpriteFrimeByUrl(player.headUrl, (sf) => {
if (player.color == 'Red') {
red.getComponent(cc.Sprite).spriteFrame = sf;
} else {
blue.getComponent(cc.Sprite).spriteFrame = sf;
}
});
});
}
async movePiece(letter, color) {
const offsetX = { Red: -45, Blue: 45 };
const offsetY = { Red: -90, Blue: -90 };
const pieceNode = cc.find(`Canvas/bg/chessBoard/piece${color}`)
const board = cc.find('Canvas/bg/chessBoard/boardItems');
const startIdx = this._status[color];
for (let i = startIdx + 1; i < board.children.length; i++) {
const targetNode = board.children[i];
const itemData = targetNode.getComponent('ItemData');
const prograssbar = cc.find(`Canvas/bg/Life${color.toLowerCase()}/life_${color.toLowerCase()}/mask/prograssbar`);
const mask = cc.find(`Canvas/bg/Life${color.toLowerCase()}/life_${color.toLowerCase()}/mask`);
const targetHeight = (i / board.children.length) * prograssbar.height;
cc.tween(mask)
.to(1, { height: targetHeight }, { easing: 'cubicInOut' })
.start();
await asyncTweenTo(pieceNode, 1, {
x: targetNode.x + offsetX[color],
y: targetNode.y + offsetY[color]
}, { easing: 'cubicInOut' });
if (itemData.letter.toLowerCase() == letter.toLowerCase()) {
this._status[color] = i;
return;
}
}
this.finish();
}
finish() {
onHomeworkFinish();
}
rollTheDice(num) {
const dice = cc.find('Canvas/bg/chessBoard/diceBg/dice');
if (dice['cantRoll']) {
return;
}
return new Promise((resolve, reject) => {
const targetAngle = Math.ceil(dice.angle / 360 + 1) * 360;
const time = (targetAngle - 360 - dice.angle) / 360;
dice['cantRoll'] = true;
cc.tween(dice)
.by(3, { angle: 360 }, { easing: "cubicIn" })
.to(time, { angle: targetAngle })
.by(1, { angle: 360 })
.by(1, { angle: 360 })
.by(1, { angle: 360 })
.by(1, { angle: 360 })
.by(1 / 6 * num, { angle: 60 * num })
.by(3, { angle: 360 }, { easing: "cubicOut" })
.call(() => {
dice['cantRoll'] = false;
resolve(null);
})
.start();
});
}
playLocalAudio(audioName) {
const audio = cc.find(`audioClips/${audioName}`).getComponent(cc.AudioSource);
return new Promise((resolve, reject) => {
const id = cc.audioEngine.playEffect(audio.clip, false);
cc.audioEngine.setFinishCallback(id, () => {
resolve(id);
});
});
});
}
async movePiece(letter, color) {
const offsetX = { Red: -45, Blue: 45 };
const offsetY = { Red: -90, Blue: -90 };
const pieceNode = cc.find(`Canvas/bg/chessBoard/piece${color}`);
const board = cc.find("Canvas/bg/chessBoard/boardItems");
const startIdx = this._status[color];
for (let i = startIdx + 1; i < board.children.length; i++) {
const targetNode = board.children[i];
const itemData = targetNode.getComponent("ItemData");
const prograssbar = cc.find(
`Canvas/bg/Life${color.toLowerCase()}/life_${color.toLowerCase()}/mask/prograssbar`
);
const mask = cc.find(
`Canvas/bg/Life${color.toLowerCase()}/life_${color.toLowerCase()}/mask`
);
const targetHeight = (i / board.children.length) * prograssbar.height;
cc.tween(mask)
.to(1, { height: targetHeight }, { easing: "cubicInOut" })
.start();
await asyncTweenTo(
pieceNode,
1,
{
x: targetNode.x + offsetX[color],
y: targetNode.y + offsetY[color],
},
{ easing: "cubicInOut" }
);
if (itemData.letter.toLowerCase() == letter.toLowerCase()) {
this._status[color] = i;
console.log("汪汪汪 784");
return;
}
}
this.finish();
}
finish() {
onHomeworkFinish();
}
rollTheDice(num) {
const dice = cc.find("Canvas/bg/chessBoard/diceBg/dice");
if (dice["cantRoll"]) {
return;
}
return new Promise((resolve, reject) => {
const targetAngle = Math.ceil(dice.angle / 360 + 1) * 360;
const time = (targetAngle - 360 - dice.angle) / 360;
dice["cantRoll"] = true;
cc.tween(dice)
.by(3, { angle: 360 }, { easing: "cubicIn" })
.to(time, { angle: targetAngle })
.by(1, { angle: 360 })
.by(1, { angle: 360 })
.by(1, { angle: 360 })
.by(1, { angle: 360 })
.by((1 / 6) * num, { angle: 60 * num })
.by(3, { angle: 360 }, { easing: "cubicOut" })
.call(() => {
dice["cantRoll"] = false;
resolve(null);
})
}
// 生命周期
onDestroy() {
this.networkHelper.onDestroy();
}
.start();
});
}
playLocalAudio(audioName) {
const audio = cc
.find(`audioClips/${audioName}`)
.getComponent(cc.AudioSource);
return new Promise((resolve, reject) => {
const id = cc.audioEngine.playEffect(audio.clip, false);
cc.audioEngine.setFinishCallback(id, () => {
resolve(id);
});
});
}
// 生命周期
onDestroy() {
this.networkHelper.onDestroy();
}
}
......@@ -7,8 +7,8 @@ export class AI {
_status = {
Red: 0,
Blue: 0,
letter: '',
current: 'Blue'
letter: "",
current: "Blue",
};
constructor(networkHelper: NetworkHelper, playerData: any) {
......@@ -17,44 +17,47 @@ export class AI {
}
async onFrameEvent(event) {
console.log('AI get event: ' + JSON.stringify(event));
if (event.type == 'SERVER_updateStatus') {
console.log("AI get event: " + JSON.stringify(event));
if (event.type == "SERVER_updateStatus") {
this._status = JSON.parse(JSON.stringify(event.status));
} else if (event.type == 'SERVER_playerRoll') {
} else if (event.type == "SERVER_playerRoll") {
console.log('汪汪汪0');
this._status.letter = event.letter;
if (this.playerData.color == this._status.current) {
await asyncDelay(Math.random() * 3 + 11);
await asyncDelay(Math.random() * 3 + 12);
}
} else if (event.type == 'SERVER_playerRight') {
this._status.letter = '';
} else if (event.type == "SERVER_playerRight") {
console.log('汪汪汪1');
this._status.letter = "";
this._status[event.color] = event.idx;
this.changeSide();
} else if (event.type == 'SERVER_playerWrong') {
this._status.letter = '';
} else if (event.type == "SERVER_playerWrong") {
console.log('汪汪汪2');
this._status.letter = "";
this.changeSide();
}
if (this.playerData.color == this._status.current) {
await asyncDelay(Math.random() * 3 + 2);
if (this._status.letter == '') {
await asyncDelay(Math.random() * 3 + 4);
if (this._status.letter == "") {
this.networkHelper.sendFrame({
type: 'roll',
uuid: this.playerData.uuid
type: "roll",
uuid: this.playerData.uuid,
});
} else {
const idx = this.getNextRightIdx();
if (Math.random() > 0.5) {
if (Math.random() < 0.9) {
this.networkHelper.sendFrame({
type: 'right',
type: "right",
idx: idx,
uuid: this.playerData.uuid,
color: this.playerData.color
color: this.playerData.color,
});
} else {
this.networkHelper.sendFrame({
type: 'wrong',
type: "wrong",
uuid: this.playerData.uuid,
color: this.playerData.color
color: this.playerData.color,
});
}
}
......@@ -62,23 +65,23 @@ export class AI {
}
changeSide() {
if (this._status.current == 'Red') {
this._status.current = 'Blue';
if (this._status.current == "Red") {
this._status.current = "Blue";
} else {
this._status.current = 'Red';
this._status.current = "Red";
}
}
getNextRightIdx() {
const board = cc.find('Canvas/bg/chessBoard/boardItems');
const board = cc.find("Canvas/bg/chessBoard/boardItems");
const startIdx = this._status[this._status.current];
for (let i = startIdx + 1; i < board.children.length; i++) {
const targetNode = board.children[i];
const itemData = targetNode.getComponent('ItemData');
const itemData = targetNode.getComponent("ItemData");
if (itemData.letter.toLowerCase() == this._status.letter.toLowerCase()) {
return i;
}
}
return -1;
}
}
\ No newline at end of file
}
......@@ -97,6 +97,7 @@ export default class SceneComponent extends cc.Component {
cc.find('right', this.node).addChild(headNode);
const vs = cc.find('vs', this.node);
asyncPlayDragonBoneAnimation(vs, 'normal', 1);
this.playLocalAudio('match');
}
const rate = Math.min(1, this._playerList.length / this._maxPlayerNum);
......@@ -231,6 +232,25 @@ export default class SceneComponent extends cc.Component {
}
});
}
playLocalAudio(name) {
return new Promise((resolve, reject) => {
this.stopCurrentPlayedAudio();
const audioNode = cc.find(`res/${name}`, this.node);
if (!audioNode) {
resolve(null);
return;
}
const audioClip = audioNode.getComponent(cc.AudioSource).clip;
const audioId = cc.audioEngine.play(audioClip, false, 0.8);
this.currentPlayedAudioId = audioId;
cc.audioEngine.setFinishCallback(audioId, () => {
resolve(null);
});
});
}
_timeoutIds = [];
_intervalIds = [];
// 生命周期
......
import { Base64 } from "js-base64";
export class NetworkHelper {
_eventListeners: any = {};
ctor() { }
ctor() {}
on(eventName, func) {
this._eventListeners[eventName] = func;
}
async init(roomType: string, maxPlayers: number) {
this.initRoom();
try {
return await this.joinRoom(roomType, maxPlayers);
} catch (e) {
await this.initListener();
this.initRoom();
await this.initListener();
return await this.joinRoom(roomType, maxPlayers);
} catch (e) {
// return null;
}
}
......@@ -28,6 +25,7 @@ export class NetworkHelper {
async stopGame() {
await this.stopFrameSync();
await this.closeRoom();
await this.leaveRoom();
}
......@@ -35,7 +33,14 @@ export class NetworkHelper {
return this.room.roomInfo;
}
listenerInited = false;
initListener() {
if (this.listenerInited) {
return;
}
// MGOBE.Listener;
return new Promise((resolve, reject) => {
const gameId = "obg-i4ql53h1"; //替换为控制台上的 游戏 ID
const openId = "openid_op_16" + Math.random();
......@@ -44,50 +49,58 @@ export class NetworkHelper {
gameId: gameId,
openId: openId,
createSignature: (callback) => {
this.callNetworkApiGet('http://staging-teach.ireadabc.com', '/api/oxford/game/v1/config', {
gameid: gameId,
openid: openId,
}, (data) => {
callback(JSON.parse(data));
});
}
this.callNetworkApiGet(
"http://staging-teach.ireadabc.com",
"/api/oxford/game/v1/config",
{
gameid: gameId,
openid: openId,
},
(data) => {
callback(JSON.parse(data));
}
);
},
};
const serverUrl = "i4ql53h1.wxlagame.com"; //替换为控制台上的 域名
const config = {
url: serverUrl,
reconnectMaxTimes: 5,
reconnectMaxTimes: 3,
reconnectInterval: 1000,
resendInterval: 1000,
resendTimeout: 10000,
cacertNativeUrl: ""
resendTimeout: 5000,
cacertNativeUrl: "",
};
MGOBE.DebuggerLog.enable = false;
// 如果是原生平台,则加载 Cert 证书,否则会提示 WSS 错误
if (cc.sys.isNative) {
let cacertFile;
const cacertNode = cc.find('cacertNode');
const cacertNode = cc.find("cacertNode");
if (cacertNode) {
cacertFile = cacertNode.getComponent('cacert').cacertFile;
cacertFile = cacertNode.getComponent("cacert").cacertFile;
}
if (!cacertFile) {
console.log('没有cacertFile!!!');
console.log("没有cacertFile!!!");
}
config.cacertNativeUrl = cc.loader.md5Pipe && cc.ENGINE_VERSION < "2.4.0" ?
cc.loader.md5Pipe.transformURL(cacertFile.nativeUrl) :
cacertFile.nativeUrl;
config.cacertNativeUrl =
cc.loader.md5Pipe && cc.ENGINE_VERSION < "2.4.0"
? cc.loader.md5Pipe.transformURL(cacertFile.nativeUrl)
: cacertFile.nativeUrl;
}
MGOBE.Listener.init(gameInfo, config, event => {
console.log("initListener");
MGOBE.Listener.init(gameInfo, config, (event) => {
console.log(JSON.stringify(event));
if (event.code !== 0) {
console.log("初始化失败: " + event.code);
reject();
return;
}
this.listenerInited = true;
console.log("初始化成功");
resolve(null);
});
......@@ -101,14 +114,16 @@ export class NetworkHelper {
this.room.onJoinRoom = this.onJoinRoom.bind(this);
this.room.onLeaveRoom = this.onLeaveRoom.bind(this);
this.room.onRecvFromClient = this.onRecvFromClient.bind(this);
this.room.onChangePlayerNetworkState =
this.onChangePlayerNetworkState.bind(this);
this.room.onRecvFrame = this.onRecvFrame.bind(this);
this.room.onStartFrameSync = this.onStartFrameSync.bind(this);
this.room.onStopFrameSync = this.onStopFrameSync.bind(this);
this.room.onRecvFromGameSvr = this.onRecvFromGameSvr.bind(this);
console.log('this.room = ' + JSON.stringify(this.room.roomInfo));
console.log("this.room = " + JSON.stringify(this.room.roomInfo));
}
joinRoom(roomType: string, maxPlayers: number, customData: string = '') {
joinRoom(roomType: string, maxPlayers: number, customData: string = "") {
return new Promise((resolve, reject) => {
const playerName = "Tom" + Math.random();
const playerInfo = {
......@@ -120,27 +135,44 @@ export class NetworkHelper {
const matchRoomPara = {
playerInfo,
maxPlayers: maxPlayers,
roomType: roomType
roomType: roomType,
};
this.room.matchRoom(matchRoomPara, event => {
this.room.matchRoom(matchRoomPara, async (event) => {
// console.log(JSON.stringify(event))
if (event.code === 0) {
cc.log("匹配成功: " + event.data.roomInfo.id);
const player = event.data.roomInfo.playerList.find(player => player.name == playerName);
resolve(player.id);
} else {
if (event.code !== 0) {
cc.log("匹配失败");
reject(event);
return;
}
const roomInfo = event.data.roomInfo;
cc.log("匹配成功: " + roomInfo.id);
const player = roomInfo.playerList.find(
(player) => player.name == playerName
);
if (roomInfo.owner == player.id) {
console.log("房主: " + player.id);
resolve(player.id);
return;
}
if (roomInfo.playerList.length == 1) {
console.log("空房间");
await this.leaveRoom();
await this.closeRoom();
resolve(null);
return;
}
resolve(player.id);
});
});
}
leaveRoom() {
return new Promise((resolve, reject) => {
this.room.leaveRoom({}, event => {
console.log(JSON.stringify(event))
this.room.leaveRoom({}, (event) => {
console.log(JSON.stringify(event));
if (event.code === 0) {
console.log("退房成功" + this.room.roomInfo.id);
// this.room.initRoom();
......@@ -152,10 +184,24 @@ export class NetworkHelper {
});
}
dismissRoom() {
const roomInfo = this.room.roomInfo;
const player = roomInfo.playerList.find(
(player) => player.name == playerName
);
if (roomInfo.owner == player.id) {
return new Promise((resolve, reject) => {
this.room.dismissRoom({}, (res) => {
console.log("房间已解散");
});
});
}
}
closeRoom() {
return new Promise((resolve, reject) => {
this.room.changeRoom({ isForbidJoin: true }, (event) => {
console.log('关门')
console.log("关门");
// console.log(JSON.stringify(event))
resolve(null);
});
......@@ -166,15 +212,15 @@ export class NetworkHelper {
const sendToClientPara = {
recvType: MGOBE.ENUM.RecvType.ROOM_ALL,
recvPlayerList: [],
msg: "hello" + Math.random()
msg: "hello" + Math.random(),
};
this.room.sendToClient(sendToClientPara, event => console.log(event));
this.room.sendToClient(sendToClientPara, (event) => console.log(event));
}
startFrameSync() {
return new Promise((resolve, reject) => {
this.room.startFrameSync({}, event => {
console.log(JSON.stringify(event))
this.room.startFrameSync({}, (event) => {
console.log(JSON.stringify(event));
if (event.code === 0) {
cc.log("开始帧同步成功,请到控制台查看具体帧同步信息");
resolve(null);
......@@ -191,8 +237,8 @@ export class NetworkHelper {
resolve(null);
return;
}
this.room.stopFrameSync({}, event => {
console.log(JSON.stringify(event))
this.room.stopFrameSync({}, (event) => {
console.log(JSON.stringify(event));
if (event.code === 0) {
console.log("停止帧同步成功");
resolve(null);
......@@ -207,69 +253,94 @@ export class NetworkHelper {
sendToServer() {
const sendToGameServerPara = {
data: {
cmd: 1
}
cmd: 1,
},
};
this.room.sendToGameSvr(sendToGameServerPara, event => console.log(event));
this.room.sendToGameSvr(sendToGameServerPara, (event) =>
console.log(event)
);
}
sendFrame(data: any) {
this.room.sendFrame({ data }, err => {
this.room.sendFrame({ data }, (err) => {
if (err.code != 0) {
console.log("err", err)
console.log("err", err);
}
});
}
onJoinRoom(event) {
if (this._eventListeners['playerJoin']) {
this._eventListeners['playerJoin'](event);
if (this._eventListeners["playerJoin"]) {
this._eventListeners["playerJoin"](event);
}
console.log("新玩家加入", event.data.joinPlayerId);
}
onLeaveRoom(event) {
if (this._eventListeners['playerLeave']) {
this._eventListeners['playerLeave'](event);
console.log("onLeaveRoom");
if (this._eventListeners["playerLeave"]) {
this._eventListeners["playerLeave"](event);
}
console.log("玩家退出", event.data.leavePlayerId);
}
onRecvFromClient() { }
onRecvFromClient() {}
onChangePlayerNetworkState(event) {
console.log("玩家网络变化: " + JSON.stringify(event));
const changePlayer = event.data.roomInfo.playerList.find(
(player) => player.id == event.data.changePlayerId
);
if (
changePlayer.commonNetworkState ==
MGOBE.types.NetworkState.COMMON_OFFLINE ||
changePlayer.relayNetworkState == MGOBE.types.NetworkState.RELAY_OFFLINE
) {
if (this._eventListeners["playerOffLine"]) {
this._eventListeners["playerOffLine"](event);
}
cc.log("掉线了");
} else {
// resolve(player.id);
}
}
onRecvFrame(event) {
if (this._eventListeners['frameEvent']) {
this._eventListeners['frameEvent'](event);
if (this._eventListeners["frameEvent"]) {
this._eventListeners["frameEvent"](event);
}
}
onStartFrameSync(event) {
if (this._eventListeners['gameStart']) {
this._eventListeners['gameStart'](event);
if (this._eventListeners["gameStart"]) {
this._eventListeners["gameStart"](event);
}
}
onStopFrameSync(event) { }
onRecvFromGameSvr() { }
onStopFrameSync(event) {}
onRecvFromGameSvr() {}
async onDestroy() {
try {
console.log('onDestroy1')
console.log("onDestroy1");
this.dismissRoom();
MGOBE.Listener.clear();
await this.stopGame();
console.log('onDestroy2')
this.stopFrameSync();
this.closeRoom();
this.leaveRoom();
console.log("onDestroy2");
} catch (e) {
console.log(JSON.stringify(e));
}
}
log(str) {
const node = cc.find('middleLayer');
const node = cc.find("middleLayer");
if (node) {
node.getComponent('middleLayer').log(str);
node.getComponent("middleLayer").log(str);
} else {
cc.log(str);
}
}
callNetworkApiGet(baseUrl, uri, data, callBack) {
let queryStr = '?';
let queryStr = "?";
const params = [];
for (const key in data) {
if (Object.hasOwnProperty.call(data, key)) {
......@@ -279,13 +350,24 @@ export class NetworkHelper {
queryStr += params.join("&");
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => {
if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) {
if (xhr.readyState == 4 && xhr.status >= 200 && xhr.status < 400) {
callBack(xhr.responseText);
}
};
const url = `${baseUrl}${uri}${queryStr}`;
console.log('url = ' + url);
xhr.open('GET', url, true);
console.log("url = " + url);
xhr.open("GET", url, true);
xhr.send();
}
}
\ No newline at end of file
}
export function asyncDelay(time) {
return new Promise((resolve, reject) => {
cc.tween(cc.find("Canvas"))
.delay(time)
.call(() => {
resolve();
})
.start();
});
}
......@@ -7,16 +7,25 @@ export class GameServer {
playerMaxNumber = 0;
networkHelper: NetworkHelper = null;
nameList = [
'Chris', 'Benny', 'Leslie', 'Devin', 'Sam',
'Kerry', 'Joey', 'Hailey', 'Fred', 'Arrow',
'Tony', 'Michael',
"Chris",
"Benny",
"Leslie",
"Devin",
"Sam",
"Kerry",
"Joey",
"Hailey",
"Fred",
"Arrow",
"Tony",
"Michael",
];
headUrls = [
'http://staging-teach.cdn.ireadabc.com/0751c28419a0e8ffb1f0e84435b081ce.png',
'http://staging-teach.cdn.ireadabc.com/f596e586a31ac2813b1702557941c022.png',
'http://staging-teach.cdn.ireadabc.com/f0f396c52c42239913fd94523db979fa.png',
'http://staging-teach.cdn.ireadabc.com/9f2d2ef622fa33d4e2abcbdc4b40ab6a.png',
'http://staging-teach.cdn.ireadabc.com/f40ce4a8630039c4cf48a63fc1399c52.png'
"http://staging-teach.cdn.ireadabc.com/0751c28419a0e8ffb1f0e84435b081ce.png",
"http://staging-teach.cdn.ireadabc.com/f596e586a31ac2813b1702557941c022.png",
"http://staging-teach.cdn.ireadabc.com/f0f396c52c42239913fd94523db979fa.png",
"http://staging-teach.cdn.ireadabc.com/9f2d2ef622fa33d4e2abcbdc4b40ab6a.png",
"http://staging-teach.cdn.ireadabc.com/f40ce4a8630039c4cf48a63fc1399c52.png",
];
constructor(playerMaxNumber, networkHelper) {
......@@ -33,19 +42,20 @@ export class GameServer {
}
async addPlayer(player) {
console.log('addPlayer');
console.log("addPlayer");
this.playerList.push({
name: this.nameList.splice(0, 1)[0],
uuid: player.uuid,
color: player.uuid == this.networkHelper.room.roomInfo.owner ? 'Blue' : 'Red',
color:
player.uuid == this.networkHelper.room.roomInfo.owner ? "Blue" : "Red",
isAI: player.isAI,
headUrl: this.headUrls.splice(0, 1)[0]
headUrl: this.headUrls.splice(0, 1)[0],
});
await asyncDelay(1);
this.networkHelper.sendFrame({
type: 'SERVER_allPlayerInfo',
playerData: this.playerList
type: "SERVER_allPlayerInfo",
playerData: this.playerList,
});
if (this.playerList.length == this.playerMaxNumber) {
......@@ -59,83 +69,90 @@ export class GameServer {
gameStatus = {
Red: 0,
Blue: 0,
letter: '',
current: 'Blue'
letter: "",
current: "Blue",
};
startGame() {
this.networkHelper.sendFrame({
type: 'SERVER_updateStatus',
status: this.gameStatus
type: "SERVER_updateStatus",
status: this.gameStatus,
});
}
onPlayerJoin(event) {
this.addPlayer({
uuid: event.data.joinPlayerId,
isAI: false
isAI: false,
});
}
_aiPlayerList = [];
startMatch() {
for (let i = 0; i < this.playerMaxNumber; i++) {
this._timeoutIds.push(setTimeout(() => {
const count = this.playerMaxNumber - this.playerList.length;
if (count > 0) {
const playerInfo = {
uuid: 'ai_' + i,
isAI: true,
color: 'Red'
this._timeoutIds.push(
setTimeout(() => {
const count = this.playerMaxNumber - this.playerList.length;
if (count > 0) {
const playerInfo = {
uuid: "ai_" + i,
isAI: true,
color: "Red",
};
this._aiPlayerList.push(new AI(this.networkHelper, playerInfo));
this.addPlayer(playerInfo);
}
this._aiPlayerList.push(new AI(this.networkHelper, playerInfo));
this.addPlayer(playerInfo);
}
}, RandomInt(10000, 15000)));
}, RandomInt(10000, 15000))
);
}
}
onFrameEvent(data) {
if (data.type == 'roll') {
if (this.gameStatus.gameOver) {
return;
}
if (data.type == "roll") {
const letterList = this.getLetterList();
if (letterList.length > 0) {
const letter = letterList[RandomInt(letterList.length)];
this.gameStatus.letter = letter;
this.networkHelper.sendFrame({
type: 'SERVER_playerRoll',
letter: letter
type: "SERVER_playerRoll",
letter: letter,
});
} else {
this.networkHelper.sendFrame({
type: 'SERVER_playerWin',
color: this.gameStatus.current
type: "SERVER_playerWin",
color: this.gameStatus.current,
});
this.gameStatus.gameOver = true;
}
} else if (data.type == 'right') {
} else if (data.type == "right") {
this.gameStatus[data.color] = data.idx;
const letterList = this.getLetterList();
console.log('letterList = ' + JSON.stringify(letterList));
console.log("letterList = " + JSON.stringify(letterList));
if (letterList.length > 0) {
this.changeSide();
this.networkHelper.sendFrame({
type: 'SERVER_playerRight',
type: "SERVER_playerRight",
idx: data.idx,
uuid: data.uuid,
color: data.color
color: data.color,
});
} else {
this.networkHelper.sendFrame({
type: 'SERVER_playerWin',
color: this.gameStatus.current
type: "SERVER_playerWin",
color: this.gameStatus.current,
});
this.gameStatus.gameOver = true;
}
} else if (data.type == 'wrong') {
console.log('data = ' + JSON.stringify(data));
} else if (data.type == "wrong") {
console.log("data = " + JSON.stringify(data));
// this.gameStatus[data.color] = data.idx;
this.changeSide();
this.networkHelper.sendFrame({
type: 'SERVER_playerWrong',
type: "SERVER_playerWrong",
uuid: data.uuid,
color: data.color
color: data.color,
});
} else {
this._aiPlayerList.forEach((ai: AI) => {
......@@ -145,19 +162,19 @@ export class GameServer {
}
getLetterList() {
const board = cc.find('Canvas/bg/chessBoard/boardItems');
const board = cc.find("Canvas/bg/chessBoard/boardItems");
const color = this.gameStatus.current;
console.log("color = " + color);
console.log('this.gameStatus = ' + JSON.stringify(this.gameStatus));
console.log("this.gameStatus = " + JSON.stringify(this.gameStatus));
const startIdx = this.gameStatus[color];
console.log('startIdx = ' + startIdx);
console.log("startIdx = " + startIdx);
const letterList = [];
for (let i = startIdx + 1; i < board.children.length; i++) {
const targetNode = board.children[i];
const itemData = targetNode.getComponent('ItemData');
const itemData = targetNode.getComponent("ItemData");
const nodeLetter = itemData.letter.toUpperCase();
if (!letterList.find(letter => letter == nodeLetter)) {
if (!letterList.find((letter) => letter == nodeLetter)) {
letterList.push(nodeLetter);
}
}
......@@ -165,30 +182,28 @@ export class GameServer {
}
changeSide() {
if (this.gameStatus.current == 'Red') {
this.gameStatus.current = 'Blue';
if (this.gameStatus.current == "Red") {
this.gameStatus.current = "Blue";
} else {
this.gameStatus.current = 'Red';
this.gameStatus.current = "Red";
}
}
startAI() {
this.playerList
.filter(player => player.isAI == true)
.forEach(player => {
});
.filter((player) => player.isAI == true)
.forEach((player) => {});
}
_timeoutIds = null;
_intervalIds = null;
// 生命周期
onDestroy() {
this._timeoutIds.forEach(id => {
this._timeoutIds.forEach((id) => {
clearTimeout(id);
});
this._intervalIds.forEach(id => {
this._intervalIds.forEach((id) => {
clearInterval(id);
});
}
}
\ No newline at end of file
}
{
"ver": "2.3.5",
"uuid": "e1c1011c-37ad-47ab-b75c-0528fb58912e",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 584,
"height": 235,
"platformSettings": {},
"subMetas": {
"yourturn": {
"ver": "1.0.4",
"uuid": "eeb8a1d1-4858-4241-8733-38b1cff4c7cf",
"rawTextureUuid": "e1c1011c-37ad-47ab-b75c-0528fb58912e",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 584,
"height": 235,
"rawWidth": 584,
"rawHeight": 235,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
......@@ -616,6 +616,11 @@
"mime-types": "~2.1.24"
}
},
"typescript": {
"version": "4.5.5",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.5.tgz",
"integrity": "sha512-TCTIul70LyWe6IJWT8QSYeA54WQe8EjQFU4wY52Fasj5UKx88LNYKCgBEHcOMOrFF1rKGbD8v/xcNWVUq9SymA=="
},
"unpipe": {
"version": "1.0.0",
"resolved": "https://registry.npm.taobao.org/unpipe/download/unpipe-1.0.0.tgz",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment