Commit 433b549c authored by Tt's avatar Tt

游戏已完成

parent 2030376a
{
"ver": "2.0.1",
"uuid": "e7bef66a-c0b7-4cb2-b26c-08b7b287f86f",
"downloadMode": 0,
"duration": 1.28,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "3d83ebd7-1d06-43e0-ad6c-4e0148dce170",
"downloadMode": 0,
"duration": 0.470204,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "23331216-135b-4d59-a284-30f0be0d55b0",
"downloadMode": 0,
"duration": 0.653061,
"subMetas": {}
}
\ No newline at end of file
import Data from "../script/defaultData";
interface Item {
id: number;
text: string;
pic: string;
type: string;
right: string;
}
export default class Game {
private static ins: Game;
public static getIns(): Game {
if (!Game.ins) Game.ins = new Game();
return Game.ins;
}
private data: Array<any>
private lists: Array<any>
private nowStem: any;
public pause: boolean;
public isRobot: boolean;
public playerScore: number;
public robotScore: number;
public robotLevel: number;
constructor() {
//
}
reset() {
this.data = Data.list;
this.lists = JSON.parse(JSON.stringify(Data.list));
this.pause = false;
// let winCount = 0;
// let nowItem = [];
// this.data.forEach(li => {
// winCount += li.stem.times;
// });
this.isRobot = false;
this.playerScore = 0;
this.robotScore = 0;
let rand = Math.random();
if (rand < 0.3) {
this.robotLevel = 0;//0 1 2 三个级别 0 最高
} else if (rand < 0.6) {
this.robotLevel = 1;//0 1 2 三个级别 0 最高
} else {
this.robotLevel = 2;//0 1 2 三个级别 0 最高
}
}
addScore() {
if (this.isRobot) {
this.robotScore++;
} else {
this.playerScore++;
}
this.nowStem.stem.times--;
this.nowStem = null;
}
get nowList() {
if (this.nowStem) {
return this.nowStem.list;
}
//每一个企鹅是什么应该在这边获取。
return [];
let items: any = this.lists.filter(li => {
return li.stem.times > 0;
});
let item = items[Math.floor(Math.random() * items.length)]
this.nowStem = item;
return item.list;
}
get isOver() {
let times = 0;
this.lists.forEach((li) => {
times += li.stem.times;
})
return times == 0;
}
get penguin() {
let item = null;
let item = this.nowList[Math.floor(Math.random() * this.nowList.length)];
return item;
}
}
\ No newline at end of file
This diff is collapsed.
......@@ -60,9 +60,7 @@ export default class NewClass extends MyCocosSceneComponent {
// 所有全局变量 默认都是null
this._cantouch = true;
Game.getIns().reset();
//开始显示企鹅
}
initView() {
this.log("test initView")
......@@ -71,50 +69,54 @@ export default class NewClass extends MyCocosSceneComponent {
this.log("test initEvent")
pg.event.on("game_start", () => { this.onGameStart() })
pg.event.on("item_touch_right", (data) => { this.onTouchRight(data) })
pg.event.on("speak_success", () => { this.onSpeakScueess() });
pg.event.on("speak_fail", () => { this.onSpeakFail() });
}
//-----------------------------流程------------------------------
private playerPoint: number;//
private robotPoint: number;//
private turnRobot: boolean;//当前是谁操作
private robotLevel: number;
onGameStart() {
this.log("test onGameStart")
this.playerPoint = 0;
this.robotPoint = 0;
this.turnRobot = Math.random() < 0.5;
let rand = Math.random();
if (rand < 0.3) {
this.robotLevel = 0;//0 1 2 三个级别 0 最高
} else if (rand < 0.6) {
this.robotLevel = 1;//0 1 2 三个级别 0 最高
Game.getIns().reset();
this.scheduleOnce(() => {
pg.event.emit("game_start_loop")
}, 2)
}
private touchData: any;
onTouchRight(data) {
if (Game.getIns().isRobot) {
this.onSpeakScueess();
} else {
this.robotLevel = 2;//0 1 2 三个级别 0 最高
this.touchData = data;
pg.event.emit("speak_open", data.text);
}
pg.event.emit("game_start_loop")
}
onSpeakScueess() {
//执行后续的动作。
this.turnNext();
this.touchData && this.touchData.cbSuccess && this.touchData.cbSuccess();
Game.getIns().addScore()
pg.event.emit("player_point_update");
if (Game.getIns().isOver) {
this.gameOver();
}
}
onSpeakFail() {
//回退到最后一个位置
this.touchData && this.touchData.cbFailed && this.touchData.cbFailed();
}
turnNext() {
this.turnRobot = !this.turnRobot;
}
//----------------------------小企鹅-------------------
//----------------------------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) {
if (Game.getIns().playerScore > Game.getIns().robotScore) {
pg.view.visible(bg_win, true);
pg.view.visible(bg_lose, false);
this.showFireFlower();
// pg.hw.playLocalAudio("flower");
} else {
pg.view.visible(bg_win, false);
pg.view.visible(bg_lose, true);
......
// Learn TypeScript:
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import Game from "./Game";
import pg from "./pg";
const { ccclass, property } = cc._decorator;
......@@ -16,32 +10,136 @@ export default class NewClass extends cc.Component {
private penguin: cc.Node;
private penguin_1: cc.Node;
private penguin_2: cc.Node;
private penguin_1_wrong: cc.Node;
private penguin_2_wrong: cc.Node;
private panel_text: cc.Node;
private txt: cc.Node;
private right: cc.Node;
private img: cc.Node;
onLoad() {
this.mask = pg.view.find(this, "mask");
this.penguin = pg.view.find(this.mask, "penguin");
this.penguin_1 = pg.view.find(this.penguin, "penguin_1");
this.penguin_2 = pg.view.find(this.penguin, "penguin_2");
this.penguin_1_wrong = pg.view.find(this.penguin, "penguin_1_wrong");
this.penguin_2_wrong = pg.view.find(this.penguin, "penguin_2_wrong");
this.panel_text = pg.view.find(this.penguin, "panel_text");
this.txt = pg.view.find(this.panel_text, "txt");
this.right = pg.view.find(this.panel_text, "right");
this.img = pg.view.find(this.panel_text, "img");
pg.view.touchOn(this.panel_text, this.onPlayerText, this);
}
start() {
let data = {
text: "info"
}
this.showAni(data);
// let data = {
// text: "info"
// }
// this.showAni(data);
}
private data: any;
private touched: boolean;
showAni(data) {
this.touched = false;
this.data = data;
this.penguin.y = -100;
this.panel_text.opacity = 0;
pg.view.setString(this.txt, data.text);
pg.view.visible(this.panel_text, true);
cc.tween(this.penguin).to(0.4, { y: 190 }).delay(1).to(0.4, { y: -100 }).delay(0.1).call(() => {
pg.view.visible(this.penguin_1, true);
pg.view.visible(this.penguin_2, false);
pg.view.visible(this.penguin_1_wrong, false);
pg.view.visible(this.penguin_2_wrong, false);
if (data.type == "text") {
pg.view.setString(this.txt, data.text);
pg.view.visible(this.img, false)
pg.view.visible(this.txt, true)
} else {
pg.view.setNetImg(this.img, data.pic, { w: 300, h: 100 });
pg.view.visible(this.img, true)
pg.view.visible(this.txt, false)
}
pg.hw.playLocalAudio("appear");
cc.tween(this.penguin).to(0.4, { y: 190 }).delay(2).to(0.4, { y: -100 }).delay(0.1).call(() => {
this.node.parent = null;
}).start();
cc.tween(this.panel_text).to(0.2, { opacity: 255 }).delay(1.4).to(0.2, { opacity: 0 }).start();
cc.tween(this.panel_text).to(0.2, { opacity: 255 }).delay(2.4).to(0.2, { opacity: 0 }).start();
let point = 6 - Game.getIns().robotLevel;//
if (data.right == "1") {
if (Math.random() * point >= 3) {
let time = 0.4 + Math.random() * 2 + Game.getIns().robotLevel * 0.65;
this.scheduleOnce(() => {
if (this.touched) return;
Game.getIns().isRobot = true;
this.onTouchText();
}, time);
}
}
}
showSuccessAni() {
Game.getIns().pause = false;
pg.hw.playLocalAudio("right");
cc.tween(this.penguin).to(0.4, { y: -100 }).delay(0.1).call(() => {
this.node.parent = null;
}).start();
cc.tween(this.panel_text).delay(0.2).to(0.2, { opacity: 0 }).start();
}
showErrorAni() {
pg.hw.playLocalAudio("wrong");
pg.view.visible(this.penguin_1, false);
pg.view.visible(this.penguin_2, false);
pg.view.visible(this.penguin_1_wrong, true);
pg.view.visible(this.penguin_2_wrong, false);
this.scheduleOnce(() => {
pg.view.visible(this.penguin_1, true);
pg.view.visible(this.penguin_2, false);
pg.view.visible(this.penguin_1_wrong, false);
pg.view.visible(this.penguin_2_wrong, false);
cc.tween(this.penguin).to(0.4, { y: -100 }).delay(0.1).call(() => {
this.node.parent = null;
}).start();
cc.tween(this.panel_text).delay(0.2).to(0.2, { opacity: 0 }).start();
}, 1)
}
onPlayerText() {
if (this.touched) return;
Game.getIns().isRobot = false;
this.onTouchText();
}
onTouchText() {
if (Game.getIns().isOver) return;
if (this.touched) return;
this.touched = true;
let data = this.data;
if (Game.getIns().isRobot) {
if (data.right == "1") {
pg.view.visible(this.right, true);
pg.hw.playLocalAudio("right");
pg.view.playDBAnimation(this.right, "newAnimation", 1);
pg.event.emit("item_touch_right", data);
}
} else {
cc.Tween.stopAllByTarget(this.penguin);
cc.Tween.stopAllByTarget(this.panel_text);
if (data.right == "1") {
Game.getIns().pause = true;
//正确
pg.view.visible(this.right, true);
pg.view.playDBAnimation(this.right, "newAnimation", 1);
data.cbSuccess = () => {
//执行
this.showSuccessAni();
}
data.cbFailed = () => {
this.showErrorAni();
}
pg.event.emit("item_touch_right", data);
} else {
//错误
// pg.event.emit("item_touch_error", data);
this.showErrorAni();
}
}
}
}
......@@ -5,6 +5,7 @@
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import Game from "./Game";
import pg from "./pg";
const { ccclass, property } = cc._decorator;
......@@ -32,15 +33,17 @@ export default class NewClass extends cc.Component {
}
startLoop() {
this.lastId = [];
this.unschedule(this.createItem);
this.schedule(this.createItem, 1);
}
pauseLoop() {
}
stopLoop() {
}
private lastId: number;
private lastId: Array<number>;
createItem() {
if (Game.getIns().pause || Game.getIns().isOver) return;
console.log("createItem");
let posList = [
cc.v2(-640, -13),
......@@ -53,16 +56,22 @@ export default class NewClass extends cc.Component {
cc.v2(640, -280)
];
let id = Math.floor(Math.random() * posList.length);
while (id == this.lastId) {
while (this.lastId.some(i => i == id)) {
id = Math.floor(Math.random() * posList.length);
}
this.lastId = id;
this.lastId.push(id);
if (this.lastId.length == 4) {
this.lastId.shift();
}
let layout = id <= 3 ? this.layout_up : this.layout_down;
let pos = posList[id];
let item = pg.view.clone(this.item);
item.x = pos.x;
item.y = pos.y;
layout.addChild(item);
let data = Game.getIns().penguin;
//设置item内部内容。
item.getComponent("item").showAni(data);
}
update(dt) {
......
......@@ -204,7 +204,7 @@ let pg = {
})
})
},
setNetImg(item, res) {
setNetImg(item, res, { w, h }) {
return new Promise((resolve, reject) => {
if (!item) return pg.logger.w("图片更换失败,传入了错误的item");
let node = item.node ? item.node : item;
......@@ -214,8 +214,6 @@ let pg = {
}
if (!node) return pg.logger.w("图片更换失败,传入了错误的item");
if (node.net_url == res) return;
let w = node.width;
let h = node.height;
node.active = false;//
pg.load.loadNetImg(res).then((texture: cc.Texture2D) => {
if (!cc.isValid(node)) return pg.logger.i("节点已销毁");
......@@ -227,8 +225,13 @@ let pg = {
node.net_url = res;
if (!cc.isValid(node)) return pg.logger.i("节点已销毁");
if (!node) return pg.logger.w("节点已销毁");
node.width = w;
node.height = h;
if (w && h) {
let scaleX = w / nw;
let scaleY = h / nh;
let scale = scaleX <= scaleY ? scaleX : scaleY;
node.width = nw * scale;
node.height = nh * scale;
}
node.active = true;
resolve({ w: nw, h: nh });
})
......
import Game from "./Game";
import pg from "./pg";
const { ccclass, property } = cc._decorator;
......@@ -19,51 +20,30 @@ export default class NewClass extends cc.Component {
this.robot = pg.view.find(this, "robot");
pg.event.on("player_point_update", (data) => {
this.updatePlayer(data.isRobot, data.num);
this.updateRobot(data.isRobot, data.num);
})
}
protected onDestroy(): void {
pg.event.off("player_point_update");
}
updatePlayer(isRobot, num) {
if (!isRobot && num >= 1 && num <= 6) {
updatePlayer() {
let icon_player = pg.view.find(this.player, "icon_player");
let icon_player_dice = pg.view.find(this.player, "icon_player_dice");
pg.view.visible(icon_player, false);
pg.view.visible(icon_player_dice, true);
for (let i = 1; i <= 6; i++) {
let item = pg.view.find(icon_player_dice, "icon_" + i);
pg.view.visible(item, i == num);
pg.view.visible(icon_player, Game.getIns().isRobot);
pg.view.visible(icon_player_dice, !Game.getIns().isRobot);
}
} else {
let icon_player = pg.view.find(this.player, "icon_player");
let icon_player_dice = pg.view.find(this.player, "icon_player_dice");
pg.view.visible(icon_player, true);
pg.view.visible(icon_player_dice, false);
}
}
updateRobot(isRobot, num) {
if (isRobot && num >= 1 && num <= 6) {
let icon_robot = pg.view.find(this.robot, "icon_robot");
let icon_robot_dice = pg.view.find(this.robot, "icon_robot_dice");
pg.view.visible(icon_robot, false);
pg.view.visible(icon_robot_dice, true);
for (let i = 1; i <= 6; i++) {
let item = pg.view.find(icon_robot_dice, "icon_" + i);
pg.view.visible(item, i == num);
}
} else {
updateRobot() {
let icon_robot = pg.view.find(this.robot, "icon_robot");
let icon_robot_dice = pg.view.find(this.robot, "icon_robot_dice");
pg.view.visible(icon_robot, true);
pg.view.visible(icon_robot_dice, false);
pg.view.visible(icon_robot, !Game.getIns().isRobot);
pg.view.visible(icon_robot_dice, Game.getIns().isRobot);
}
updateScore() {
let score = pg.view.find(this, "score");
pg.view.setString(score, `${Game.getIns().playerScore} : ${Game.getIns().robotScore}`);
}
start() {
update(dt) {
this.updatePlayer();
this.updateRobot();
this.updateScore();
}
// update (dt) {}
}
......@@ -55,10 +55,8 @@ export default class NewClass extends cc.Component {
}
private tryCount: number;
private val: string;
open(cell) {
if (cell) {
this.val = cell.value;
}
open(value) {
this.val = value;
pg.view.visible(this.btn_audio_start, true);
pg.view.visible(this.btn_audio_stop, false);
pg.view.visible(this.speak_ske, true);
......
......@@ -4,14 +4,14 @@ export default {
{
"id": 0,
"stem": {
"times": 5
"times": 3
},
"list": [
{
"id": 2001, "text": "door", "pic": "", "type": "text", "right": "1"
},
{
"id": 2002, "text": "ijfs", "pic": "", "type": "text", "right": "1"
"id": 2002, "text": "ijfs", "pic": "", "type": "text", "right": "0"
},
{
"id": 2003, "text": "", "pic": "http://staging-teach.cdn.ireadabc.com/d0414e91f8519ece2909b15cedf23f08.png", "type": "pic", "right": "0"
......@@ -24,7 +24,7 @@ export default {
{
"id": 1,
"stem": {
"times": 4
"times": 2
},
"list":
[
......
This diff is collapsed.
{
"ver": "1.0.1",
"uuid": "1b5c954c-a0c5-48dd-845d-eab0a9940df9",
"subMetas": {}
}
\ No newline at end of file
{"name":"right","imagePath":"right_tex.png","height":256,"SubTexture":[{"name":"1/圆","x":1,"height":98,"y":1,"width":98},{"name":"1/星1","x":66,"height":59,"y":172,"width":57},{"name":"1/星2","x":71,"height":45,"y":101,"width":43},{"name":"1/星3","x":1,"height":64,"y":172,"width":63},{"name":"1/星4","x":183,"height":45,"y":172,"width":45},{"name":"1/星6","x":1,"height":69,"y":101,"width":68},{"name":"1/星7","x":116,"height":40,"y":101,"width":37},{"name":"1/星5","x":125,"height":57,"y":172,"width":56},{"name":"1/星8","x":183,"height":33,"y":219,"width":32},{"name":"1/星9","x":155,"height":37,"y":101,"width":36}],"width":256}
\ No newline at end of file
{
"ver": "1.0.1",
"uuid": "b9944f50-b741-469b-ab31-e9785ad80cca",
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "4f701593-065f-41ef-924a-2a9de8e214bb",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 256,
"height": 256,
"platformSettings": {},
"subMetas": {
"right_tex": {
"ver": "1.0.4",
"uuid": "92f25047-4c93-49a5-8633-865635e30517",
"rawTextureUuid": "4f701593-065f-41ef-924a-2a9de8e214bb",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": -13.5,
"offsetY": 1.5,
"trimX": 1,
"trimY": 1,
"width": 227,
"height": 251,
"rawWidth": 256,
"rawHeight": 256,
"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