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 { ...@@ -19,9 +19,6 @@ export class AI {
if (!this._status?.round && serverStatus.round == 1) { if (!this._status?.round && serverStatus.round == 1) {
this._status = serverStatus; this._status = serverStatus;
this.startGame(); this.startGame();
} else if (this._status.round == 1 && serverStatus.round == 2) {
this._status = serverStatus;
this.startGame();
} }
this._status = serverStatus; this._status = serverStatus;
} }
...@@ -29,11 +26,10 @@ export class AI { ...@@ -29,11 +26,10 @@ export class AI {
startGame() { startGame() {
const boatIdxList = this._status.boats const boatIdxList = this._status.boats
.map((boat, idx) => boat.show ? idx : -1) .map((boat, idx) => idx)
.filter(idx => idx != -1)
.sort(() => Math.random() - 0.5); .sort(() => Math.random() - 0.5);
let time = 0; let time = 6;
for (let i = 0; i < 8; i++) { for (let i = 0; i < 16; i++) {
time += this.params.testDuration + Math.random() * 5; time += this.params.testDuration + Math.random() * 5;
setTimeout(() => { setTimeout(() => {
if (Math.random() < 0.7) { if (Math.random() < 0.7) {
......
...@@ -35,7 +35,7 @@ export class GameServer { ...@@ -35,7 +35,7 @@ export class GameServer {
this.networkHelper.startFrameSync(); this.networkHelper.startFrameSync();
this.gameStatus = { this.gameStatus = {
round: 0,// 0: 未开始, 1: 回合1, 2: 回合2, 3: 已结束 round: 0,// 0: 未开始, 1: 游戏中, 2: 已结束
boats: [], boats: [],
}; };
for (let i = 0; i < 16; i++) { for (let i = 0; i < 16; i++) {
...@@ -86,6 +86,12 @@ export class GameServer { ...@@ -86,6 +86,12 @@ export class GameServer {
type: "SERVER_updateStatus", type: "SERVER_updateStatus",
status: this.gameStatus, status: this.gameStatus,
}); });
console.log('this.params = ', this.params);
this._timeoutIds.push(setTimeout(() => {
this.timeOutFlg = true;
this.checkover();
}, this.params.roundTime * 1000));
} }
onPlayerJoin(event) { onPlayerJoin(event) {
...@@ -135,9 +141,10 @@ export class GameServer { ...@@ -135,9 +141,10 @@ export class GameServer {
this.startAI(); this.startAI();
} }
} else if (data.type == "right") { } else if (data.type == "right") {
if (this.gameStatus.round == 3) { if (this.gameStatus.round == 2) {
return; return;
} }
console.log('data.boatIdx = ', data.boatIdx);
this.gameStatus.boats[data.boatIdx][data.playerId] = 'right'; this.gameStatus.boats[data.boatIdx][data.playerId] = 'right';
this.networkHelper.sendFrame({ this.networkHelper.sendFrame({
type: "SERVER_updateStatus", type: "SERVER_updateStatus",
...@@ -145,9 +152,10 @@ export class GameServer { ...@@ -145,9 +152,10 @@ export class GameServer {
}); });
this.checkover(); this.checkover();
} else if (data.type == "wrong") { } else if (data.type == "wrong") {
if (this.gameStatus.round == 3) { if (this.gameStatus.round == 2) {
return; return;
} }
console.log('data.boatIdx = ', data.boatIdx);
this.gameStatus.boats[data.boatIdx][data.playerId] = 'wrong'; this.gameStatus.boats[data.boatIdx][data.playerId] = 'wrong';
this.networkHelper.sendFrame({ this.networkHelper.sendFrame({
type: "SERVER_updateStatus", type: "SERVER_updateStatus",
...@@ -161,20 +169,52 @@ export class GameServer { ...@@ -161,20 +169,52 @@ export class GameServer {
} }
} }
timeOutFlg = false;
firstCompletePlayerId;
checkover() { checkover() {
if (this.gameStatus.boats if (!this.firstCompletePlayerId) {
.filter(boat => boat.show) this.playerList.forEach(player => {
.every(boat => Object.keys(boat).length == 3) if (this.gameStatus.boats.every(boat => boat[player.uuid])) {
) { this.firstCompletePlayerId = player.uuid;
this.gameStatus.round++; }
this.gameStatus.boats.forEach(boat => {
boat.show = !boat.show;
});
this.networkHelper.sendFrame({
type: "SERVER_updateStatus",
status: this.gameStatus,
}); });
} }
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() { startAI() {
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -9,7 +9,18 @@ const { ccclass, property } = cc._decorator; ...@@ -9,7 +9,18 @@ const { ccclass, property } = cc._decorator;
export default class SceneComponent extends MyCocosSceneComponent { export default class SceneComponent extends MyCocosSceneComponent {
addPreloadImage() { addPreloadImage() {
// this._imageResList.push({ url: this.data.pic_url }); this._imageResList.push({ url: this.data.audioOnEnterMatch });
this._imageResList.push({ url: this.data.audioOnEnterGame });
this._imageResList.push({ url: this.data.auidoDuringGame });
this._imageResList.push({ url: this.data.audioOnFirstTest });
this._imageResList.push({ url: this.data.audioDuringTest });
this._imageResList.push({ url: this.data.audioRight });
this._imageResList.push({ url: this.data.audioWrong });
this._imageResList.push({ url: this.data.audioWinInTime });
this._imageResList.push({ url: this.data.audioLossInTime });
this._imageResList.push({ url: this.data.audioWinOutTime });
this._imageResList.push({ url: this.data.audioLossOutTime });
this._imageResList.push({ url: this.data.audioAfterGame });
} }
onLoadEnd() { onLoadEnd() {
...@@ -53,7 +64,10 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -53,7 +64,10 @@ export default class SceneComponent extends MyCocosSceneComponent {
if (this.playerId == room.roomInfo.owner) { if (this.playerId == room.roomInfo.owner) {
console.log("房主"); console.log("房主");
this.isRoomOwner = true; this.isRoomOwner = true;
const serverParams = { testDuration: this.data.testDuration }; const serverParams = {
testDuration: this.data.testDuration,
roundTime: this.data.roundTime,
};
this.server = new GameServer(2, this.networkHelper, serverParams); this.server = new GameServer(2, this.networkHelper, serverParams);
await this.networkHelper.startFrameSync(); await this.networkHelper.startFrameSync();
this.server.addPlayer({ this.server.addPlayer({
...@@ -143,20 +157,16 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -143,20 +157,16 @@ export default class SceneComponent extends MyCocosSceneComponent {
}); });
if (this._status.round == 0 && serverStatus.round == 1) { if (this._status.round == 0 && serverStatus.round == 1) {
this._status.round = serverStatus.round; this._status.round = serverStatus.round;
this.playAudioByUrl(this.data.audioOnEnterGame);
this.initCountDown(this.onTimerFinish.bind(this)); this.initCountDown(this.onTimerFinish.bind(this));
this.initBoats(); this.initBoats();
} else if (this._status.round == 1 && serverStatus.round == 2) {
this._status.round = serverStatus.round;
this.initBoats();
} else { } else {
this._status.round = serverStatus.round;
this.updateBoats(); this.updateBoats();
} }
this.updateProgress(); this.updateProgress();
} else if (item.data.type == "SERVER_playerWin") { } else if (item.data.type == "SERVER_playerWin") {
const playerMe = this.allPlayerList.find( if (item.data.winnerId == this.playerId) {
(player) => player.uuid == this.playerId
);
if (playerMe.color == this._status.current) {
this.showWin(); this.showWin();
onHomeworkFinish({ isWin: true }); onHomeworkFinish({ isWin: true });
} else { } else {
...@@ -169,10 +179,36 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -169,10 +179,36 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
showWin() { showWin() {
if (this._status.boats.every(boat => boat[this.playerId])) {
this.playAudioByUrl(this.data.audioWinInTime);
} else {
this.playAudioByUrl(this.data.audioWinOutTime);
}
const youWin = cc.find('Canvas/bg/youWin');
youWin.active = true;
const bg = cc.find('Canvas/bg/youWin/bg');
cc.tween(bg)
.set({ opacity: 0 })
.to(0.5, { opacity: 100 })
.start();
const frame = cc.find('Canvas/bg/youWin/frame');
frame.scale = bg.width / frame.width;
} }
showLoss() { showLoss() {
if (this._status.boats.every(boat => boat[this.playerId])) {
this.playAudioByUrl(this.data.audioLossInTime);
} else {
this.playAudioByUrl(this.data.audioLossOutTime);
}
const youLoss = cc.find('Canvas/bg/youLoss');
youLoss.active = true;
const bg = cc.find('Canvas/bg/youLoss/bg');
cc.tween(bg)
.set({ opacity: 0 })
.to(0.5, { opacity: 100 })
.start();
const frame = cc.find('Canvas/bg/youLoss/frame');
frame.scale = bg.width / frame.width;
} }
async initHeadImgAndName() { async initHeadImgAndName() {
...@@ -199,6 +235,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -199,6 +235,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
async initView() { async initView() {
this.playAudioByUrl(this.data.audioOnEnterMatch);
this.initProgress(); this.initProgress();
this.initBubbles(); this.initBubbles();
this.initLoadingLayer(); this.initLoadingLayer();
...@@ -210,10 +247,15 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -210,10 +247,15 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
onTimerFinish() { onTimerFinish() {
// this._status.round = 2;
} }
startQuestionFirstTime = true;
async startQuestion(idx: number) { async startQuestion(idx: number) {
if (this.startQuestionFirstTime) {
this.startQuestionFirstTime = false;
this.playAudioByUrl(this.data.audioOnFirstTest);
}
this.showTestFrame(); this.showTestFrame();
this.showTestImage(idx); this.showTestImage(idx);
const words = [ const words = [
...@@ -322,6 +364,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -322,6 +364,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
showGoodJob() { showGoodJob() {
return new Promise((resolve) => { return new Promise((resolve) => {
this.playAudioByUrl(this.data.audioRight);
const result = cc.find('Canvas/testBg/result'); const result = cc.find('Canvas/testBg/result');
result.active = true; result.active = true;
const goodjob = cc.find('Canvas/testBg/result/goodjob'); const goodjob = cc.find('Canvas/testBg/result/goodjob');
...@@ -343,6 +386,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -343,6 +386,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
showNiceTry() { showNiceTry() {
return new Promise((resolve) => { return new Promise((resolve) => {
this.playAudioByUrl(this.data.audioWrong);
const result = cc.find('Canvas/testBg/result'); const result = cc.find('Canvas/testBg/result');
result.active = true; result.active = true;
const goodjob = cc.find('Canvas/testBg/result/goodjob'); const goodjob = cc.find('Canvas/testBg/result/goodjob');
...@@ -363,6 +407,13 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -363,6 +407,13 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
initBoats() { initBoats() {
const words = [
'toad', 'new', 'coat', 'boot',
'yellow', 'fruit', 'cube', 'window',
'moon', 'zoo', 'elbow', 'bow',
'suit', 'boat', 'blue', 'goat'
];
for (let i = 0; i < 16; i++) { for (let i = 0; i < 16; i++) {
const boatNode = cc.find(`Canvas/bg/boats/boat_${i}`); const boatNode = cc.find(`Canvas/bg/boats/boat_${i}`);
boatNode.removeComponent(cc.Sprite); boatNode.removeComponent(cc.Sprite);
...@@ -372,7 +423,48 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -372,7 +423,48 @@ export default class SceneComponent extends MyCocosSceneComponent {
const boat = cc.instantiate(cc.find('boat')); const boat = cc.instantiate(cc.find('boat'));
boat.parent = boatNode; boat.parent = boatNode;
boat.name = 'boat'; boat.name = 'boat';
boat.setPosition(0, 0); boat.setPosition(2500 + boat.parent.x, 0);
const label = boat.getChildByName('label');
label.getComponent(cc.Label).string = words[i];
const image = cc.find(`images/img_${i}`);
const icon = boat.getChildByName('icon');
icon.getComponent(cc.Sprite).spriteFrame = image.getComponent(cc.Sprite).spriteFrame;
const btn = boat.getChildByName('btn');
btn.on('click', () => {
this.startQuestion(i);
});
const phone = boat.getChildByName('phone');
cc.tween(boat)
.delay(2 + Math.random() * 2)
.to(2, { x: 0 }, { easing: 'quadOut' })
.call(() => {
label.active = false;
phone.active = true;
})
.start();
}
}
}
initOtherBoats() {
const words = [
'toad', 'new', 'coat', 'boot',
'yellow', 'fruit', 'cube', 'window',
'moon', 'zoo', 'elbow', 'bow',
'suit', 'boat', 'blue', 'goat'
];
for (let i = 0; i < 16; i++) {
const boatNode = cc.find(`Canvas/bg/boats/boat_${i}`);
if (!this._status.boats[i].show) {
const boat = cc.instantiate(cc.find('boat'));
boat.parent = boatNode;
boat.name = 'boat';
boat.setPosition(2500 + boat.parent.x, 0);
const label = boat.getChildByName('label');
label.getComponent(cc.Label).string = words[i];
const image = cc.find(`images/img_${i}`); const image = cc.find(`images/img_${i}`);
const icon = boat.getChildByName('icon'); const icon = boat.getChildByName('icon');
icon.getComponent(cc.Sprite).spriteFrame = image.getComponent(cc.Sprite).spriteFrame; icon.getComponent(cc.Sprite).spriteFrame = image.getComponent(cc.Sprite).spriteFrame;
...@@ -381,6 +473,16 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -381,6 +473,16 @@ export default class SceneComponent extends MyCocosSceneComponent {
btn.on('click', () => { btn.on('click', () => {
this.startQuestion(i); this.startQuestion(i);
}); });
const phone = boat.getChildByName('phone');
cc.tween(boat)
.delay(2 + Math.random() * 2)
.to(2, { x: 0 }, { easing: 'quadOut' })
.call(() => {
label.active = false;
phone.active = true;
})
.start();
} }
} }
} }
...@@ -389,33 +491,30 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -389,33 +491,30 @@ export default class SceneComponent extends MyCocosSceneComponent {
for (let i = 0; i < 16; i++) { for (let i = 0; i < 16; i++) {
const boat = cc.find(`Canvas/bg/boats/boat_${i}/boat`); const boat = cc.find(`Canvas/bg/boats/boat_${i}/boat`);
const boatData = this._status.boats[i]; const boatData = this._status.boats[i];
if (boatData.show) { if (!boat) {
if (boatData[this.playerId] == 'wrong') { continue;
boat.active = true; }
const lock = boat.getChildByName('lock'); if (boatData[this.playerId] == 'wrong') {
lock.active = true; boat.active = true;
const btn = boat.getChildByName('btn'); const lock = boat.getChildByName('lock');
btn.active = false; lock.active = true;
const phone = boat.getChildByName('phone'); const btn = boat.getChildByName('btn');
phone.active = false; btn.active = false;
} else if (boatData[this.playerId] == 'right') { const phone = boat.getChildByName('phone');
const btn = boat.getChildByName('btn'); phone.active = false;
btn.active = false; } else if (boatData[this.playerId] == 'right') {
const phone = boat.getChildByName('phone'); const btn = boat.getChildByName('btn');
phone.active = false; btn.active = false;
if (boat.active == true && !boat['tween']) { const phone = boat.getChildByName('phone');
boat['tween'] = cc.tween(boat) phone.active = false;
.to(0.5, { scale: 2, opacity: 0 }) if (boat.active == true && !boat['tween']) {
.call(() => { boat['tween'] = cc.tween(boat)
boat.active = false; .to(0.5, { scale: 2, opacity: 0 })
boat['tween'] = null; .call(() => {
}) boat.active = false;
.start(); boat['tween'] = null;
} })
} .start();
} else {
if (boat) {
boat.active = false;
} }
} }
} }
...@@ -507,6 +606,20 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -507,6 +606,20 @@ export default class SceneComponent extends MyCocosSceneComponent {
if (shakeRight) { if (shakeRight) {
this.shakeProgress('Right'); this.shakeProgress('Right');
} }
if (this.isRoomOwner) {
if (leftRightNumber + leftWrongNumber == 8) {
if (shakeLeft) {
this.initOtherBoats();
}
}
} else {
if (rightRightNumber + rightWrongNumber == 8) {
if (shakeRight) {
this.initOtherBoats();
}
}
}
} }
shakeProgress(side: string) { shakeProgress(side: string) {
...@@ -546,7 +659,6 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -546,7 +659,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
box.parent = layoutLeft; box.parent = layoutLeft;
box.name = `box_${i}`; box.name = `box_${i}`;
this.changeNodeGray(box); this.changeNodeGray(box);
// this.changeNodeColor(box);
} }
const layoutRight = cc.find('Canvas/bg/progress2/layout'); const layoutRight = cc.find('Canvas/bg/progress2/layout');
for (let i = 0; i < 16; i++) { for (let i = 0; i < 16; i++) {
......
export const defaultData = { export const defaultData = {
roundTime: 80, roundTime: 80,
testDuration: 5, 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