Commit 6945f6fb authored by Tt's avatar Tt

界面基本刷新完成

parent ca6a8d11
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -16,10 +16,10 @@ class Card { ...@@ -16,10 +16,10 @@ class Card {
} }
} }
class defClass { class defClass {
constructor(id, name, dep) { constructor(id, title, dep) {
this.id = id; this.id = id;
this.dep = dep; this.dep = dep;
this.name = name; this.title = title;
this.child = []; this.child = [];
} }
addChild(child) { addChild(child) {
...@@ -52,6 +52,7 @@ class GameManager { ...@@ -52,6 +52,7 @@ class GameManager {
} }
constructor() { constructor() {
//主类 1 //主类 1
this._title = {};
this._allClass = []; this._allClass = [];
this._sonArray = [];//卡片数据解析 this._sonArray = [];//卡片数据解析
this._cardArray = [];//卡片数据解析 this._cardArray = [];//卡片数据解析
...@@ -60,44 +61,205 @@ class GameManager { ...@@ -60,44 +61,205 @@ class GameManager {
console.log(`init`); console.log(`init`);
this.parseData(); this.parseData();
} }
parseData() { parseData(data) {
let obj = [{ let obj = [{
id: 0, name: "zhulei", child: [ id: 0,
title: "biaoti",
child: [
{ {
id: 10, id: 0, title: "zhulei", child: [
name: "fenlei1",
child: [
{ {
id: 101, id: 10,
name: "sonlei1", title: "fenlei1",
child: [ child: [
{ {
id: 1001, id: 101,
name: "card1", title: "sonlei1",
title: "卡片1001", child: [
radioValue: "A" {
id: 1001,
title: "card1",
title: "卡片1001",
radioValue: "A"
},
{
id: 1002,
title: "card2",
title: "卡片1002",
radioValue: "A"
},
{
id: 1003,
title: "card3",
title: "卡片1003",
radioValue: "A"
},
{
id: 1004,
title: "card4",
title: "卡片1004",
radioValue: "A"
}
]
}, },
{ {
id: 1002, id: 101,
name: "card2", title: "sonlei2",
title: "卡片1002", child: [
radioValue: "A" {
id: 1001,
title: "card1",
title: "卡片1001",
radioValue: "A"
},
{
id: 1002,
title: "card2",
title: "卡片1002",
radioValue: "A"
},
{
id: 1003,
title: "card3",
title: "卡片1003",
radioValue: "A"
},
{
id: 1004,
title: "card4",
title: "卡片1004",
radioValue: "A"
}
]
}, },
{ {
id: 1003, id: 101,
name: "card3", title: "sonlei3",
title: "卡片1003", child: [
radioValue: "A" {
id: 1001,
title: "card1",
title: "卡片1001",
radioValue: "A"
},
{
id: 1002,
title: "card2",
title: "卡片1002",
radioValue: "A"
},
{
id: 1003,
title: "card3",
title: "卡片1003",
radioValue: "A"
},
{
id: 1004,
title: "card4",
title: "卡片1004",
radioValue: "A"
}
]
}
]
},
{
id: 10,
title: "fenlei2",
child: [
{
id: 201,
title: "sonlei4",
child: [
{
id: 1001,
title: "card2",
title: "卡片2001",
radioValue: "A"
},
{
id: 1002,
title: "card2",
title: "卡片2002",
radioValue: "A"
},
{
id: 1003,
title: "card3",
title: "卡片2003",
radioValue: "A"
},
{
id: 1004,
title: "card4",
title: "卡片2004",
radioValue: "A"
}
]
}, },
{ {
id: 1004, id: 201,
name: "card4", title: "sonlei5",
title: "卡片1004", child: [
radioValue: "A" {
id: 1001,
title: "card2",
title: "卡片2001",
radioValue: "A"
},
{
id: 1002,
title: "card2",
title: "卡片2002",
radioValue: "A"
},
{
id: 1003,
title: "card3",
title: "卡片2003",
radioValue: "A"
},
{
id: 1004,
title: "card4",
title: "卡片2004",
radioValue: "A"
}
]
},
{
id: 201,
title: "sonlei6",
child: [
{
id: 1001,
title: "card2",
title: "卡片2001",
radioValue: "A"
},
{
id: 1002,
title: "card2",
title: "卡片2002",
radioValue: "A"
},
{
id: 1003,
title: "card3",
title: "卡片2003",
radioValue: "A"
},
{
id: 1004,
title: "card4",
title: "卡片2004",
radioValue: "A"
}
]
} }
] ]
} }
] ]
} }
] ]
...@@ -105,17 +267,18 @@ class GameManager { ...@@ -105,17 +267,18 @@ class GameManager {
let fenId = 1; let fenId = 1;
let sonId = 100; let sonId = 100;
let cardId = 1000; let cardId = 1000;
for (let i = 0; i < obj.length; i++) { this._title = obj[0];
let zhulei = obj[i]; for (let i = 0; i < obj[0].child.length; i++) {
let zhuleiClass = new defClass(zhulei.id, zhulei.name, 0); let zhulei = obj[0].child[i];
let zhuleiClass = new defClass(zhulei.id, zhulei.title, 0);
for (let a = 0; a < zhulei.child.length; a++) { for (let a = 0; a < zhulei.child.length; a++) {
let fenlei = zhulei.child[a]; let fenlei = zhulei.child[a];
let fenleiClass = new defClass(fenId, fenlei.name, 1); let fenleiClass = new defClass(fenId, fenlei.title, 1);
fenId++;//只有1和2 fenId++;//只有1和2
for (let b = 0; b < fenlei.child.length; b++) { for (let b = 0; b < fenlei.child.length; b++) {
sonId++; sonId++;
let sonlei = fenlei.child[b]; let sonlei = fenlei.child[b];
let sonleiClass = new defClass(sonId, sonlei.name, 2); let sonleiClass = new defClass(sonId, sonlei.title, 2);
for (let c = 0; c < sonlei.child.length; c++) { for (let c = 0; c < sonlei.child.length; c++) {
let card = sonlei.child[c]; let card = sonlei.child[c];
cardId++; cardId++;
...@@ -132,18 +295,21 @@ class GameManager { ...@@ -132,18 +295,21 @@ class GameManager {
} }
console.log(this._allClass); console.log(this._allClass);
} }
getTitle() {
return this._title.title;
}
getZhuClass() { getZhuClass() {
return this._allClass[0]; return this._allClass[0];
} }
getFenClass(id) { getFenClass(id) {
return this._allClass[0].filter(fen => fen.id == id)[0]; return this._allClass[0].child.filter(fen => fen.id == id)[0];
} }
getSonClass(id) { getSonClass(id) {
return this._sonArray.filter(son => son.id == id)[0]; return this._sonArray.filter(son => son.id == id)[0];
} }
getCards() { getCards() {
//基础卡片列表 //基础卡片列表
return this._cardArray; return this._cardArray.concat();
} }
compareCard(cardId, sonId) { compareCard(cardId, sonId) {
let sonClass = this.getSonClass(sonId); let sonClass = this.getSonClass(sonId);
...@@ -156,4 +322,6 @@ class GameManager { ...@@ -156,4 +322,6 @@ class GameManager {
//[] [] [] [] [] []sonclass //[] [] [] [] [] []sonclass
//() () () () () () () ()card //() () () () () () () ()card
//() () () () () () () () //() () () () () () () ()
//() () () () () () () () //() () () () () () () ()
\ No newline at end of file
export default GameManager;
\ No newline at end of file
...@@ -232,6 +232,9 @@ pg.view = { ...@@ -232,6 +232,9 @@ pg.view = {
skl.setAnimation(0, aniName, loop); skl.setAnimation(0, aniName, loop);
return skl; return skl;
}, },
cloneNode(node) {
return cc.instantiate(node);
}
} }
//加载 未封装bundle //加载 未封装bundle
pg.load = { pg.load = {
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -2,7 +2,7 @@ import { onHomeworkFinish } from "../script/util"; ...@@ -2,7 +2,7 @@ import { onHomeworkFinish } from "../script/util";
import { defaultData } from "../script/defaultData"; import { defaultData } from "../script/defaultData";
import { itemData } from "./data"; import { itemData } from "./data";
import { hyLoader } from "./hyLoader"; import { hyLoader } from "./hyLoader";
import CardManager from "./cardManager"; import GameManager from "./gameManager";
import pg from "./pg"; import pg from "./pg";
import ani from "./ani"; import ani from "./ani";
import { asyncDelay, RandomInt, showFireworks } from "../script/utils"; import { asyncDelay, RandomInt, showFireworks } from "../script/utils";
...@@ -133,11 +133,13 @@ cc.Class({ ...@@ -133,11 +133,13 @@ cc.Class({
//---------------------------------项目代码开始--------------------------------- //---------------------------------项目代码开始---------------------------------
loadEnd() { loadEnd() {
// this.initData(); this.initData();
// this.initSingleData(); this.initSingleData();
// this.initAudio(); this.initAudio();
// this.initView(); this.initView();
this.initButton();
// this.initButton();
}, },
initButton() { initButton() {
//触碰判断 //触碰判断
...@@ -204,9 +206,9 @@ cc.Class({ ...@@ -204,9 +206,9 @@ cc.Class({
_gameCode: null, _gameCode: null,
initData() { initData() {
//数据解析 //数据解析
CardManager.getIns().initCards(this.data); GameManager.getIns().parseData(this.data);
CardManager.getIns().resetPageNum(); // GameManager.getIns().resetPageNum();
CardManager.getIns().randomPageCards(); // GameManager.getIns().randomPageCards();
this._gameCode = 0; this._gameCode = 0;
}, },
//单局游戏 //单局游戏
...@@ -216,22 +218,25 @@ cc.Class({ ...@@ -216,22 +218,25 @@ cc.Class({
_cardTouchItems: null, _cardTouchItems: null,
_successItems: null, _successItems: null,
initSingleData() { initSingleData() {
this._title = GameManager.getIns().getTitle();
this._zhuClass = GameManager.getIns().getZhuClass();
// 所有全局变量 默认都是null // 所有全局变量 默认都是null
this._cantouch = true; this._cantouch = true;
//界面用数据 //界面用数据
this._cardTouchItems = []; this._cardTouchItems = [];
this._successItems = []; this._successItems = [];
this._cardPage = CardManager.getIns().getPage(); // this._cardPage = CardManager.getIns().getPage();
cc.log(this._cardPage); // cc.log(this._cardPage);
}, },
initAudio() { initAudio() {
}, },
initView() { initView() {
this.btn_replay = pg.view.find(this, "btn_replay"); // this.btn_replay = pg.view.find(this, "btn_replay");
pg.view.visible(this.btn_replay, false); // pg.view.visible(this.btn_replay, false);
pg.view.touchOn(this.btn_replay, this.onTouchReplay, this); // pg.view.touchOn(this.btn_replay, this.onTouchReplay, this);
this.initStars(); // this.initStars();
this.initLayout(); this.initLayout();
}, },
initStars() { initStars() {
...@@ -239,123 +244,202 @@ cc.Class({ ...@@ -239,123 +244,202 @@ cc.Class({
this.addStar(); this.addStar();
}, },
initLayout() { initLayout() {
pg.view.visible(this.btn_replay, false); //根据当前显示用数据来执行对应的效果
pg.view.visible(pg.view.find(this, `layout_card_4`), false); pg.view.setString(pg.view.find(this, "title/txt"), this._title);
pg.view.visible(pg.view.find(this, `layout_card_6`), false); //刷新主类
pg.view.visible(pg.view.find(this, `layout_card_8`), false); pg.view.setString(pg.view.find(this, "box/main/txt"), this._zhuClass.title);
pg.view.visible(pg.view.find(this, `layout_card_10`), false); //刷新分类
this._cardLayout = pg.view.find(this, `layout_card_${this._cardPage.length}`); pg.view.setString(pg.view.find(this, "box/sub_0/txt"), this._zhuClass.child[0].title);
ani.scaleIn(this._cardLayout); pg.view.setString(pg.view.find(this, "box/sub_1/txt"), this._zhuClass.child[1].title);
pg.view.visible(this._cardLayout, true); this.initSon();
for (let i = 0; i < this._cardPage.length; i++) { this.initBox();
let data = this._cardPage[i]; this.initItems();
let item = pg.view.find(this._cardLayout, `item_${i}`); },
if (!data || !item || data.type == CardManager.TYPE_NULL) continue; initSon() {
this.updateItem(item, data); //刷新子类
let son = pg.view.find(this, "box/son_0");
let box = pg.view.find(this, "box");
let fenlei1 = this._zhuClass.child[0];
let fenlei2 = this._zhuClass.child[1];
let sonleis = fenlei1.child.concat(fenlei2.child);
let x = -480;//-291.057
let addX = 190;
let y = 75;
for (let i = 0; i < sonleis.length; i++) {
let sonClone = cc.instantiate(son);
sonClone.active = true;
let posX = x + addX * i;
let posY = y;
sonClone.x = posX;
sonClone.y = posY;
box.addChild(sonClone);
} }
}, },
updateItem(item, data) { initBox() {
let img = pg.view.find(item, `img`); //刷新子类
let txt = pg.view.find(item, `txt`); let son = pg.view.find(this, "box/box_0");
let audio = pg.view.find(item, `audio`); let box = pg.view.find(this, "box");
let box = pg.view.find(item, `box`); let fenlei1 = this._zhuClass.child[0];
console.log(CardManager.TYPE_IMG); let fenlei2 = this._zhuClass.child[1];
if (data.type == CardManager.TYPE_IMG) { let sonleis = fenlei1.child.concat(fenlei2.child);
pg.view.setNetImg(img, data.img); let x = -480;//-290
pg.view.visible(img, true); let addX = 190;
pg.view.visible(txt, false); let y = -62;
pg.view.visible(audio, false); for (let i = 0; i < sonleis.length; i++) {
} else if (data.type == CardManager.TYPE_TXT) { let sonClone = cc.instantiate(son);
pg.view.setString(txt, data.txt); sonClone.active = true;
pg.view.visible(img, false); let posX = x + addX * i;
pg.view.visible(txt, true); let posY = y;
pg.view.visible(audio, false); sonClone.x = posX;
} else if (data.type == CardManager.TYPE_MP3) { sonClone.y = posY;
pg.view.visible(img, false); box.addChild(sonClone);
pg.view.visible(txt, false);
pg.view.visible(audio, true);
pg.view.visible(pg.view.find(item, `audio/btn_laba`), true);
} }
item.scaleX = 1; },
item.scaleY = 1; initItems() {
pg.view.visible(box, false); //刷新子类
item.attr({ data: data }); let son = pg.view.find(this, "items/item");
pg.view.visible(item, true); let box = pg.view.find(this, "items");
pg.view.touchOn(item, this.onTouchItem, this); let sonleis = GameManager.getIns().getCards();
}, if (sonleis.length <= 14) {
onTouchItem(touch, info) { let x = -500;
if (!this._cantouch) return; let addX = 165;
this._cantouch = false; let y = -210;
let item = touch.target; let addY = -90;
let data = item.data; for (let i = 0; i < sonleis.length; i++) {
console.log(data); let sonClone = cc.instantiate(son);
this._cardTouchItems.push(item); sonClone.active = true;
if (this._cardTouchItems.length == 2) { let posX = x + addX * (i % 7);
let item0 = this._cardTouchItems[0]; let posY = y + addY * Math.floor(i / 7);
let item1 = this._cardTouchItems[1]; sonClone.x = posX;
//检测重复点击 取消选中 sonClone.y = posY;
if (item0.data && item1.data && item0.data.cardId == item1.data.cardId) { box.addChild(sonClone);
pg.view.visible(pg.view.find(item, 'box'), false);
this._cantouch = true;
} else if (item0.data && item1.data && item0.data.cardDid == item1.data.cardDid) {
//成功--变小 消失
this._successItems.push(item0);
this._successItems.push(item1);
pg.view.visible(pg.view.find(item, 'box'), true);
this.playSFX("audio_choice").then(() => {
this.playAudioAni(item).then(() => {
this.createRightAni(cc.v2(item0.x, item0.y));
this.createRightAni(cc.v2(item1.x, item1.y));
this.playSFX("audio_right").then(() => {
this._cantouch = true;
this.playAudioAni(item0).then(() => {
this.playAudioAni(item1).then(() => {
ani.scaleOut(item0);
ani.scaleOut(item1).then(() => {
setTimeout(() => {
this.groupEnd();//判定单组结束
}, 100);
});
pg.view.visible(pg.view.find(item0, 'box'), false);
pg.view.visible(pg.view.find(item1, 'box'), false);
});
});
});
})
});
} else {
//失败--抖动效果
pg.view.visible(pg.view.find(item, 'box'), true);
this.playSFX("audio_choice").then(() => {
this.playAudioAni(item).then(() => {
ani.shake(item0);
ani.shake(item1);
pg.view.visible(pg.view.find(item0, 'box'), false);
pg.view.visible(pg.view.find(item1, 'box'), false);
this.playSFX("audio_error").then(() => {
this._cantouch = true;
});
});
});
} }
this._cardTouchItems.length = 0;
} else if (this._cardTouchItems.length == 1) {
//显示选中效果
pg.view.visible(pg.view.find(item, 'box'), true);
this.playSFX("audio_choice").then(() => {
//audio 播放的时候动画播放, audio停的时候 动画正好能停下
//如果动画停的位置不对,直接强制设置对应的效果
//下一次播放没有问题即可
this.playAudioAni(item).then(() => {
this._cantouch = true;
})
});
} else { } else {
//异常情况 let scale = 0.7;
this._cardTouchItems.length = 0; let x = -500;
this._cantouch = true; let addX = 165 * scale;
let y = -200;
let addY = -90 * scale;
let arr = [3, 4, 5, 6, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30];
for (let i = 0; i < sonleis.length; i++) {
let sonClone = cc.instantiate(son);
sonClone.active = true;
let posX = x + addX * (arr[i] % 10);
let posY = y + addY * Math.floor(arr[i] / 10);
sonClone.x = posX;
sonClone.y = posY;
sonClone.scaleX = scale;
sonClone.scaleY = scale;
box.addChild(sonClone);
}
} }
}, },
// updateItem(item, data) {
// let img = pg.view.find(item, `img`);
// let txt = pg.view.find(item, `txt`);
// let audio = pg.view.find(item, `audio`);
// let box = pg.view.find(item, `box`);
// console.log(CardManager.TYPE_IMG);
// if (data.type == CardManager.TYPE_IMG) {
// pg.view.setNetImg(img, data.img);
// pg.view.visible(img, true);
// pg.view.visible(txt, false);
// pg.view.visible(audio, false);
// } else if (data.type == CardManager.TYPE_TXT) {
// pg.view.setString(txt, data.txt);
// pg.view.visible(img, false);
// pg.view.visible(txt, true);
// pg.view.visible(audio, false);
// } else if (data.type == CardManager.TYPE_MP3) {
// pg.view.visible(img, false);
// pg.view.visible(txt, false);
// pg.view.visible(audio, true);
// pg.view.visible(pg.view.find(item, `audio/btn_laba`), true);
// }
// item.scaleX = 1;
// item.scaleY = 1;
// pg.view.visible(box, false);
// item.attr({ data: data });
// pg.view.visible(item, true);
// pg.view.touchOn(item, this.onTouchItem, this);
// },
// onTouchItem(touch, info) {
// if (!this._cantouch) return;
// this._cantouch = false;
// let item = touch.target;
// let data = item.data;
// console.log(data);
// this._cardTouchItems.push(item);
// if (this._cardTouchItems.length == 2) {
// let item0 = this._cardTouchItems[0];
// let item1 = this._cardTouchItems[1];
// //检测重复点击 取消选中
// if (item0.data && item1.data && item0.data.cardId == item1.data.cardId) {
// pg.view.visible(pg.view.find(item, 'box'), false);
// this._cantouch = true;
// } else if (item0.data && item1.data && item0.data.cardDid == item1.data.cardDid) {
// //成功--变小 消失
// this._successItems.push(item0);
// this._successItems.push(item1);
// pg.view.visible(pg.view.find(item, 'box'), true);
// this.playSFX("audio_choice").then(() => {
// this.playAudioAni(item).then(() => {
// this.createRightAni(cc.v2(item0.x, item0.y));
// this.createRightAni(cc.v2(item1.x, item1.y));
// this.playSFX("audio_right").then(() => {
// this._cantouch = true;
// this.playAudioAni(item0).then(() => {
// this.playAudioAni(item1).then(() => {
// ani.scaleOut(item0);
// ani.scaleOut(item1).then(() => {
// setTimeout(() => {
// this.groupEnd();//判定单组结束
// }, 100);
// });
// pg.view.visible(pg.view.find(item0, 'box'), false);
// pg.view.visible(pg.view.find(item1, 'box'), false);
// });
// });
// });
// })
// });
// } else {
// //失败--抖动效果
// pg.view.visible(pg.view.find(item, 'box'), true);
// this.playSFX("audio_choice").then(() => {
// this.playAudioAni(item).then(() => {
// ani.shake(item0);
// ani.shake(item1);
// pg.view.visible(pg.view.find(item0, 'box'), false);
// pg.view.visible(pg.view.find(item1, 'box'), false);
// this.playSFX("audio_error").then(() => {
// this._cantouch = true;
// });
// });
// });
// }
// this._cardTouchItems.length = 0;
// } else if (this._cardTouchItems.length == 1) {
// //显示选中效果
// pg.view.visible(pg.view.find(item, 'box'), true);
// this.playSFX("audio_choice").then(() => {
// //audio 播放的时候动画播放, audio停的时候 动画正好能停下
// //如果动画停的位置不对,直接强制设置对应的效果
// //下一次播放没有问题即可
// this.playAudioAni(item).then(() => {
// this._cantouch = true;
// })
// });
// } else {
// //异常情况
// this._cardTouchItems.length = 0;
// this._cantouch = true;
// }
// },
playAudioAni(item) { playAudioAni(item) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
var anim = pg.view.find(item, `audio`).getComponent(cc.Animation); var anim = pg.view.find(item, `audio`).getComponent(cc.Animation);
......
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