Commit f14dd5c9 authored by 范雪寒's avatar 范雪寒

feat:

parent a10dd21d
{
"ver": "1.1.0",
"uuid": "79f0f099-3ac8-4fab-b77e-065c19b5d71a",
"subMetas": {}
}
\ No newline at end of file
......@@ -19,9 +19,6 @@ export class AI {
if (!this._status?.round && serverStatus.round == 1) {
this._status = serverStatus;
this.startGame();
} else if (this._status.round == 1 && serverStatus.round == 2) {
this._status = serverStatus;
this.startGame();
}
this._status = serverStatus;
}
......@@ -29,11 +26,10 @@ export class AI {
startGame() {
const boatIdxList = this._status.boats
.map((boat, idx) => boat.show ? idx : -1)
.filter(idx => idx != -1)
.map((boat, idx) => idx)
.sort(() => Math.random() - 0.5);
let time = 0;
for (let i = 0; i < 8; i++) {
let time = 6;
for (let i = 0; i < 16; i++) {
time += this.params.testDuration + Math.random() * 5;
setTimeout(() => {
if (Math.random() < 0.7) {
......
......@@ -35,7 +35,7 @@ export class GameServer {
this.networkHelper.startFrameSync();
this.gameStatus = {
round: 0,// 0: 未开始, 1: 回合1, 2: 回合2, 3: 已结束
round: 0,// 0: 未开始, 1: 游戏中, 2: 已结束
boats: [],
};
for (let i = 0; i < 16; i++) {
......@@ -86,6 +86,12 @@ export class GameServer {
type: "SERVER_updateStatus",
status: this.gameStatus,
});
console.log('this.params = ', this.params);
this._timeoutIds.push(setTimeout(() => {
this.timeOutFlg = true;
this.checkover();
}, this.params.roundTime * 1000));
}
onPlayerJoin(event) {
......@@ -135,9 +141,10 @@ export class GameServer {
this.startAI();
}
} else if (data.type == "right") {
if (this.gameStatus.round == 3) {
return;
if (this.gameStatus.round == 2) {
return;
}
console.log('data.boatIdx = ', data.boatIdx);
this.gameStatus.boats[data.boatIdx][data.playerId] = 'right';
this.networkHelper.sendFrame({
type: "SERVER_updateStatus",
......@@ -145,9 +152,10 @@ export class GameServer {
});
this.checkover();
} else if (data.type == "wrong") {
if (this.gameStatus.round == 3) {
return;
if (this.gameStatus.round == 2) {
return;
}
console.log('data.boatIdx = ', data.boatIdx);
this.gameStatus.boats[data.boatIdx][data.playerId] = 'wrong';
this.networkHelper.sendFrame({
type: "SERVER_updateStatus",
......@@ -161,20 +169,52 @@ export class GameServer {
}
}
timeOutFlg = false;
firstCompletePlayerId;
checkover() {
if (this.gameStatus.boats
.filter(boat => boat.show)
.every(boat => Object.keys(boat).length == 3)
) {
this.gameStatus.round++;
this.gameStatus.boats.forEach(boat => {
boat.show = !boat.show;
});
this.networkHelper.sendFrame({
type: "SERVER_updateStatus",
status: this.gameStatus,
if (!this.firstCompletePlayerId) {
this.playerList.forEach(player => {
if (this.gameStatus.boats.every(boat => boat[player.uuid])) {
this.firstCompletePlayerId = player.uuid;
}
});
}
if (this.gameStatus.boats.some(boat => Object.keys(boat).length != 3)) {
// 有人没有完成游戏
if (!this.timeOutFlg) {
return;
}
}
this.gameStatus.round = 2;
this.networkHelper.sendFrame({
type: "SERVER_updateStatus",
status: this.gameStatus,
});
const idScoreMap = {};
this.gameStatus.boats.forEach(boat => {
Object.keys(boat).forEach(key => {
if (boat[key] == 'right') {
if (!idScoreMap[key]) {
idScoreMap[key] = 0;
}
idScoreMap[key]++;
}
});
});
let winnerId = null;
Object.keys(idScoreMap).forEach(key => {
if (winnerId == null || idScoreMap[key] > idScoreMap[winnerId]) {
winnerId = key;
} else if (idScoreMap[key] == idScoreMap[winnerId]) {
winnerId = this.firstCompletePlayerId;
}
});
this.networkHelper.sendFrame({
type: "SERVER_playerWin",
winnerId: winnerId,
});
}
startAI() {
......
export const defaultData = {
roundTime: 80,
testDuration: 5,
audioOnEnterMatch: '',
audioOnEnterGame: '',
auidoDuringGame: '', // TODO:
audioOnFirstTest: '',
audioDuringTest: '', // TODO:
audioRight: '',
audioWrong: '',
audioWinInTime: '',
audioLossInTime: '',
audioWinOutTime: '',
audioLossOutTime: '',
audioAfterGame: '', // TODO:
}
\ No newline at end of file
{
"ver": "1.1.2",
"uuid": "3e5bb1d7-2141-4c18-b3bd-174805d444ea",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "8d5c696c-93bc-4ccf-816c-dc1b5db0c2f6",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 2176,
"height": 485,
"platformSettings": {},
"subMetas": {
"bg": {
"ver": "1.0.4",
"uuid": "415ce19c-14be-4e76-aae5-3554e72085b4",
"rawTextureUuid": "8d5c696c-93bc-4ccf-816c-dc1b5db0c2f6",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 2176,
"height": 485,
"rawWidth": 2176,
"rawHeight": 485,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "46cbf903-b8ab-43ea-a423-128ed16c4328",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 1064,
"height": 451,
"platformSettings": {},
"subMetas": {
"labelLoss": {
"ver": "1.0.4",
"uuid": "52e98523-d799-4cdf-9139-173d2199edd6",
"rawTextureUuid": "46cbf903-b8ab-43ea-a423-128ed16c4328",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 1064,
"height": 451,
"rawWidth": 1064,
"rawHeight": 451,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "d850d933-91e1-4073-9358-afaef2b4f40f",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 1070,
"height": 451,
"platformSettings": {},
"subMetas": {
"labelWin": {
"ver": "1.0.4",
"uuid": "0c0827af-f3ed-48c9-92ed-f74057731852",
"rawTextureUuid": "d850d933-91e1-4073-9358-afaef2b4f40f",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 1070,
"height": 451,
"rawWidth": 1070,
"rawHeight": 451,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
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