Commit 43515f55 authored by Tt's avatar Tt

游戏完成

parent 1c657840
{
"ver": "2.0.1",
"uuid": "bafa1aa4-6376-4c89-8d02-e2fb6df24456",
"downloadMode": 0,
"duration": 4.04898,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "b10193a0-5d02-4884-9a04-36a14bb0a4ba",
"downloadMode": 0,
"duration": 2.220417,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "c3a0e501-c3ba-4e12-b5f8-1035f48524fe",
"downloadMode": 0,
"duration": 0.182857,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "d1e763b0-65c4-476a-b702-789e1b46ddff",
"downloadMode": 0,
"duration": 0.261224,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "e87f6086-9efd-4adf-982c-bcddc6b1115e",
"downloadMode": 0,
"duration": 0.809796,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "5da8b129-4fec-4b5b-936a-336cb269d6fb",
"downloadMode": 0,
"duration": 1.906939,
"subMetas": {}
}
\ No newline at end of file
This diff is collapsed.
...@@ -10,6 +10,7 @@ enum CELLTYPE { ...@@ -10,6 +10,7 @@ enum CELLTYPE {
ROLL_AGAIN = 3, ROLL_AGAIN = 3,
DELAY_TIME = 4, DELAY_TIME = 4,
JUMP_ROLL = 5, JUMP_ROLL = 5,
WIN = 100,
} }
@ccclass @ccclass
export default class SceneComponent extends MyCocosSceneComponent { export default class SceneComponent extends MyCocosSceneComponent {
...@@ -79,8 +80,11 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -79,8 +80,11 @@ export default class SceneComponent extends MyCocosSceneComponent {
onGameStart() { onGameStart() {
this.playerPoint = 0; this.playerPoint = 0;
this.robotPoint = 0; this.robotPoint = 0;
this.turnRobot = false; this.turnRobot = Math.random() < 0.5;
this.startTouzi(); this.initChess();
setTimeout(() => {
this.startTouzi();
}, 2100);
} }
onSpeakScueess() { onSpeakScueess() {
//执行后续的动作。 //执行后续的动作。
...@@ -88,7 +92,11 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -88,7 +92,11 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
onSpeakFail() { onSpeakFail() {
//回退到最后一个位置 //回退到最后一个位置
this.turnNext(); let cell = map[this.playerPoint];
this.jumpChess(cell, this.lastPointId).then(() => {
this.turnNext();
})
} }
turnNext() { turnNext() {
this.turnRobot = !this.turnRobot; this.turnRobot = !this.turnRobot;
...@@ -101,6 +109,11 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -101,6 +109,11 @@ export default class SceneComponent extends MyCocosSceneComponent {
//初始化棋子 //初始化棋子
this.chessPlayer = pg.view.find(this, "chess/chess_player"); this.chessPlayer = pg.view.find(this, "chess/chess_player");
this.chessRobot = pg.view.find(this, "chess/chess_robot"); this.chessRobot = pg.view.find(this, "chess/chess_robot");
let point = map[0];
this.chessPlayer.x = Number(point.yellow_x);
this.chessPlayer.y = Number(point.yellow_y);
this.chessRobot.x = Number(point.blue_x);
this.chessRobot.y = Number(point.blue_y);
} }
getMovePoints(now, runNum) { getMovePoints(now, runNum) {
let points = []; let points = [];
...@@ -169,6 +182,9 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -169,6 +182,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.checkCell(); this.checkCell();
}) })
break; break;
case CELLTYPE.WIN:
this.gameOver();
break;
default: default:
this.turnNext(); this.turnNext();
break; break;
...@@ -181,7 +197,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -181,7 +197,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
let type = Number(cell.type); let type = Number(cell.type);
switch (type) { switch (type) {
case CELLTYPE.SPEAK: case CELLTYPE.SPEAK:
pg.event.emit("speak_open") pg.event.emit("speak_open", cell)
break; break;
case CELLTYPE.DELAY_TIME: case CELLTYPE.DELAY_TIME:
setTimeout(() => { setTimeout(() => {
...@@ -202,6 +218,9 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -202,6 +218,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.checkCell(); this.checkCell();
}) })
break; break;
case CELLTYPE.WIN:
this.gameOver();
break;
default: default:
this.turnNext(); this.turnNext();
break; break;
...@@ -218,11 +237,16 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -218,11 +237,16 @@ export default class SceneComponent extends MyCocosSceneComponent {
if (this.turnRobot) return; if (this.turnRobot) return;
this.stopTouzi(); this.stopTouzi();
} }
lastPointId: number;
stopTouzi(runNum = 0) { stopTouzi(runNum = 0) {
pg.audio.stopAudio(this.touziAudio);
let touzi_ani = pg.view.find(this, "touzi_ani"); let touzi_ani = pg.view.find(this, "touzi_ani");
let icon = pg.view.find(touzi_ani, "icon"); let icon = pg.view.find(touzi_ani, "icon");
let touzi = icon.getComponent("touzi"); let touzi = icon.getComponent("touzi");
let hand = pg.view.find(touzi_ani, "hand"); let hand = pg.view.find(touzi_ani, "hand");
let btn_stop = pg.view.find(touzi_ani, "btn_stop");
btn_stop.active = false;
this.lastPointId = this.playerPoint + 1;
if (!runNum) { if (!runNum) {
runNum = 1 + Math.floor(Math.random() * 6); runNum = 1 + Math.floor(Math.random() * 6);
if (this.turnRobot) runNum = 1 + Math.floor(Math.random() * 5); if (this.turnRobot) runNum = 1 + Math.floor(Math.random() * 5);
...@@ -238,25 +262,52 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -238,25 +262,52 @@ export default class SceneComponent extends MyCocosSceneComponent {
}) })
} }
private stopHandTimer: number; private stopHandTimer: number;
private touziAudio: number;
startTouzi() { startTouzi() {
let touzi_ani = pg.view.find(this, "touzi_ani"); let touzi_ani = pg.view.find(this, "touzi_ani");
let icon = pg.view.find(touzi_ani, "icon"); let icon = pg.view.find(touzi_ani, "icon");
let touzi = icon.getComponent("touzi"); let touzi = icon.getComponent("touzi");
let hand = pg.view.find(touzi_ani, "hand"); let hand = pg.view.find(touzi_ani, "hand");
let btn_stop = pg.view.find(touzi_ani, "btn_stop");
btn_stop.active = true;
touzi_ani.active = true; touzi_ani.active = true;
touzi.startAni(); touzi.startAni();
if (this.turnRobot) { if (this.turnRobot) {
setTimeout(() => { setTimeout(() => {
this.stopTouzi(); this.stopTouzi();
}, 100); }, 300 + Math.random() * 200);
} else { } else {
this.stopHandTimer = setTimeout(() => { this.stopHandTimer = setTimeout(() => {
hand.active = true; hand.active = true;
}, 5000); }, 5000);
} }
pg.hw.playLocalAudio("touzi", true).then((id: number) => {
this.touziAudio = id;
})
}
//----------------------------OVER-------------------
gameOver() {
let state = pg.view.find(this, "state");
let bg_win = pg.view.find(state, "bg_win");
let bg_lose = pg.view.find(state, "bg_lose");
pg.view.visible(state, true);
if (this.playerPoint > this.robotPoint) {
pg.view.visible(bg_win, true);
pg.view.visible(bg_lose, false);
pg.hw.playLocalAudio("flower");
} else {
pg.view.visible(bg_win, false);
pg.view.visible(bg_lose, true);
}
setTimeout(() => {
pg.view.visible(bg_win, false);
pg.view.visible(bg_lose, false);
pg.event.emit("game_over");
}, 5000);
// onHomeworkFinish最后需要添加作业完成
onHomeworkFinish();
} }
//-----------------------------TOOL------------------------------- //-----------------------------TOOL-------------------------------
// onHomeworkFinish最后需要添加作业完成
playLocalAudio(audioName) { playLocalAudio(audioName) {
const audio = cc.find(`Canvas/res/audio/${audioName}`).getComponent(cc.AudioSource); const audio = cc.find(`Canvas/res/audio/${audioName}`).getComponent(cc.AudioSource);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
......
...@@ -38,7 +38,8 @@ export default class NewClass extends cc.Component { ...@@ -38,7 +38,8 @@ export default class NewClass extends cc.Component {
id: i, id: i,
time: 0.2, time: 0.2,
x: pos.x, x: pos.x,
y: pos.y y: pos.y,
audionode: "star"
}) })
} }
movement.loadTween(this.node, movementList).then(() => { movement.loadTween(this.node, movementList).then(() => {
......
This diff is collapsed.
...@@ -428,6 +428,21 @@ let pg = { ...@@ -428,6 +428,21 @@ let pg = {
} }
}, },
audio: {
stopAudio(audioId) {
if (!audioId) return;
cc.audioEngine.stopEffect(audioId);
}
},
hw: {
playLocalAudio(audioName, loop = false) {
const audio = cc.find(`Canvas/res/audio/${audioName}`).getComponent(cc.AudioSource);
return new Promise((resolve, reject) => {
const id = cc.audioEngine.playEffect(audio.clip, loop);
resolve(id);
})
}
},
event: Emitter.getInstance() event: Emitter.getInstance()
}; };
export default pg; export default pg;
\ No newline at end of file
...@@ -42,11 +42,20 @@ export default class NewClass extends cc.Component { ...@@ -42,11 +42,20 @@ export default class NewClass extends cc.Component {
pg.view.touchOn(this.btn_audio_start, this.onTouchStart, this); pg.view.touchOn(this.btn_audio_start, this.onTouchStart, this);
pg.view.touchOn(this.btn_audio_stop, this.onTouchStop, this); pg.view.touchOn(this.btn_audio_stop, this.onTouchStop, this);
this.tryCount = 0;
pg.event.on("speak_open", () => { this.open() }) pg.event.on("speak_open", (data) => {
this.tryCount = 0;
this.open(data)
})
} }
open() { private tryCount: number;
private val: string;
open(cell) {
if (cell) {
this.val = cell.value;
}
this.text_tip.active = true; this.text_tip.active = true;
this.btn_audio_start.active = true; this.btn_audio_start.active = true;
this.btn_audio_stop.active = false; this.btn_audio_stop.active = false;
...@@ -67,8 +76,47 @@ export default class NewClass extends cc.Component { ...@@ -67,8 +76,47 @@ export default class NewClass extends cc.Component {
pg.view.playDBAnimation(this.speak_ske, "newAnimation", 0); pg.view.playDBAnimation(this.speak_ske, "newAnimation", 0);
this.btn_audio_start.active = false; this.btn_audio_start.active = false;
this.btn_audio_stop.active = true; this.btn_audio_stop.active = true;
let win: any = window;
win.courseware && win.courseware.startTest(this.val); //开始录音
} }
onTouchStop() { onTouchStop() {
this.btn_audio_start.active = false;
this.btn_audio_stop.active = false;
let win: any = window;
if (!win.courseware) {
setTimeout(() => {
let data = {
"dtLastResponse": "2021-09-17 13:36:26:109",
"refText": "I haven't found anything out about him yet.",
"recordId": "6144295213f0a2200000ed93",
"eof": 1,
"result": {
"pronunciation": 25,
"resource_version": "3.1.0",
"fluency": 60,
"rhythm": 90,
"kernel_version": "5.2.4",
"overall": 75,
"integrity": 100,
"duration": "6.779",
"rear_tone": "fall",
"speed": 96,
},
"tokenId": "6144295408558b08dd000001",
"applicationId": "154838659000009e"
};
this.onRealStop(data.result.overall);
}, 100);
} else {
win.courseware && win.courseware.stopTest((data: any) => {
data = JSON.parse(data);
this.onRealStop(data.result.overall);
});
}
}
onRealStop(score) {
pg.view.playDBAnimation(this.speak_ske, "newAnimation", 1); pg.view.playDBAnimation(this.speak_ske, "newAnimation", 1);
this.text_tip.active = false; this.text_tip.active = false;
this.btn_audio_start.active = false; this.btn_audio_start.active = false;
...@@ -78,7 +126,8 @@ export default class NewClass extends cc.Component { ...@@ -78,7 +126,8 @@ export default class NewClass extends cc.Component {
this.bg_tryagain.active = false; this.bg_tryagain.active = false;
setTimeout(() => { setTimeout(() => {
let score = Math.random() * 100 + 50; // let score = Math.random() * 100 - 50;
pg.hw.playLocalAudio("goodjob");
if (score > 50) { if (score > 50) {
this.bg_goodjob.active = true; this.bg_goodjob.active = true;
setTimeout(() => { setTimeout(() => {
...@@ -86,14 +135,26 @@ export default class NewClass extends cc.Component { ...@@ -86,14 +135,26 @@ export default class NewClass extends cc.Component {
pg.event.emit("speak_success"); pg.event.emit("speak_success");
}, 2000); }, 2000);
} else { } else {
this.bg_tryagain.active = true; if (this.tryCount >= 1) {
//需要处理提供两次机会。重置一次到open状态 this.bg_tryagain.active = true;
setTimeout(() => { pg.hw.playLocalAudio("tryagain");
this.close(); this.tryCount++;
pg.event.emit("speak_fail"); //需要处理提供两次机会。重置一次到open状态
}, 2000); setTimeout(() => {
this.close();
pg.event.emit("speak_fail");
}, 2000);
} else {
this.bg_tryagain.active = true;
pg.hw.playLocalAudio("tryagain");
this.tryCount++;
setTimeout(() => {
this.open(null);
}, 1000);
}
} }
}, 200); }, 300);
} }
start() { start() {
......
...@@ -14,15 +14,27 @@ export default class NewClass extends cc.Component { ...@@ -14,15 +14,27 @@ export default class NewClass extends cc.Component {
// LIFE-CYCLE CALLBACKS: // LIFE-CYCLE CALLBACKS:
onLoad() { onLoad() {
this.initView();
let panel_gray = pg.view.find(this, "panel_gray"); let panel_gray = pg.view.find(this, "panel_gray");
let btn_start = pg.view.find(this, "btn_start"); let btn_start = pg.view.find(this, "btn_start");
let btn_restart = pg.view.find(this, "btn_restart"); let btn_restart = pg.view.find(this, "btn_restart");
let bg_vs = pg.view.find(this, "bg_vs"); let bg_vs = pg.view.find(this, "bg_vs");
pg.view.touchOn(btn_start, this.onTouchStart, this); pg.view.touchOn(btn_start, this.onTouchStart, this);
pg.view.touchOn(btn_restart, this.onTouchRestart, this);
pg.event.on("game_over", () => {
this.onGameOver();
})
}
initView() {
let panel_gray = pg.view.find(this, "panel_gray");
let btn_start = pg.view.find(this, "btn_start");
let btn_restart = pg.view.find(this, "btn_restart");
let bg_vs = pg.view.find(this, "bg_vs");
panel_gray.active = true; panel_gray.active = true;
btn_start.active = true; btn_start.active = true;
} }
onTouchStart() { onTouchStart() {
pg.hw.playLocalAudio("vs");
let panel_gray = pg.view.find(this, "panel_gray"); let panel_gray = pg.view.find(this, "panel_gray");
let btn_start = pg.view.find(this, "btn_start"); let btn_start = pg.view.find(this, "btn_start");
let btn_restart = pg.view.find(this, "btn_restart"); let btn_restart = pg.view.find(this, "btn_restart");
...@@ -30,11 +42,35 @@ export default class NewClass extends cc.Component { ...@@ -30,11 +42,35 @@ export default class NewClass extends cc.Component {
panel_gray.active = true; panel_gray.active = true;
btn_start.active = false; btn_start.active = false;
bg_vs.active = true; bg_vs.active = true;
pg.event.emit("game_start");
setTimeout(() => { setTimeout(() => {
bg_vs.active = false; bg_vs.active = false;
panel_gray.active = false; panel_gray.active = false;
pg.event.emit("game_start") }, 2000);
}, 100); }
onTouchRestart() {
pg.hw.playLocalAudio("vs");
let panel_gray = pg.view.find(this, "panel_gray");
let btn_start = pg.view.find(this, "btn_start");
let btn_restart = pg.view.find(this, "btn_restart");
let bg_vs = pg.view.find(this, "bg_vs");
panel_gray.active = true;
btn_start.active = false;
btn_restart.active = false;
bg_vs.active = true;
setTimeout(() => {
bg_vs.active = false;
panel_gray.active = false;
btn_restart.active = false;
pg.event.emit("game_start");
}, 2000);
}
onGameOver() {
let panel_gray = pg.view.find(this, "panel_gray");
let btn_restart = pg.view.find(this, "btn_restart");
let bg_vs = pg.view.find(this, "bg_vs");
panel_gray.active = true;
btn_restart.active = true;
} }
update(dt) { } update(dt) { }
} }
...@@ -57,7 +57,7 @@ export default class NewClass extends cc.Component { ...@@ -57,7 +57,7 @@ export default class NewClass extends cc.Component {
this.playing = false; this.playing = false;
setTimeout(() => { setTimeout(() => {
resolve(''); resolve('');
}, 100); }, 1500);
}); });
} }
start() { start() {
......
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