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

fix: bugs

parent 3acf5050
No preview for this file type
{
"ver": "2.0.1",
"uuid": "64769aad-08a2-4b33-8fbb-6a6ba01f53f2",
"downloadMode": 0,
"duration": 3.474286,
"subMetas": {}
}
\ No newline at end of file
......@@ -40,19 +40,22 @@
},
{
"__id__": 34
},
{
"__id__": 54
}
],
"_active": true,
"_components": [
{
"__id__": 54
"__id__": 59
},
{
"__id__": 55
"__id__": 60
}
],
"_prefab": {
"__id__": 56
"__id__": 61
},
"_opacity": 255,
"_color": {
......@@ -1959,6 +1962,175 @@
"fileId": "f9qrJyDh5P1oErn3FfsNL7",
"sync": false
},
{
"__type__": "cc.Node",
"_name": "res",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_children": [
{
"__id__": 55
}
],
"_active": true,
"_components": [],
"_prefab": {
"__id__": 58
},
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 0,
"height": 0
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0,
0,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": ""
},
{
"__type__": "cc.Node",
"_name": "match",
"_objFlags": 0,
"_parent": {
"__id__": 54
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 56
}
],
"_prefab": {
"__id__": 57
},
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 0,
"height": 0
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0,
0,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": ""
},
{
"__type__": "cc.AudioSource",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 55
},
"_enabled": true,
"_clip": {
"__uuid__": "64769aad-08a2-4b33-8fbb-6a6ba01f53f2"
},
"_volume": 1,
"_mute": false,
"_loop": false,
"_firstlyEnabled": true,
"playOnLoad": false,
"preload": false,
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__uuid__": "4839576b-7c74-49ab-aa3e-8eeec631d7c0"
},
"fileId": "24pM39t0xAcpeV3Rbf7iK5",
"sync": false
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__uuid__": "4839576b-7c74-49ab-aa3e-8eeec631d7c0"
},
"fileId": "28B+az6rRACpZT/KUohVaz",
"sync": false
},
{
"__type__": "cc.Widget",
"_name": "",
......
This diff is collapsed.
This diff is collapsed.
......@@ -7,8 +7,8 @@ export class AI {
_status = {
Red: 0,
Blue: 0,
letter: '',
current: 'Blue'
letter: "",
current: "Blue",
};
constructor(networkHelper: NetworkHelper, playerData: any) {
......@@ -17,44 +17,47 @@ export class AI {
}
async onFrameEvent(event) {
console.log('AI get event: ' + JSON.stringify(event));
if (event.type == 'SERVER_updateStatus') {
console.log("AI get event: " + JSON.stringify(event));
if (event.type == "SERVER_updateStatus") {
this._status = JSON.parse(JSON.stringify(event.status));
} else if (event.type == 'SERVER_playerRoll') {
} else if (event.type == "SERVER_playerRoll") {
console.log('汪汪汪0');
this._status.letter = event.letter;
if (this.playerData.color == this._status.current) {
await asyncDelay(Math.random() * 3 + 11);
await asyncDelay(Math.random() * 3 + 12);
}
} else if (event.type == 'SERVER_playerRight') {
this._status.letter = '';
} else if (event.type == "SERVER_playerRight") {
console.log('汪汪汪1');
this._status.letter = "";
this._status[event.color] = event.idx;
this.changeSide();
} else if (event.type == 'SERVER_playerWrong') {
this._status.letter = '';
} else if (event.type == "SERVER_playerWrong") {
console.log('汪汪汪2');
this._status.letter = "";
this.changeSide();
}
if (this.playerData.color == this._status.current) {
await asyncDelay(Math.random() * 3 + 2);
if (this._status.letter == '') {
await asyncDelay(Math.random() * 3 + 4);
if (this._status.letter == "") {
this.networkHelper.sendFrame({
type: 'roll',
uuid: this.playerData.uuid
type: "roll",
uuid: this.playerData.uuid,
});
} else {
const idx = this.getNextRightIdx();
if (Math.random() > 0.5) {
if (Math.random() < 0.9) {
this.networkHelper.sendFrame({
type: 'right',
type: "right",
idx: idx,
uuid: this.playerData.uuid,
color: this.playerData.color
color: this.playerData.color,
});
} else {
this.networkHelper.sendFrame({
type: 'wrong',
type: "wrong",
uuid: this.playerData.uuid,
color: this.playerData.color
color: this.playerData.color,
});
}
}
......@@ -62,23 +65,23 @@ export class AI {
}
changeSide() {
if (this._status.current == 'Red') {
this._status.current = 'Blue';
if (this._status.current == "Red") {
this._status.current = "Blue";
} else {
this._status.current = 'Red';
this._status.current = "Red";
}
}
getNextRightIdx() {
const board = cc.find('Canvas/bg/chessBoard/boardItems');
const board = cc.find("Canvas/bg/chessBoard/boardItems");
const startIdx = this._status[this._status.current];
for (let i = startIdx + 1; i < board.children.length; i++) {
const targetNode = board.children[i];
const itemData = targetNode.getComponent('ItemData');
const itemData = targetNode.getComponent("ItemData");
if (itemData.letter.toLowerCase() == this._status.letter.toLowerCase()) {
return i;
}
}
return -1;
}
}
\ No newline at end of file
}
......@@ -97,6 +97,7 @@ export default class SceneComponent extends cc.Component {
cc.find('right', this.node).addChild(headNode);
const vs = cc.find('vs', this.node);
asyncPlayDragonBoneAnimation(vs, 'normal', 1);
this.playLocalAudio('match');
}
const rate = Math.min(1, this._playerList.length / this._maxPlayerNum);
......@@ -231,6 +232,25 @@ export default class SceneComponent extends cc.Component {
}
});
}
playLocalAudio(name) {
return new Promise((resolve, reject) => {
this.stopCurrentPlayedAudio();
const audioNode = cc.find(`res/${name}`, this.node);
if (!audioNode) {
resolve(null);
return;
}
const audioClip = audioNode.getComponent(cc.AudioSource).clip;
const audioId = cc.audioEngine.play(audioClip, false, 0.8);
this.currentPlayedAudioId = audioId;
cc.audioEngine.setFinishCallback(audioId, () => {
resolve(null);
});
});
}
_timeoutIds = [];
_intervalIds = [];
// 生命周期
......
This diff is collapsed.
......@@ -7,16 +7,25 @@ export class GameServer {
playerMaxNumber = 0;
networkHelper: NetworkHelper = null;
nameList = [
'Chris', 'Benny', 'Leslie', 'Devin', 'Sam',
'Kerry', 'Joey', 'Hailey', 'Fred', 'Arrow',
'Tony', 'Michael',
"Chris",
"Benny",
"Leslie",
"Devin",
"Sam",
"Kerry",
"Joey",
"Hailey",
"Fred",
"Arrow",
"Tony",
"Michael",
];
headUrls = [
'http://staging-teach.cdn.ireadabc.com/0751c28419a0e8ffb1f0e84435b081ce.png',
'http://staging-teach.cdn.ireadabc.com/f596e586a31ac2813b1702557941c022.png',
'http://staging-teach.cdn.ireadabc.com/f0f396c52c42239913fd94523db979fa.png',
'http://staging-teach.cdn.ireadabc.com/9f2d2ef622fa33d4e2abcbdc4b40ab6a.png',
'http://staging-teach.cdn.ireadabc.com/f40ce4a8630039c4cf48a63fc1399c52.png'
"http://staging-teach.cdn.ireadabc.com/0751c28419a0e8ffb1f0e84435b081ce.png",
"http://staging-teach.cdn.ireadabc.com/f596e586a31ac2813b1702557941c022.png",
"http://staging-teach.cdn.ireadabc.com/f0f396c52c42239913fd94523db979fa.png",
"http://staging-teach.cdn.ireadabc.com/9f2d2ef622fa33d4e2abcbdc4b40ab6a.png",
"http://staging-teach.cdn.ireadabc.com/f40ce4a8630039c4cf48a63fc1399c52.png",
];
constructor(playerMaxNumber, networkHelper) {
......@@ -33,19 +42,20 @@ export class GameServer {
}
async addPlayer(player) {
console.log('addPlayer');
console.log("addPlayer");
this.playerList.push({
name: this.nameList.splice(0, 1)[0],
uuid: player.uuid,
color: player.uuid == this.networkHelper.room.roomInfo.owner ? 'Blue' : 'Red',
color:
player.uuid == this.networkHelper.room.roomInfo.owner ? "Blue" : "Red",
isAI: player.isAI,
headUrl: this.headUrls.splice(0, 1)[0]
headUrl: this.headUrls.splice(0, 1)[0],
});
await asyncDelay(1);
this.networkHelper.sendFrame({
type: 'SERVER_allPlayerInfo',
playerData: this.playerList
type: "SERVER_allPlayerInfo",
playerData: this.playerList,
});
if (this.playerList.length == this.playerMaxNumber) {
......@@ -59,83 +69,90 @@ export class GameServer {
gameStatus = {
Red: 0,
Blue: 0,
letter: '',
current: 'Blue'
letter: "",
current: "Blue",
};
startGame() {
this.networkHelper.sendFrame({
type: 'SERVER_updateStatus',
status: this.gameStatus
type: "SERVER_updateStatus",
status: this.gameStatus,
});
}
onPlayerJoin(event) {
this.addPlayer({
uuid: event.data.joinPlayerId,
isAI: false
isAI: false,
});
}
_aiPlayerList = [];
startMatch() {
for (let i = 0; i < this.playerMaxNumber; i++) {
this._timeoutIds.push(setTimeout(() => {
const count = this.playerMaxNumber - this.playerList.length;
if (count > 0) {
const playerInfo = {
uuid: 'ai_' + i,
isAI: true,
color: 'Red'
this._timeoutIds.push(
setTimeout(() => {
const count = this.playerMaxNumber - this.playerList.length;
if (count > 0) {
const playerInfo = {
uuid: "ai_" + i,
isAI: true,
color: "Red",
};
this._aiPlayerList.push(new AI(this.networkHelper, playerInfo));
this.addPlayer(playerInfo);
}
this._aiPlayerList.push(new AI(this.networkHelper, playerInfo));
this.addPlayer(playerInfo);
}
}, RandomInt(10000, 15000)));
}, RandomInt(10000, 15000))
);
}
}
onFrameEvent(data) {
if (data.type == 'roll') {
if (this.gameStatus.gameOver) {
return;
}
if (data.type == "roll") {
const letterList = this.getLetterList();
if (letterList.length > 0) {
const letter = letterList[RandomInt(letterList.length)];
this.gameStatus.letter = letter;
this.networkHelper.sendFrame({
type: 'SERVER_playerRoll',
letter: letter
type: "SERVER_playerRoll",
letter: letter,
});
} else {
this.networkHelper.sendFrame({
type: 'SERVER_playerWin',
color: this.gameStatus.current
type: "SERVER_playerWin",
color: this.gameStatus.current,
});
this.gameStatus.gameOver = true;
}
} else if (data.type == 'right') {
} else if (data.type == "right") {
this.gameStatus[data.color] = data.idx;
const letterList = this.getLetterList();
console.log('letterList = ' + JSON.stringify(letterList));
console.log("letterList = " + JSON.stringify(letterList));
if (letterList.length > 0) {
this.changeSide();
this.networkHelper.sendFrame({
type: 'SERVER_playerRight',
type: "SERVER_playerRight",
idx: data.idx,
uuid: data.uuid,
color: data.color
color: data.color,
});
} else {
this.networkHelper.sendFrame({
type: 'SERVER_playerWin',
color: this.gameStatus.current
type: "SERVER_playerWin",
color: this.gameStatus.current,
});
this.gameStatus.gameOver = true;
}
} else if (data.type == 'wrong') {
console.log('data = ' + JSON.stringify(data));
} else if (data.type == "wrong") {
console.log("data = " + JSON.stringify(data));
// this.gameStatus[data.color] = data.idx;
this.changeSide();
this.networkHelper.sendFrame({
type: 'SERVER_playerWrong',
type: "SERVER_playerWrong",
uuid: data.uuid,
color: data.color
color: data.color,
});
} else {
this._aiPlayerList.forEach((ai: AI) => {
......@@ -145,19 +162,19 @@ export class GameServer {
}
getLetterList() {
const board = cc.find('Canvas/bg/chessBoard/boardItems');
const board = cc.find("Canvas/bg/chessBoard/boardItems");
const color = this.gameStatus.current;
console.log("color = " + color);
console.log('this.gameStatus = ' + JSON.stringify(this.gameStatus));
console.log("this.gameStatus = " + JSON.stringify(this.gameStatus));
const startIdx = this.gameStatus[color];
console.log('startIdx = ' + startIdx);
console.log("startIdx = " + startIdx);
const letterList = [];
for (let i = startIdx + 1; i < board.children.length; i++) {
const targetNode = board.children[i];
const itemData = targetNode.getComponent('ItemData');
const itemData = targetNode.getComponent("ItemData");
const nodeLetter = itemData.letter.toUpperCase();
if (!letterList.find(letter => letter == nodeLetter)) {
if (!letterList.find((letter) => letter == nodeLetter)) {
letterList.push(nodeLetter);
}
}
......@@ -165,30 +182,28 @@ export class GameServer {
}
changeSide() {
if (this.gameStatus.current == 'Red') {
this.gameStatus.current = 'Blue';
if (this.gameStatus.current == "Red") {
this.gameStatus.current = "Blue";
} else {
this.gameStatus.current = 'Red';
this.gameStatus.current = "Red";
}
}
startAI() {
this.playerList
.filter(player => player.isAI == true)
.forEach(player => {
});
.filter((player) => player.isAI == true)
.forEach((player) => {});
}
_timeoutIds = null;
_intervalIds = null;
// 生命周期
onDestroy() {
this._timeoutIds.forEach(id => {
this._timeoutIds.forEach((id) => {
clearTimeout(id);
});
this._intervalIds.forEach(id => {
this._intervalIds.forEach((id) => {
clearInterval(id);
});
}
}
\ No newline at end of file
}
{
"ver": "2.3.5",
"uuid": "e1c1011c-37ad-47ab-b75c-0528fb58912e",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 584,
"height": 235,
"platformSettings": {},
"subMetas": {
"yourturn": {
"ver": "1.0.4",
"uuid": "eeb8a1d1-4858-4241-8733-38b1cff4c7cf",
"rawTextureUuid": "e1c1011c-37ad-47ab-b75c-0528fb58912e",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 584,
"height": 235,
"rawWidth": 584,
"rawHeight": 235,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
......@@ -616,6 +616,11 @@
"mime-types": "~2.1.24"
}
},
"typescript": {
"version": "4.5.5",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.5.tgz",
"integrity": "sha512-TCTIul70LyWe6IJWT8QSYeA54WQe8EjQFU4wY52Fasj5UKx88LNYKCgBEHcOMOrFF1rKGbD8v/xcNWVUq9SymA=="
},
"unpipe": {
"version": "1.0.0",
"resolved": "https://registry.npm.taobao.org/unpipe/download/unpipe-1.0.0.tgz",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment