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 @@ ...@@ -40,19 +40,22 @@
}, },
{ {
"__id__": 34 "__id__": 34
},
{
"__id__": 54
} }
], ],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 54 "__id__": 59
}, },
{ {
"__id__": 55 "__id__": 60
} }
], ],
"_prefab": { "_prefab": {
"__id__": 56 "__id__": 61
}, },
"_opacity": 255, "_opacity": 255,
"_color": { "_color": {
...@@ -1959,6 +1962,175 @@ ...@@ -1959,6 +1962,175 @@
"fileId": "f9qrJyDh5P1oErn3FfsNL7", "fileId": "f9qrJyDh5P1oErn3FfsNL7",
"sync": false "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", "__type__": "cc.Widget",
"_name": "", "_name": "",
......
...@@ -17,7 +17,10 @@ ...@@ -17,7 +17,10 @@
"__id__": 2 "__id__": 2
}, },
{ {
"__id__": 168 "__id__": 172
},
{
"__id__": 185
} }
], ],
"_active": false, "_active": false,
...@@ -81,19 +84,19 @@ ...@@ -81,19 +84,19 @@
"__id__": 7 "__id__": 7
}, },
{ {
"__id__": 151 "__id__": 154
} }
], ],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 165 "__id__": 169
}, },
{ {
"__id__": 166 "__id__": 170
}, },
{ {
"__id__": 167 "__id__": 171
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -354,19 +357,22 @@ ...@@ -354,19 +357,22 @@
"__id__": 112 "__id__": 112
}, },
{ {
"__id__": 126 "__id__": 127
}, },
{ {
"__id__": 141 "__id__": 142
}, },
{ {
"__id__": 148 "__id__": 149
},
{
"__id__": 151
} }
], ],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 150 "__id__": 153
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -4725,10 +4731,10 @@ ...@@ -4725,10 +4731,10 @@
"__id__": 121 "__id__": 121
}, },
{ {
"__id__": 122 "__id__": 123
}, },
{ {
"__id__": 124 "__id__": 125
} }
], ],
"_active": true, "_active": true,
...@@ -5162,7 +5168,11 @@ ...@@ -5162,7 +5168,11 @@
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [], "_components": [
{
"__id__": 122
}
],
"_prefab": null, "_prefab": null,
"_opacity": 255, "_opacity": 255,
"_color": { "_color": {
...@@ -5211,6 +5221,38 @@ ...@@ -5211,6 +5221,38 @@
"groupIndex": 0, "groupIndex": 0,
"_id": "0bfyX/nTdPJIpfRKUryv4/" "_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", "__type__": "cc.Node",
"_name": "faceBlue", "_name": "faceBlue",
...@@ -5222,7 +5264,7 @@ ...@@ -5222,7 +5264,7 @@
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 123 "__id__": 124
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -5278,7 +5320,7 @@ ...@@ -5278,7 +5320,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 122 "__id__": 123
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
...@@ -5316,7 +5358,7 @@ ...@@ -5316,7 +5358,7 @@
"_active": false, "_active": false,
"_components": [ "_components": [
{ {
"__id__": 125 "__id__": 126
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -5372,7 +5414,7 @@ ...@@ -5372,7 +5414,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 124 "__id__": 125
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
...@@ -5416,19 +5458,19 @@ ...@@ -5416,19 +5458,19 @@
}, },
"_children": [ "_children": [
{ {
"__id__": 127 "__id__": 128
}, },
{ {
"__id__": 133 "__id__": 134
}, },
{ {
"__id__": 135 "__id__": 136
}, },
{ {
"__id__": 137 "__id__": 138
}, },
{ {
"__id__": 139 "__id__": 140
} }
], ],
"_active": true, "_active": true,
...@@ -5486,17 +5528,17 @@ ...@@ -5486,17 +5528,17 @@
"_name": "life_red", "_name": "life_red",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 126 "__id__": 127
}, },
"_children": [ "_children": [
{ {
"__id__": 128 "__id__": 129
} }
], ],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 132 "__id__": 133
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -5552,17 +5594,17 @@ ...@@ -5552,17 +5594,17 @@
"_name": "mask", "_name": "mask",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 127 "__id__": 128
}, },
"_children": [ "_children": [
{ {
"__id__": 129 "__id__": 130
} }
], ],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 131 "__id__": 132
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -5618,13 +5660,13 @@ ...@@ -5618,13 +5660,13 @@
"_name": "prograssbar", "_name": "prograssbar",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 128 "__id__": 129
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 130 "__id__": 131
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -5680,7 +5722,7 @@ ...@@ -5680,7 +5722,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 129 "__id__": 130
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
...@@ -5712,7 +5754,7 @@ ...@@ -5712,7 +5754,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 128 "__id__": 129
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
...@@ -5732,7 +5774,7 @@ ...@@ -5732,7 +5774,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 127 "__id__": 128
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
...@@ -5764,13 +5806,13 @@ ...@@ -5764,13 +5806,13 @@
"_name": "dice_bg", "_name": "dice_bg",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 126 "__id__": 127
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 134 "__id__": 135
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -5826,7 +5868,7 @@ ...@@ -5826,7 +5868,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 133 "__id__": 134
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
...@@ -5858,13 +5900,13 @@ ...@@ -5858,13 +5900,13 @@
"_name": "faceFrame", "_name": "faceFrame",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 126 "__id__": 127
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 136 "__id__": 137
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -5920,7 +5962,7 @@ ...@@ -5920,7 +5962,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 135 "__id__": 136
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
...@@ -5952,13 +5994,13 @@ ...@@ -5952,13 +5994,13 @@
"_name": "faceRed", "_name": "faceRed",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 126 "__id__": 127
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 138 "__id__": 139
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -6014,7 +6056,7 @@ ...@@ -6014,7 +6056,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 137 "__id__": 138
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
...@@ -6046,13 +6088,13 @@ ...@@ -6046,13 +6088,13 @@
"_name": "effect", "_name": "effect",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 126 "__id__": 127
}, },
"_children": [], "_children": [],
"_active": false, "_active": false,
"_components": [ "_components": [
{ {
"__id__": 140 "__id__": 141
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -6108,7 +6150,7 @@ ...@@ -6108,7 +6150,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 139 "__id__": 140
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
...@@ -6152,13 +6194,13 @@ ...@@ -6152,13 +6194,13 @@
}, },
"_children": [ "_children": [
{ {
"__id__": 142 "__id__": 143
} }
], ],
"_active": false, "_active": false,
"_components": [ "_components": [
{ {
"__id__": 147 "__id__": 148
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -6214,20 +6256,20 @@ ...@@ -6214,20 +6256,20 @@
"_name": "Background", "_name": "Background",
"_objFlags": 512, "_objFlags": 512,
"_parent": { "_parent": {
"__id__": 141 "__id__": 142
}, },
"_children": [ "_children": [
{ {
"__id__": 143 "__id__": 144
} }
], ],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 145 "__id__": 146
}, },
{ {
"__id__": 146 "__id__": 147
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -6283,13 +6325,13 @@ ...@@ -6283,13 +6325,13 @@
"_name": "Label", "_name": "Label",
"_objFlags": 512, "_objFlags": 512,
"_parent": { "_parent": {
"__id__": 142 "__id__": 143
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 144 "__id__": 145
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -6345,7 +6387,7 @@ ...@@ -6345,7 +6387,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 143 "__id__": 144
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
...@@ -6378,7 +6420,7 @@ ...@@ -6378,7 +6420,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 142 "__id__": 143
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
...@@ -6410,7 +6452,7 @@ ...@@ -6410,7 +6452,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 142 "__id__": 143
}, },
"_enabled": true, "_enabled": true,
"alignMode": 0, "alignMode": 0,
...@@ -6437,7 +6479,7 @@ ...@@ -6437,7 +6479,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 141 "__id__": 142
}, },
"_enabled": true, "_enabled": true,
"_normalMaterial": null, "_normalMaterial": null,
...@@ -6510,7 +6552,7 @@ ...@@ -6510,7 +6552,7 @@
"__uuid__": "29158224-f8dd-4661-a796-1ffab537140e" "__uuid__": "29158224-f8dd-4661-a796-1ffab537140e"
}, },
"_N$target": { "_N$target": {
"__id__": 142 "__id__": 143
}, },
"_id": "72uh6FFMhPZJXe9I3tJ4Qt" "_id": "72uh6FFMhPZJXe9I3tJ4Qt"
}, },
...@@ -6525,7 +6567,7 @@ ...@@ -6525,7 +6567,7 @@
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 149 "__id__": 150
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -6581,7 +6623,7 @@ ...@@ -6581,7 +6623,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 148 "__id__": 149
}, },
"_enabled": true, "_enabled": true,
"alignMode": 2, "alignMode": 2,
...@@ -6603,6 +6645,100 @@ ...@@ -6603,6 +6645,100 @@
"_originalHeight": 0, "_originalHeight": 0,
"_id": "9fr0grwX5J57n69Cqpwnin" "_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", "__type__": "cc.Widget",
"_name": "", "_name": "",
...@@ -6639,13 +6775,19 @@ ...@@ -6639,13 +6775,19 @@
}, },
"_children": [ "_children": [
{ {
"__id__": 152 "__id__": 155
},
{
"__id__": 158
} }
], ],
"_active": true, "_active": false,
"_components": [ "_components": [
{ {
"__id__": 164 "__id__": 167
},
{
"__id__": 168
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -6701,20 +6843,16 @@ ...@@ -6701,20 +6843,16 @@
"_name": "bg", "_name": "bg",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 151 "__id__": 154
}, },
"_children": [ "_children": [],
{
"__id__": 153
}
],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 162 "__id__": 156
}, },
{ {
"__id__": 163 "__id__": 157
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -6766,27 +6904,86 @@ ...@@ -6766,27 +6904,86 @@
"_id": "9cjbtB0sNCsLMdza0zrJ8B" "_id": "9cjbtB0sNCsLMdza0zrJ8B"
}, },
{ {
"__type__": "cc.Node", "__type__": "cc.Sprite",
"_name": "bg", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "node": {
"__id__": 152 "__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, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 160 "__id__": 165
}, },
{ {
"__id__": 161 "__id__": 166
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -6842,16 +7039,16 @@ ...@@ -6842,16 +7039,16 @@
"_name": "labelLoss", "_name": "labelLoss",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 153 "__id__": 158
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 155 "__id__": 160
}, },
{ {
"__id__": 156 "__id__": 161
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -6907,7 +7104,7 @@ ...@@ -6907,7 +7104,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 154 "__id__": 159
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
...@@ -6939,7 +7136,7 @@ ...@@ -6939,7 +7136,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 154 "__id__": 159
}, },
"_enabled": true, "_enabled": true,
"alignMode": 1, "alignMode": 1,
...@@ -6966,16 +7163,16 @@ ...@@ -6966,16 +7163,16 @@
"_name": "labelWin", "_name": "labelWin",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 153 "__id__": 158
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 158 "__id__": 163
}, },
{ {
"__id__": 159 "__id__": 164
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -7031,7 +7228,7 @@ ...@@ -7031,7 +7228,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 157 "__id__": 162
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
...@@ -7063,7 +7260,7 @@ ...@@ -7063,7 +7260,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 157 "__id__": 162
}, },
"_enabled": true, "_enabled": true,
"alignMode": 1, "alignMode": 1,
...@@ -7090,7 +7287,7 @@ ...@@ -7090,7 +7287,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 153 "__id__": 158
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
...@@ -7122,7 +7319,7 @@ ...@@ -7122,7 +7319,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 153 "__id__": 158
}, },
"_enabled": true, "_enabled": true,
"alignMode": 2, "alignMode": 2,
...@@ -7144,44 +7341,12 @@ ...@@ -7144,44 +7341,12 @@
"_originalHeight": 0, "_originalHeight": 0,
"_id": "e8w4Lw+2VNObnuwPQ1d2O8" "_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", "__type__": "cc.Widget",
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 152 "__id__": 154
}, },
"_enabled": true, "_enabled": true,
"alignMode": 2, "alignMode": 2,
...@@ -7199,36 +7364,77 @@ ...@@ -7199,36 +7364,77 @@
"_isAbsBottom": true, "_isAbsBottom": true,
"_isAbsHorizontalCenter": true, "_isAbsHorizontalCenter": true,
"_isAbsVerticalCenter": true, "_isAbsVerticalCenter": true,
"_originalWidth": 100, "_originalWidth": 0,
"_originalHeight": 100, "_originalHeight": 0,
"_id": "3c8tUAlc9PQoBjysSDbTCd" "_id": "38i+Ag8ZBHWY+hWxjSeIa4"
}, },
{ {
"__type__": "cc.Widget", "__type__": "cc.Button",
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 151 "__id__": 154
}, },
"_enabled": true, "_enabled": true,
"alignMode": 2, "_normalMaterial": null,
"_target": null, "_grayMaterial": null,
"_alignFlags": 45, "duration": 0.1,
"_left": 0, "zoomScale": 1.2,
"_right": 0, "clickEvents": [],
"_top": 0, "_N$interactable": true,
"_bottom": 0, "_N$enableAutoGrayEffect": false,
"_verticalCenter": 0, "_N$transition": 0,
"_horizontalCenter": 0, "transition": 0,
"_isAbsLeft": true, "_N$normalColor": {
"_isAbsRight": true, "__type__": "cc.Color",
"_isAbsTop": true, "r": 255,
"_isAbsBottom": true, "g": 255,
"_isAbsHorizontalCenter": true, "b": 255,
"_isAbsVerticalCenter": true, "a": 255
"_originalWidth": 0, },
"_originalHeight": 0, "_N$pressedColor": {
"_id": "38i+Ag8ZBHWY+hWxjSeIa4" "__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", "__type__": "cc.Canvas",
...@@ -7295,12 +7501,6 @@ ...@@ -7295,12 +7501,6 @@
"__id__": 1 "__id__": 1
}, },
"_children": [ "_children": [
{
"__id__": 169
},
{
"__id__": 171
},
{ {
"__id__": 173 "__id__": 173
}, },
...@@ -7312,6 +7512,12 @@ ...@@ -7312,6 +7512,12 @@
}, },
{ {
"__id__": 179 "__id__": 179
},
{
"__id__": 181
},
{
"__id__": 183
} }
], ],
"_active": true, "_active": true,
...@@ -7369,13 +7575,13 @@ ...@@ -7369,13 +7575,13 @@
"_name": "落子", "_name": "落子",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 168 "__id__": 172
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 170 "__id__": 174
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -7431,7 +7637,7 @@ ...@@ -7431,7 +7637,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 169 "__id__": 173
}, },
"_enabled": true, "_enabled": true,
"_clip": { "_clip": {
...@@ -7450,13 +7656,13 @@ ...@@ -7450,13 +7656,13 @@
"_name": "正确", "_name": "正确",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 168 "__id__": 172
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 172 "__id__": 176
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -7512,7 +7718,7 @@ ...@@ -7512,7 +7718,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 171 "__id__": 175
}, },
"_enabled": true, "_enabled": true,
"_clip": { "_clip": {
...@@ -7531,13 +7737,13 @@ ...@@ -7531,13 +7737,13 @@
"_name": "失败", "_name": "失败",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 168 "__id__": 172
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 174 "__id__": 178
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -7593,7 +7799,7 @@ ...@@ -7593,7 +7799,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 173 "__id__": 177
}, },
"_enabled": true, "_enabled": true,
"_clip": { "_clip": {
...@@ -7612,13 +7818,13 @@ ...@@ -7612,13 +7818,13 @@
"_name": "错误弹回", "_name": "错误弹回",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 168 "__id__": 172
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 176 "__id__": 180
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -7674,7 +7880,7 @@ ...@@ -7674,7 +7880,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 175 "__id__": 179
}, },
"_enabled": true, "_enabled": true,
"_clip": { "_clip": {
...@@ -7693,13 +7899,13 @@ ...@@ -7693,13 +7899,13 @@
"_name": "进度条升高", "_name": "进度条升高",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 168 "__id__": 172
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 178 "__id__": 182
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -7755,7 +7961,7 @@ ...@@ -7755,7 +7961,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 177 "__id__": 181
}, },
"_enabled": true, "_enabled": true,
"_clip": { "_clip": {
...@@ -7774,13 +7980,13 @@ ...@@ -7774,13 +7980,13 @@
"_name": "胜利", "_name": "胜利",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 168 "__id__": 172
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 180 "__id__": 184
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -7836,7 +8042,7 @@ ...@@ -7836,7 +8042,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 179 "__id__": 183
}, },
"_enabled": true, "_enabled": true,
"_clip": { "_clip": {
...@@ -7849,5 +8055,258 @@ ...@@ -7849,5 +8055,258 @@
"playOnLoad": false, "playOnLoad": false,
"preload": false, "preload": false,
"_id": "dbccc2jl1Lw6v0V1Jts0W8" "_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 { MyCocosSceneComponent } from "../script/MyCocosSceneComponent";
import { NetworkHelper } from "../script/NetworkHelper"; import { NetworkHelper } from "../script/NetworkHelper";
import { GameServer } from "../script/Server"; import { GameServer } from "../script/Server";
...@@ -7,671 +13,865 @@ const { ccclass, property } = cc._decorator; ...@@ -7,671 +13,865 @@ const { ccclass, property } = cc._decorator;
@ccclass @ccclass
export default class SceneComponent extends MyCocosSceneComponent { export default class SceneComponent extends MyCocosSceneComponent {
@property(cc.Prefab)
@property(cc.Prefab) loadingLayerPrefab = null;
loadingLayerPrefab = null;
addPreloadImage() {
addPreloadImage() { // TODO 根据自己的配置预加载图片资源
// TODO 根据自己的配置预加载图片资源 // this._imageResList.push({ url: this.data.pic_url });
// this._imageResList.push({ url: this.data.pic_url }); }
}
addPreloadAudio() {
addPreloadAudio() { // TODO 根据自己的配置预加载音频资源
// TODO 根据自己的配置预加载音频资源 this._audioResList.push({ url: this.data.gameStartAudio });
this._audioResList.push({ url: this.data.gameStartAudio }); this._audioResList.push({ url: this.data.gameLoadingAudio });
this._audioResList.push({ url: this.data.gameLoadingAudio }); this._audioResList.push({ url: this.data.waitingWheel });
this._audioResList.push({ url: this.data.waitingWheel }); this._audioResList.push({ url: this.data.waitingPiece });
this._audioResList.push({ url: this.data.waitingPiece }); this._audioResList.push({ url: this.data.waitingTurn });
this._audioResList.push({ url: this.data.waitingTurn }); }
}
addPreloadAnima() {}
addPreloadAnima() {
onLoadEnd() {
} // TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考
this.initData();
onLoadEnd() { this.initView();
// TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考 this.initListener();
this.initData(); }
this.initView();
this.initListener(); _status = {
} Red: 0,
Blue: 0,
_status = { letter: "",
Red: 0, current: "Blue",
Blue: 0, };
letter: '', playerId;
current: 'Blue' isRoomOwner;
}; server: GameServer;
playerId; networkHelper: NetworkHelper;
isRoomOwner; async initData() {
server: GameServer; this.networkHelper = new NetworkHelper();
networkHelper: NetworkHelper; this.initNetworkListener();
async initData() { do {
this.networkHelper = new NetworkHelper(); this.playerId = await this.networkHelper.init("op_16", 2);
if (this.playerId === null) {
this.initNetworkListener(); console.log("onDestroy");
this.networkHelper.onDestroy();
this.playerId = await this.networkHelper.init('op_16', 2); }
console.log("this.playerId = " + this.playerId);
const room = this.networkHelper.room; } while (this.playerId === null);
if (this.playerId == room.roomInfo.owner) {
console.log('房主'); const room = this.networkHelper.room;
this.isRoomOwner = true; if (this.playerId == room.roomInfo.owner) {
this.server = new GameServer(2, this.networkHelper); console.log("房主");
await this.networkHelper.startFrameSync(); this.isRoomOwner = true;
this.server.addPlayer({ this.server = new GameServer(2, this.networkHelper);
uuid: this.playerId, await this.networkHelper.startFrameSync();
isAI: false this.server.addPlayer({
}); uuid: this.playerId,
this.server.startMatch(); isAI: false,
} });
} this.server.startMatch();
}
initView() { }
this.initBg();
this.initLoadingLayer(); initView() {
this.initPiece(); this.initBg();
} this.initLoadingLayer();
this.initPiece();
initBg() { }
const canvas = cc.find('Canvas');
const bgImg = cc.find('Canvas/bgImg'); initBg() {
bgImg.scale = Math.max(canvas.width / bgImg.width, canvas.height / bgImg.height); const canvas = cc.find("Canvas");
const bgImg = cc.find("Canvas/bgImg");
const bg = cc.find('Canvas/bg'); bgImg.scale = Math.max(
bg.scale = Math.min(canvas.width / bg.width, canvas.height / bg.height); canvas.width / bgImg.width,
canvas.height / bgImg.height
const chessBoardBg = cc.find('Canvas/bg/chessBoard/bg'); );
const offsetX = chessBoardBg.width * chessBoardBg.scaleX / 2 + (canvas.width - chessBoardBg.width * chessBoardBg.scaleX) / 4; const bg = cc.find("Canvas/bg");
const lifeblue = cc.find('Canvas/bg/Lifeblue'); bg.scale = Math.min(canvas.width / bg.width, canvas.height / bg.height);
lifeblue.x = -offsetX;
const lifered = cc.find('Canvas/bg/Lifered'); const chessBoardBg = cc.find("Canvas/bg/chessBoard/bg");
lifered.x = offsetX;
} const offsetX =
(chessBoardBg.width * chessBoardBg.scaleX) / 2 +
loadingLayer; (canvas.width - chessBoardBg.width * chessBoardBg.scaleX) / 4;
initLoadingLayer() { const lifeblue = cc.find("Canvas/bg/Lifeblue");
const loadingLayerBase = cc.find('Canvas/bg/loadingLayerBase'); lifeblue.x = -offsetX;
const lifered = cc.find("Canvas/bg/Lifered");
const loadingLayerNode = cc.instantiate(this.loadingLayerPrefab); lifered.x = offsetX;
loadingLayerBase.addChild(loadingLayerNode); }
this.loadingLayer = loadingLayerNode.getComponent('LoadingLayer'); loadingLayer;
this.loadingLayer.setMaxPlayerNumber(2); initLoadingLayer() {
this.loadingLayer.onLoadFinished(() => { const loadingLayerBase = cc.find("Canvas/bg/loadingLayerBase");
this.playAudioByUrl(this.data.gameStartAudio);
}); const loadingLayerNode = cc.instantiate(this.loadingLayerPrefab);
loadingLayerBase.addChild(loadingLayerNode);
this.playAudioByUrl(this.data.gameLoadingAudio);
} this.loadingLayer = loadingLayerNode.getComponent("LoadingLayer");
this.loadingLayer.setMaxPlayerNumber(2);
blinkTheDice() { this.loadingLayer.onLoadFinished(() => {
const dice = cc.find('Canvas/bg/chessBoard/diceBg/hatBlink'); this.playAudioByUrl(this.data.gameStartAudio);
cc.tween(dice) });
.set({ opacity: 0 })
.to(0.3, { opacity: 255 }) this.playAudioByUrl(this.data.gameLoadingAudio);
.to(0.3, { opacity: 0 }) }
.union()
.repeatForever() blinkTheDice() {
.start(); const dice = cc.find("Canvas/bg/chessBoard/diceBg/hatBlink");
} cc.tween(dice)
.set({ opacity: 0 })
stopBlinkTheDice() { .to(0.2, { opacity: 255 })
const dice = cc.find('Canvas/bg/chessBoard/diceBg/hatBlink'); .to(0.2, { opacity: 0 })
dice.stopAllActions(); .union()
} .repeatForever()
.start();
greyDice() {
const dice = cc.find('Canvas/bg/chessBoard/diceBg/dice'); cc.find("Canvas/bg/chessBoard/diceBg").children.forEach((node) => {
dice.color = cc.color(150, 150, 150); cc.tween(node)
} .set({ scale: 1 })
.to(0.2, { scale: 1.1 })
stopGreyDice() { .to(0.2, { scale: 1.0 })
const dice = cc.find('Canvas/bg/chessBoard/diceBg/dice'); .union()
dice.color = cc.color(255, 255, 255); .repeatForever()
} .start();
});
initPiece() {
const offsetX = { Red: -45, Blue: 45 }; const dice = cc.find("Canvas/bg/chessBoard/diceBg/dice");
const offsetY = { Red: -90, Blue: -90 }; dice["canClick"] = true;
const board = cc.find('Canvas/bg/chessBoard/boardItems'); }
const pieceNodeRed = cc.find(`Canvas/bg/chessBoard/pieceRed`) stopBlinkTheDice() {
const startIdxRed = this._status['Red']; const dice = cc.find("Canvas/bg/chessBoard/diceBg/hatBlink");
const boardNodeRed = board.children[startIdxRed]; dice.stopAllActions();
pieceNodeRed.x = boardNodeRed.x + offsetX.Red; cc.find("Canvas/bg/chessBoard/diceBg").children.forEach((node) => {
pieceNodeRed.y = boardNodeRed.y + offsetY.Red; node.stopAllActions();
node.scale = 1;
const pieceNodeBlue = cc.find(`Canvas/bg/chessBoard/pieceBlue`) node.opacity = 255;
const startIdxBlue = this._status['Blue']; });
const boardNodeBlue = board.children[startIdxBlue]; const dice = cc.find("Canvas/bg/chessBoard/diceBg/dice");
pieceNodeBlue.x = boardNodeBlue.x + offsetX.Blue; dice["canClick"] = false;
pieceNodeBlue.y = boardNodeBlue.y + offsetY.Blue; }
}
greyDice() {
initListener() { cc.find("Canvas/bg/chessBoard/diceBg").children.forEach((node) => {
const btn = cc.find('Canvas/bg/New Button'); node.color = cc.color(150, 150, 150);
btn.on('click', async () => { });
const idx = RandomInt(6); }
await this.rollTheDice(idx);
this._status.letter = ['A', 'B', 'C', 'D', 'E', 'F'][idx]; stopGreyDice() {
}); cc.find("Canvas/bg/chessBoard/diceBg").children.forEach((node) => {
node.color = cc.color(255, 255, 255);
const dice = cc.find('Canvas/bg/chessBoard/diceBg/dice'); });
dice.on('click', () => { }
if (this._status.letter != '') {
return; initPiece() {
} const offsetX = { Red: -45, Blue: 45 };
const playerMe = this.allPlayerList.find(player => player.uuid == this.playerId); const offsetY = { Red: -90, Blue: -90 };
const board = cc.find("Canvas/bg/chessBoard/boardItems");
if (this._status.current == playerMe.color) {
this.networkHelper.sendFrame({ const pieceNodeRed = cc.find(`Canvas/bg/chessBoard/pieceRed`);
type: 'roll', const startIdxRed = this._status["Red"];
uuid: playerMe.uuid 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 pieceBlue = cc.find('Canvas/bg/chessBoard/pieceBlue'); const startIdxBlue = this._status["Blue"];
this.addPieceTouchEventListener(pieceBlue, 'Blue'); const boardNodeBlue = board.children[startIdxBlue];
pieceNodeBlue.x = boardNodeBlue.x + offsetX.Blue;
const pieceRed = cc.find('Canvas/bg/chessBoard/pieceRed'); pieceNodeBlue.y = boardNodeBlue.y + offsetY.Blue;
this.addPieceTouchEventListener(pieceRed, 'Red'); }
const coolCat = cc.find('Canvas/bg/tree/catBase/cat'); initListener() {
const catBtn = cc.find('Canvas/bg/tree/catBase/catBtn'); const btn = cc.find("Canvas/bg/New Button");
catBtn.on('click', async () => { btn.on("click", async () => {
asyncPlayDragonBoneAnimation(coolCat, 'begin'); const idx = RandomInt(6);
const playerMe = this.allPlayerList.find(player => player.uuid == this.playerId); await this.rollTheDice(idx);
if (playerMe.color == this._status.current) { console.log("汪汪汪 194");
if (this._status.letter == '') { this._status.letter = ["A", "B", "C", "D", "E", "F"][idx];
await this.playAudioByUrl(this.data.waitingWheel); });
} else {
await this.playAudioByUrl(this.data.waitingPiece); const dice = cc.find("Canvas/bg/chessBoard/diceBg/dice");
} dice.on("click", () => {
} else { if (this._status.letter != "") {
await this.playAudioByUrl(this.data.waitingTurn); return;
} }
asyncPlayDragonBoneAnimation(coolCat, 'normal'); if (!dice["canClick"]) {
}); return;
} }
const playerMe = this.allPlayerList.find(
addPieceTouchEventListener(node: cc.Node, color) { (player) => player.uuid == this.playerId
);
node.on(cc.Node.EventType.TOUCH_START, (event: cc.Event.EventTouch) => {
const playerMe = this.allPlayerList.find(player => player.uuid == this.playerId); if (this._status.current == playerMe.color) {
if (playerMe.color != this._status.current) { this.networkHelper.sendFrame({
this.blinkPiece(node); type: "roll",
return; uuid: playerMe.uuid,
}
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
};
}); });
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; const pieceBlue = cc.find("Canvas/bg/chessBoard/pieceBlue");
} this.addPieceTouchEventListener(pieceBlue, "Blue");
if (this._status.current != color) {
return; const pieceRed = cc.find("Canvas/bg/chessBoard/pieceRed");
} this.addPieceTouchEventListener(pieceRed, "Red");
if (this._status.letter == '') {
return; const coolCat = cc.find("Canvas/bg/tree/catBase/cat");
} const catBtn = cc.find("Canvas/bg/tree/catBase/catBtn");
if (node['cantMove']) { catBtn.on("click", async () => {
return; asyncPlayDragonBoneAnimation(coolCat, "begin");
} const playerMe = this.allPlayerList.find(
const pos = event.getLocation(); (player) => player.uuid == this.playerId
const touchStartPos = node['touchStartPos']; );
const worldNodePos = node.parent.convertToWorldSpaceAR(cc.v2(touchStartPos.nodeX, touchStartPos.nodeY)); if (playerMe.color == this._status.current) {
const nodePos = node.parent.convertToNodeSpaceAR(cc.v2( if (this._status.letter == "") {
worldNodePos.x + pos.x - touchStartPos.touchX, await this.playAudioByUrl(this.data.waitingWheel);
worldNodePos.y + pos.y - touchStartPos.touchY, } else {
)) await this.playAudioByUrl(this.data.waitingPiece);
node.setPosition(nodePos); }
} 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) => { } else {
const playerMe = this.allPlayerList.find(player => player.uuid == this.playerId); node["cantMove"] = true;
if (playerMe.color != this._status.current) { const playerMe = this.allPlayerList.find(
return; (player) => player.uuid == this.playerId
} );
if (this._status.current != color) { this.networkHelper.sendFrame({
return; type: "wrong",
} uuid: playerMe.uuid,
if (this._status.letter == '') { color: playerMe.color,
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
});
}
}); });
} }
});
blinkPiece(node) { }
node.stopAllActions();
cc.tween(node) blinkPiece(node) {
.set({ scale: 1 }) node.stopAllActions();
.to(0.05, { scale: 1.05 }) cc.tween(node)
.to(0.05, { scale: 1 }) .set({ scale: 1 })
.start(); .to(0.05, { scale: 1.05 })
} .to(0.05, { scale: 1 })
.start();
rollPiece(node: cc.Node) { }
node.stopAllActions();
cc.tween(node) rollPiece(node: cc.Node) {
.set({ scale: 1, angle: 0 }) node.stopAllActions();
.to(0.1, { angle: -10 }) cc.tween(node)
.to(0.2, { angle: 10 }) .set({ scale: 1, angle: 0 })
.to(0.1, { angle: 0 }) .to(0.1, { angle: -10 })
.delay(1) .to(0.2, { angle: 10 })
.union() .to(0.1, { angle: 0 })
.repeatForever() .delay(1)
.start(); .union()
.repeatForever()
const board = cc.find('Canvas/bg/chessBoard/boardItems'); .start();
board.children.forEach((child: cc.Node, idx, list) => {
cc.tween(child) const board = cc.find("Canvas/bg/chessBoard/boardItems");
.set({ scale: 1.34 }) board.children.forEach((child: cc.Node, idx, list) => {
.delay(idx * 0.1) cc.tween(child)
.to(0.1, { scale: 1.5 }) .set({ scale: 1.34 })
.to(0.1, { scale: 1.34 }) .delay(idx * 0.1)
.delay(list.length * 0.2 - idx * 0.2) .to(0.1, { scale: 1.5 })
.start(); .to(0.1, { scale: 1.34 })
}); .delay(list.length * 0.2 - idx * 0.2)
} .start();
stopRollPiece(node) { });
node.scale = 1; }
node.angle = 0; stopRollPiece(node) {
node.stopAllActions(); node.scale = 1;
} node.angle = 0;
rollPieceOnce(node: cc.Node) { node.stopAllActions();
node.stopAllActions(); }
cc.tween(node) rollPieceOnce(node: cc.Node) {
.set({ scale: 1, angle: 0 }) node.stopAllActions();
.to(0.1, { angle: -10 }) cc.tween(node)
.to(0.2, { angle: 10 }) .set({ scale: 1, angle: 0 })
.to(0.1, { angle: 0 }) .to(0.1, { angle: -10 })
.start(); .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]; getRightBlock() {
for (let i = startIdx + 1; i < board.children.length; i++) { const board = cc.find("Canvas/bg/chessBoard/boardItems");
const targetNode = board.children[i]; const startIdx = this._status[this._status.current];
const itemData = targetNode.getComponent('ItemData'); console.log("startIdx = " + JSON.stringify(startIdx));
for (let i = startIdx + 1; i < board.children.length; i++) {
if (itemData.letter.toLowerCase() == this._status.letter.toLowerCase()) { const targetNode = board.children[i];
return targetNode; 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; return false;
} }
}
getNextRightIdx() { return false;
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++) { showStars(node) {
const targetNode = board.children[i]; cc.tween(node)
const itemData = targetNode.getComponent('ItemData'); .delay(0.07)
if (itemData.letter.toLowerCase() == this._status.letter.toLowerCase()) { .call(() => {
return i; 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 (item.data.type == "SERVER_allPlayerInfo") {
if (targetNode.getBoundingBox().intersects(node.getBoundingBox())) { console.log(
return true; "SERVER_allPlayerInfo: " + JSON.stringify(item.data.playerData)
} );
return false 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 (
if (status) { !this.allPlayerList.find(
this._status = status; (listPlayer) => listPlayer.uuid == player.uuid
} )
const playerMe = this.allPlayerList.find(player => player.uuid == this.playerId); ) {
if (playerMe.color == this._status.current) { this.allPlayerList.push({
this.stopGreyDice(); uuid: player.uuid,
if (this._status.letter == '') { name: player.name,
this.blinkTheDice(); color: player.color,
} else { headUrl: player.headUrl,
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() { this.loadPlayerHeadImage();
if (this._status.current == 'Red') {
return cc.find('Canvas/bg/chessBoard/pieceRed'); this.loadingLayer.addPlayer(
} else { player.name,
return cc.find('Canvas/bg/chessBoard/pieceBlue'); 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 { } else {
this._status.current = 'Red'; blue.getComponent(cc.Sprite).spriteFrame = sf;
}
}
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' }); }
}
async movePiece(letter, color) {
allPlayerList; const offsetX = { Red: -45, Blue: 45 };
initNetworkListener() { const offsetY = { Red: -90, Blue: -90 };
this.networkHelper.on('playerJoin', (event) => { const pieceNode = cc.find(`Canvas/bg/chessBoard/piece${color}`);
if (this.server) { const board = cc.find("Canvas/bg/chessBoard/boardItems");
this.server.onPlayerJoin(event); const startIdx = this._status[color];
}
cc.log("playerJoin" + JSON.stringify(event)); for (let i = startIdx + 1; i < board.children.length; i++) {
}); const targetNode = board.children[i];
this.networkHelper.on('playerLeave', (event) => { const itemData = targetNode.getComponent("ItemData");
cc.log("playerLeave" + JSON.stringify(event));
}); const prograssbar = cc.find(
this.networkHelper.on('gameStart', (event) => { `Canvas/bg/Life${color.toLowerCase()}/life_${color.toLowerCase()}/mask/prograssbar`
);
}); const mask = cc.find(
this.networkHelper.on('frameEvent', (event) => { `Canvas/bg/Life${color.toLowerCase()}/life_${color.toLowerCase()}/mask`
event.data.frame.items.forEach(async item => { );
if (this.server) { const targetHeight = (i / board.children.length) * prograssbar.height;
this.server.onFrameEvent(item.data); cc.tween(mask)
} .to(1, { height: targetHeight }, { easing: "cubicInOut" })
.start();
if (item.data.type == 'SERVER_allPlayerInfo') {
console.log('SERVER_allPlayerInfo: ' + JSON.stringify(item.data.playerData)); await asyncTweenTo(
item.data.playerData.forEach(player => { pieceNode,
if (!this.allPlayerList) { 1,
this.allPlayerList = []; {
} x: targetNode.x + offsetX[color],
y: targetNode.y + offsetY[color],
if (!this.allPlayerList.find(listPlayer => listPlayer.uuid == player.uuid)) { },
this.allPlayerList.push({ { easing: "cubicInOut" }
uuid: player.uuid, );
name: player.name,
color: player.color, if (itemData.letter.toLowerCase() == letter.toLowerCase()) {
headUrl: player.headUrl this._status[color] = i;
}); console.log("汪汪汪 784");
}
return;
this.loadPlayerHeadImage(); }
}
this.loadingLayer.addPlayer( this.finish();
player.name, }
player.uuid == this.playerId,
player.headUrl, finish() {
player.uuid onHomeworkFinish();
); }
})
} else if (item.data.type == 'SERVER_updateStatus') { rollTheDice(num) {
console.log('SERVER_updateStatus: ' + JSON.stringify(item.data.status)); const dice = cc.find("Canvas/bg/chessBoard/diceBg/dice");
this.updateStatus(item.data.status); if (dice["cantRoll"]) {
} else if (item.data.type == 'SERVER_playerRoll') { return;
console.log('SERVER_playerRoll: ' + JSON.stringify(item.data)); }
const status = this._status; return new Promise((resolve, reject) => {
status.letter = item.data.letter; const targetAngle = Math.ceil(dice.angle / 360 + 1) * 360;
const idx = ['A', 'B', 'C', 'D', 'E', 'F'].findIndex(letter => letter == status.letter); const time = (targetAngle - 360 - dice.angle) / 360;
await this.rollTheDice(idx);
this.updateStatus(status); dice["cantRoll"] = true;
} else if (item.data.type == 'SERVER_playerRight') {
console.log('SERVER_playerRight: ' + JSON.stringify(item.data)); cc.tween(dice)
const rightBlock = this.getRightBlock(); .by(3, { angle: 360 }, { easing: "cubicIn" })
const idx = this.getNextRightIdx(); .to(time, { angle: targetAngle })
this.pieceFindRightBlock(rightBlock, idx); .by(1, { angle: 360 })
this._status.letter = ''; .by(1, { angle: 360 })
this.changeSide(); .by(1, { angle: 360 })
this.updateStatus(); .by(1, { angle: 360 })
} else if (item.data.type == 'SERVER_playerWrong') { .by((1 / 6) * num, { angle: 60 * num })
console.log('SERVER_playerWrong: ' + JSON.stringify(item.data)); .by(3, { angle: 360 }, { easing: "cubicOut" })
const node = cc.find(`Canvas/bg/chessBoard/piece${this._status.current}`); .call(() => {
dice["cantRoll"] = false;
const playerMe = this.allPlayerList.find(player => player.uuid == this.playerId); resolve(null);
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);
});
}) })
} .start();
});
// 生命周期 }
onDestroy() {
this.networkHelper.onDestroy(); 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 { ...@@ -7,8 +7,8 @@ export class AI {
_status = { _status = {
Red: 0, Red: 0,
Blue: 0, Blue: 0,
letter: '', letter: "",
current: 'Blue' current: "Blue",
}; };
constructor(networkHelper: NetworkHelper, playerData: any) { constructor(networkHelper: NetworkHelper, playerData: any) {
...@@ -17,44 +17,47 @@ export class AI { ...@@ -17,44 +17,47 @@ export class AI {
} }
async onFrameEvent(event) { async onFrameEvent(event) {
console.log('AI get event: ' + JSON.stringify(event)); console.log("AI get event: " + JSON.stringify(event));
if (event.type == 'SERVER_updateStatus') { if (event.type == "SERVER_updateStatus") {
this._status = JSON.parse(JSON.stringify(event.status)); 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; this._status.letter = event.letter;
if (this.playerData.color == this._status.current) { 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') { } else if (event.type == "SERVER_playerRight") {
this._status.letter = ''; console.log('汪汪汪1');
this._status.letter = "";
this._status[event.color] = event.idx; this._status[event.color] = event.idx;
this.changeSide(); this.changeSide();
} else if (event.type == 'SERVER_playerWrong') { } else if (event.type == "SERVER_playerWrong") {
this._status.letter = ''; console.log('汪汪汪2');
this._status.letter = "";
this.changeSide(); this.changeSide();
} }
if (this.playerData.color == this._status.current) { if (this.playerData.color == this._status.current) {
await asyncDelay(Math.random() * 3 + 2); await asyncDelay(Math.random() * 3 + 4);
if (this._status.letter == '') { if (this._status.letter == "") {
this.networkHelper.sendFrame({ this.networkHelper.sendFrame({
type: 'roll', type: "roll",
uuid: this.playerData.uuid uuid: this.playerData.uuid,
}); });
} else { } else {
const idx = this.getNextRightIdx(); const idx = this.getNextRightIdx();
if (Math.random() > 0.5) { if (Math.random() < 0.9) {
this.networkHelper.sendFrame({ this.networkHelper.sendFrame({
type: 'right', type: "right",
idx: idx, idx: idx,
uuid: this.playerData.uuid, uuid: this.playerData.uuid,
color: this.playerData.color color: this.playerData.color,
}); });
} else { } else {
this.networkHelper.sendFrame({ this.networkHelper.sendFrame({
type: 'wrong', type: "wrong",
uuid: this.playerData.uuid, uuid: this.playerData.uuid,
color: this.playerData.color color: this.playerData.color,
}); });
} }
} }
...@@ -62,23 +65,23 @@ export class AI { ...@@ -62,23 +65,23 @@ export class AI {
} }
changeSide() { changeSide() {
if (this._status.current == 'Red') { if (this._status.current == "Red") {
this._status.current = 'Blue'; this._status.current = "Blue";
} else { } else {
this._status.current = 'Red'; this._status.current = "Red";
} }
} }
getNextRightIdx() { getNextRightIdx() {
const board = cc.find('Canvas/bg/chessBoard/boardItems'); const board = cc.find("Canvas/bg/chessBoard/boardItems");
const startIdx = this._status[this._status.current]; const startIdx = this._status[this._status.current];
for (let i = startIdx + 1; i < board.children.length; i++) { for (let i = startIdx + 1; i < board.children.length; i++) {
const targetNode = board.children[i]; const targetNode = board.children[i];
const itemData = targetNode.getComponent('ItemData'); const itemData = targetNode.getComponent("ItemData");
if (itemData.letter.toLowerCase() == this._status.letter.toLowerCase()) { if (itemData.letter.toLowerCase() == this._status.letter.toLowerCase()) {
return i; return i;
} }
} }
return -1; return -1;
} }
} }
\ No newline at end of file
...@@ -97,6 +97,7 @@ export default class SceneComponent extends cc.Component { ...@@ -97,6 +97,7 @@ export default class SceneComponent extends cc.Component {
cc.find('right', this.node).addChild(headNode); cc.find('right', this.node).addChild(headNode);
const vs = cc.find('vs', this.node); const vs = cc.find('vs', this.node);
asyncPlayDragonBoneAnimation(vs, 'normal', 1); asyncPlayDragonBoneAnimation(vs, 'normal', 1);
this.playLocalAudio('match');
} }
const rate = Math.min(1, this._playerList.length / this._maxPlayerNum); const rate = Math.min(1, this._playerList.length / this._maxPlayerNum);
...@@ -231,6 +232,25 @@ export default class SceneComponent extends cc.Component { ...@@ -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 = []; _timeoutIds = [];
_intervalIds = []; _intervalIds = [];
// 生命周期 // 生命周期
......
import { Base64 } from "js-base64"; import { Base64 } from "js-base64";
export class NetworkHelper { export class NetworkHelper {
_eventListeners: any = {}; _eventListeners: any = {};
ctor() { } ctor() {}
on(eventName, func) { on(eventName, func) {
this._eventListeners[eventName] = func; this._eventListeners[eventName] = func;
} }
async init(roomType: string, maxPlayers: number) { async init(roomType: string, maxPlayers: number) {
this.initRoom();
try { try {
return await this.joinRoom(roomType, maxPlayers);
} catch (e) {
await this.initListener();
this.initRoom(); this.initRoom();
await this.initListener();
return await this.joinRoom(roomType, maxPlayers); return await this.joinRoom(roomType, maxPlayers);
} catch (e) {
// return null;
} }
} }
...@@ -28,6 +25,7 @@ export class NetworkHelper { ...@@ -28,6 +25,7 @@ export class NetworkHelper {
async stopGame() { async stopGame() {
await this.stopFrameSync(); await this.stopFrameSync();
await this.closeRoom();
await this.leaveRoom(); await this.leaveRoom();
} }
...@@ -35,7 +33,14 @@ export class NetworkHelper { ...@@ -35,7 +33,14 @@ export class NetworkHelper {
return this.room.roomInfo; return this.room.roomInfo;
} }
listenerInited = false;
initListener() { initListener() {
if (this.listenerInited) {
return;
}
// MGOBE.Listener;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const gameId = "obg-i4ql53h1"; //替换为控制台上的 游戏 ID const gameId = "obg-i4ql53h1"; //替换为控制台上的 游戏 ID
const openId = "openid_op_16" + Math.random(); const openId = "openid_op_16" + Math.random();
...@@ -44,50 +49,58 @@ export class NetworkHelper { ...@@ -44,50 +49,58 @@ export class NetworkHelper {
gameId: gameId, gameId: gameId,
openId: openId, openId: openId,
createSignature: (callback) => { createSignature: (callback) => {
this.callNetworkApiGet('http://staging-teach.ireadabc.com', '/api/oxford/game/v1/config', { this.callNetworkApiGet(
gameid: gameId, "http://staging-teach.ireadabc.com",
openid: openId, "/api/oxford/game/v1/config",
}, (data) => { {
callback(JSON.parse(data)); gameid: gameId,
}); openid: openId,
} },
(data) => {
callback(JSON.parse(data));
}
);
},
}; };
const serverUrl = "i4ql53h1.wxlagame.com"; //替换为控制台上的 域名 const serverUrl = "i4ql53h1.wxlagame.com"; //替换为控制台上的 域名
const config = { const config = {
url: serverUrl, url: serverUrl,
reconnectMaxTimes: 5, reconnectMaxTimes: 3,
reconnectInterval: 1000, reconnectInterval: 1000,
resendInterval: 1000, resendInterval: 1000,
resendTimeout: 10000, resendTimeout: 5000,
cacertNativeUrl: "" cacertNativeUrl: "",
}; };
MGOBE.DebuggerLog.enable = false; MGOBE.DebuggerLog.enable = false;
// 如果是原生平台,则加载 Cert 证书,否则会提示 WSS 错误 // 如果是原生平台,则加载 Cert 证书,否则会提示 WSS 错误
if (cc.sys.isNative) { if (cc.sys.isNative) {
let cacertFile; let cacertFile;
const cacertNode = cc.find('cacertNode'); const cacertNode = cc.find("cacertNode");
if (cacertNode) { if (cacertNode) {
cacertFile = cacertNode.getComponent('cacert').cacertFile; cacertFile = cacertNode.getComponent("cacert").cacertFile;
} }
if (!cacertFile) { if (!cacertFile) {
console.log('没有cacertFile!!!'); console.log("没有cacertFile!!!");
} }
config.cacertNativeUrl = cc.loader.md5Pipe && cc.ENGINE_VERSION < "2.4.0" ? config.cacertNativeUrl =
cc.loader.md5Pipe.transformURL(cacertFile.nativeUrl) : cc.loader.md5Pipe && cc.ENGINE_VERSION < "2.4.0"
cacertFile.nativeUrl; ? 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)); console.log(JSON.stringify(event));
if (event.code !== 0) { if (event.code !== 0) {
console.log("初始化失败: " + event.code); console.log("初始化失败: " + event.code);
reject(); reject();
return; return;
} }
this.listenerInited = true;
console.log("初始化成功"); console.log("初始化成功");
resolve(null); resolve(null);
}); });
...@@ -101,14 +114,16 @@ export class NetworkHelper { ...@@ -101,14 +114,16 @@ export class NetworkHelper {
this.room.onJoinRoom = this.onJoinRoom.bind(this); this.room.onJoinRoom = this.onJoinRoom.bind(this);
this.room.onLeaveRoom = this.onLeaveRoom.bind(this); this.room.onLeaveRoom = this.onLeaveRoom.bind(this);
this.room.onRecvFromClient = this.onRecvFromClient.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.onRecvFrame = this.onRecvFrame.bind(this);
this.room.onStartFrameSync = this.onStartFrameSync.bind(this); this.room.onStartFrameSync = this.onStartFrameSync.bind(this);
this.room.onStopFrameSync = this.onStopFrameSync.bind(this); this.room.onStopFrameSync = this.onStopFrameSync.bind(this);
this.room.onRecvFromGameSvr = this.onRecvFromGameSvr.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) => { return new Promise((resolve, reject) => {
const playerName = "Tom" + Math.random(); const playerName = "Tom" + Math.random();
const playerInfo = { const playerInfo = {
...@@ -120,27 +135,44 @@ export class NetworkHelper { ...@@ -120,27 +135,44 @@ export class NetworkHelper {
const matchRoomPara = { const matchRoomPara = {
playerInfo, playerInfo,
maxPlayers: maxPlayers, maxPlayers: maxPlayers,
roomType: roomType roomType: roomType,
}; };
this.room.matchRoom(matchRoomPara, event => { this.room.matchRoom(matchRoomPara, async (event) => {
// console.log(JSON.stringify(event)) // console.log(JSON.stringify(event))
if (event.code === 0) { 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 {
cc.log("匹配失败"); cc.log("匹配失败");
reject(event); 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() { leaveRoom() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.room.leaveRoom({}, event => { this.room.leaveRoom({}, (event) => {
console.log(JSON.stringify(event)) console.log(JSON.stringify(event));
if (event.code === 0) { if (event.code === 0) {
console.log("退房成功" + this.room.roomInfo.id); console.log("退房成功" + this.room.roomInfo.id);
// this.room.initRoom(); // this.room.initRoom();
...@@ -152,10 +184,24 @@ export class NetworkHelper { ...@@ -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() { closeRoom() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.room.changeRoom({ isForbidJoin: true }, (event) => { this.room.changeRoom({ isForbidJoin: true }, (event) => {
console.log('关门') console.log("关门");
// console.log(JSON.stringify(event)) // console.log(JSON.stringify(event))
resolve(null); resolve(null);
}); });
...@@ -166,15 +212,15 @@ export class NetworkHelper { ...@@ -166,15 +212,15 @@ export class NetworkHelper {
const sendToClientPara = { const sendToClientPara = {
recvType: MGOBE.ENUM.RecvType.ROOM_ALL, recvType: MGOBE.ENUM.RecvType.ROOM_ALL,
recvPlayerList: [], 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() { startFrameSync() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.room.startFrameSync({}, event => { this.room.startFrameSync({}, (event) => {
console.log(JSON.stringify(event)) console.log(JSON.stringify(event));
if (event.code === 0) { if (event.code === 0) {
cc.log("开始帧同步成功,请到控制台查看具体帧同步信息"); cc.log("开始帧同步成功,请到控制台查看具体帧同步信息");
resolve(null); resolve(null);
...@@ -191,8 +237,8 @@ export class NetworkHelper { ...@@ -191,8 +237,8 @@ export class NetworkHelper {
resolve(null); resolve(null);
return; return;
} }
this.room.stopFrameSync({}, event => { this.room.stopFrameSync({}, (event) => {
console.log(JSON.stringify(event)) console.log(JSON.stringify(event));
if (event.code === 0) { if (event.code === 0) {
console.log("停止帧同步成功"); console.log("停止帧同步成功");
resolve(null); resolve(null);
...@@ -207,69 +253,94 @@ export class NetworkHelper { ...@@ -207,69 +253,94 @@ export class NetworkHelper {
sendToServer() { sendToServer() {
const sendToGameServerPara = { const sendToGameServerPara = {
data: { data: {
cmd: 1 cmd: 1,
} },
}; };
this.room.sendToGameSvr(sendToGameServerPara, event => console.log(event)); this.room.sendToGameSvr(sendToGameServerPara, (event) =>
console.log(event)
);
} }
sendFrame(data: any) { sendFrame(data: any) {
this.room.sendFrame({ data }, err => { this.room.sendFrame({ data }, (err) => {
if (err.code != 0) { if (err.code != 0) {
console.log("err", err) console.log("err", err);
} }
}); });
} }
onJoinRoom(event) { onJoinRoom(event) {
if (this._eventListeners['playerJoin']) { if (this._eventListeners["playerJoin"]) {
this._eventListeners['playerJoin'](event); this._eventListeners["playerJoin"](event);
} }
console.log("新玩家加入", event.data.joinPlayerId); console.log("新玩家加入", event.data.joinPlayerId);
} }
onLeaveRoom(event) { onLeaveRoom(event) {
if (this._eventListeners['playerLeave']) { console.log("onLeaveRoom");
this._eventListeners['playerLeave'](event); if (this._eventListeners["playerLeave"]) {
this._eventListeners["playerLeave"](event);
} }
console.log("玩家退出", event.data.leavePlayerId); 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) { onRecvFrame(event) {
if (this._eventListeners['frameEvent']) { if (this._eventListeners["frameEvent"]) {
this._eventListeners['frameEvent'](event); this._eventListeners["frameEvent"](event);
} }
} }
onStartFrameSync(event) { onStartFrameSync(event) {
if (this._eventListeners['gameStart']) { if (this._eventListeners["gameStart"]) {
this._eventListeners['gameStart'](event); this._eventListeners["gameStart"](event);
} }
} }
onStopFrameSync(event) { } onStopFrameSync(event) {}
onRecvFromGameSvr() { } onRecvFromGameSvr() {}
async onDestroy() { async onDestroy() {
try { try {
console.log('onDestroy1') console.log("onDestroy1");
this.dismissRoom();
MGOBE.Listener.clear(); MGOBE.Listener.clear();
await this.stopGame(); this.stopFrameSync();
console.log('onDestroy2') this.closeRoom();
this.leaveRoom();
console.log("onDestroy2");
} catch (e) { } catch (e) {
console.log(JSON.stringify(e)); console.log(JSON.stringify(e));
} }
} }
log(str) { log(str) {
const node = cc.find('middleLayer'); const node = cc.find("middleLayer");
if (node) { if (node) {
node.getComponent('middleLayer').log(str); node.getComponent("middleLayer").log(str);
} else { } else {
cc.log(str); cc.log(str);
} }
} }
callNetworkApiGet(baseUrl, uri, data, callBack) { callNetworkApiGet(baseUrl, uri, data, callBack) {
let queryStr = '?'; let queryStr = "?";
const params = []; const params = [];
for (const key in data) { for (const key in data) {
if (Object.hasOwnProperty.call(data, key)) { if (Object.hasOwnProperty.call(data, key)) {
...@@ -279,13 +350,24 @@ export class NetworkHelper { ...@@ -279,13 +350,24 @@ export class NetworkHelper {
queryStr += params.join("&"); queryStr += params.join("&");
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => { 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); callBack(xhr.responseText);
} }
}; };
const url = `${baseUrl}${uri}${queryStr}`; const url = `${baseUrl}${uri}${queryStr}`;
console.log('url = ' + url); console.log("url = " + url);
xhr.open('GET', url, true); xhr.open("GET", url, true);
xhr.send(); 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 { ...@@ -7,16 +7,25 @@ export class GameServer {
playerMaxNumber = 0; playerMaxNumber = 0;
networkHelper: NetworkHelper = null; networkHelper: NetworkHelper = null;
nameList = [ nameList = [
'Chris', 'Benny', 'Leslie', 'Devin', 'Sam', "Chris",
'Kerry', 'Joey', 'Hailey', 'Fred', 'Arrow', "Benny",
'Tony', 'Michael', "Leslie",
"Devin",
"Sam",
"Kerry",
"Joey",
"Hailey",
"Fred",
"Arrow",
"Tony",
"Michael",
]; ];
headUrls = [ headUrls = [
'http://staging-teach.cdn.ireadabc.com/0751c28419a0e8ffb1f0e84435b081ce.png', "http://staging-teach.cdn.ireadabc.com/0751c28419a0e8ffb1f0e84435b081ce.png",
'http://staging-teach.cdn.ireadabc.com/f596e586a31ac2813b1702557941c022.png', "http://staging-teach.cdn.ireadabc.com/f596e586a31ac2813b1702557941c022.png",
'http://staging-teach.cdn.ireadabc.com/f0f396c52c42239913fd94523db979fa.png', "http://staging-teach.cdn.ireadabc.com/f0f396c52c42239913fd94523db979fa.png",
'http://staging-teach.cdn.ireadabc.com/9f2d2ef622fa33d4e2abcbdc4b40ab6a.png', "http://staging-teach.cdn.ireadabc.com/9f2d2ef622fa33d4e2abcbdc4b40ab6a.png",
'http://staging-teach.cdn.ireadabc.com/f40ce4a8630039c4cf48a63fc1399c52.png' "http://staging-teach.cdn.ireadabc.com/f40ce4a8630039c4cf48a63fc1399c52.png",
]; ];
constructor(playerMaxNumber, networkHelper) { constructor(playerMaxNumber, networkHelper) {
...@@ -33,19 +42,20 @@ export class GameServer { ...@@ -33,19 +42,20 @@ export class GameServer {
} }
async addPlayer(player) { async addPlayer(player) {
console.log('addPlayer'); console.log("addPlayer");
this.playerList.push({ this.playerList.push({
name: this.nameList.splice(0, 1)[0], name: this.nameList.splice(0, 1)[0],
uuid: player.uuid, 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, isAI: player.isAI,
headUrl: this.headUrls.splice(0, 1)[0] headUrl: this.headUrls.splice(0, 1)[0],
}); });
await asyncDelay(1); await asyncDelay(1);
this.networkHelper.sendFrame({ this.networkHelper.sendFrame({
type: 'SERVER_allPlayerInfo', type: "SERVER_allPlayerInfo",
playerData: this.playerList playerData: this.playerList,
}); });
if (this.playerList.length == this.playerMaxNumber) { if (this.playerList.length == this.playerMaxNumber) {
...@@ -59,83 +69,90 @@ export class GameServer { ...@@ -59,83 +69,90 @@ export class GameServer {
gameStatus = { gameStatus = {
Red: 0, Red: 0,
Blue: 0, Blue: 0,
letter: '', letter: "",
current: 'Blue' current: "Blue",
}; };
startGame() { startGame() {
this.networkHelper.sendFrame({ this.networkHelper.sendFrame({
type: 'SERVER_updateStatus', type: "SERVER_updateStatus",
status: this.gameStatus status: this.gameStatus,
}); });
} }
onPlayerJoin(event) { onPlayerJoin(event) {
this.addPlayer({ this.addPlayer({
uuid: event.data.joinPlayerId, uuid: event.data.joinPlayerId,
isAI: false isAI: false,
}); });
} }
_aiPlayerList = []; _aiPlayerList = [];
startMatch() { startMatch() {
for (let i = 0; i < this.playerMaxNumber; i++) { for (let i = 0; i < this.playerMaxNumber; i++) {
this._timeoutIds.push(setTimeout(() => { this._timeoutIds.push(
const count = this.playerMaxNumber - this.playerList.length; setTimeout(() => {
if (count > 0) { const count = this.playerMaxNumber - this.playerList.length;
const playerInfo = { if (count > 0) {
uuid: 'ai_' + i, const playerInfo = {
isAI: true, uuid: "ai_" + i,
color: 'Red' isAI: true,
color: "Red",
};
this._aiPlayerList.push(new AI(this.networkHelper, playerInfo));
this.addPlayer(playerInfo);
} }
this._aiPlayerList.push(new AI(this.networkHelper, playerInfo)); }, RandomInt(10000, 15000))
this.addPlayer(playerInfo); );
}
}, RandomInt(10000, 15000)));
} }
} }
onFrameEvent(data) { onFrameEvent(data) {
if (data.type == 'roll') { if (this.gameStatus.gameOver) {
return;
}
if (data.type == "roll") {
const letterList = this.getLetterList(); const letterList = this.getLetterList();
if (letterList.length > 0) { if (letterList.length > 0) {
const letter = letterList[RandomInt(letterList.length)]; const letter = letterList[RandomInt(letterList.length)];
this.gameStatus.letter = letter; this.gameStatus.letter = letter;
this.networkHelper.sendFrame({ this.networkHelper.sendFrame({
type: 'SERVER_playerRoll', type: "SERVER_playerRoll",
letter: letter letter: letter,
}); });
} else { } else {
this.networkHelper.sendFrame({ this.networkHelper.sendFrame({
type: 'SERVER_playerWin', type: "SERVER_playerWin",
color: this.gameStatus.current color: this.gameStatus.current,
}); });
this.gameStatus.gameOver = true;
} }
} else if (data.type == 'right') { } else if (data.type == "right") {
this.gameStatus[data.color] = data.idx; this.gameStatus[data.color] = data.idx;
const letterList = this.getLetterList(); const letterList = this.getLetterList();
console.log('letterList = ' + JSON.stringify(letterList)); console.log("letterList = " + JSON.stringify(letterList));
if (letterList.length > 0) { if (letterList.length > 0) {
this.changeSide(); this.changeSide();
this.networkHelper.sendFrame({ this.networkHelper.sendFrame({
type: 'SERVER_playerRight', type: "SERVER_playerRight",
idx: data.idx, idx: data.idx,
uuid: data.uuid, uuid: data.uuid,
color: data.color color: data.color,
}); });
} else { } else {
this.networkHelper.sendFrame({ this.networkHelper.sendFrame({
type: 'SERVER_playerWin', type: "SERVER_playerWin",
color: this.gameStatus.current color: this.gameStatus.current,
}); });
this.gameStatus.gameOver = true;
} }
} else if (data.type == 'wrong') { } else if (data.type == "wrong") {
console.log('data = ' + JSON.stringify(data)); console.log("data = " + JSON.stringify(data));
// this.gameStatus[data.color] = data.idx; // this.gameStatus[data.color] = data.idx;
this.changeSide(); this.changeSide();
this.networkHelper.sendFrame({ this.networkHelper.sendFrame({
type: 'SERVER_playerWrong', type: "SERVER_playerWrong",
uuid: data.uuid, uuid: data.uuid,
color: data.color color: data.color,
}); });
} else { } else {
this._aiPlayerList.forEach((ai: AI) => { this._aiPlayerList.forEach((ai: AI) => {
...@@ -145,19 +162,19 @@ export class GameServer { ...@@ -145,19 +162,19 @@ export class GameServer {
} }
getLetterList() { getLetterList() {
const board = cc.find('Canvas/bg/chessBoard/boardItems'); const board = cc.find("Canvas/bg/chessBoard/boardItems");
const color = this.gameStatus.current; const color = this.gameStatus.current;
console.log("color = " + color); 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]; const startIdx = this.gameStatus[color];
console.log('startIdx = ' + startIdx); console.log("startIdx = " + startIdx);
const letterList = []; const letterList = [];
for (let i = startIdx + 1; i < board.children.length; i++) { for (let i = startIdx + 1; i < board.children.length; i++) {
const targetNode = board.children[i]; const targetNode = board.children[i];
const itemData = targetNode.getComponent('ItemData'); const itemData = targetNode.getComponent("ItemData");
const nodeLetter = itemData.letter.toUpperCase(); const nodeLetter = itemData.letter.toUpperCase();
if (!letterList.find(letter => letter == nodeLetter)) { if (!letterList.find((letter) => letter == nodeLetter)) {
letterList.push(nodeLetter); letterList.push(nodeLetter);
} }
} }
...@@ -165,30 +182,28 @@ export class GameServer { ...@@ -165,30 +182,28 @@ export class GameServer {
} }
changeSide() { changeSide() {
if (this.gameStatus.current == 'Red') { if (this.gameStatus.current == "Red") {
this.gameStatus.current = 'Blue'; this.gameStatus.current = "Blue";
} else { } else {
this.gameStatus.current = 'Red'; this.gameStatus.current = "Red";
} }
} }
startAI() { startAI() {
this.playerList this.playerList
.filter(player => player.isAI == true) .filter((player) => player.isAI == true)
.forEach(player => { .forEach((player) => {});
});
} }
_timeoutIds = null; _timeoutIds = null;
_intervalIds = null; _intervalIds = null;
// 生命周期 // 生命周期
onDestroy() { onDestroy() {
this._timeoutIds.forEach(id => { this._timeoutIds.forEach((id) => {
clearTimeout(id); clearTimeout(id);
}); });
this._intervalIds.forEach(id => { this._intervalIds.forEach((id) => {
clearInterval(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 @@ ...@@ -616,6 +616,11 @@
"mime-types": "~2.1.24" "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": { "unpipe": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npm.taobao.org/unpipe/download/unpipe-1.0.0.tgz", "resolved": "https://registry.npm.taobao.org/unpipe/download/unpipe-1.0.0.tgz",
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
"crypto-js": "^4.1.1", "crypto-js": "^4.1.1",
"express": "^4.17.1", "express": "^4.17.1",
"js-base64": "^3.7.2", "js-base64": "^3.7.2",
"typescript": "^4.5.5",
"uuid": "^8.3.2" "uuid": "^8.3.2"
} }
} }
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