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 {
}
}
class defClass {
constructor(id, name, dep) {
constructor(id, title, dep) {
this.id = id;
this.dep = dep;
this.name = name;
this.title = title;
this.child = [];
}
addChild(child) {
......@@ -52,6 +52,7 @@ class GameManager {
}
constructor() {
//主类 1
this._title = {};
this._allClass = [];
this._sonArray = [];//卡片数据解析
this._cardArray = [];//卡片数据解析
......@@ -60,44 +61,205 @@ class GameManager {
console.log(`init`);
this.parseData();
}
parseData() {
parseData(data) {
let obj = [{
id: 0, name: "zhulei", child: [
id: 0,
title: "biaoti",
child: [
{
id: 10,
name: "fenlei1",
child: [
id: 0, title: "zhulei", child: [
{
id: 101,
name: "sonlei1",
id: 10,
title: "fenlei1",
child: [
{
id: 1001,
name: "card1",
title: "卡片1001",
radioValue: "A"
id: 101,
title: "sonlei1",
child: [
{
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,
name: "card2",
title: "卡片1002",
radioValue: "A"
id: 101,
title: "sonlei2",
child: [
{
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,
name: "card3",
title: "卡片1003",
radioValue: "A"
id: 101,
title: "sonlei3",
child: [
{
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,
name: "card4",
title: "卡片1004",
radioValue: "A"
id: 201,
title: "sonlei5",
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: 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 {
let fenId = 1;
let sonId = 100;
let cardId = 1000;
for (let i = 0; i < obj.length; i++) {
let zhulei = obj[i];
let zhuleiClass = new defClass(zhulei.id, zhulei.name, 0);
this._title = obj[0];
for (let i = 0; i < obj[0].child.length; i++) {
let zhulei = obj[0].child[i];
let zhuleiClass = new defClass(zhulei.id, zhulei.title, 0);
for (let a = 0; a < zhulei.child.length; 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
for (let b = 0; b < fenlei.child.length; b++) {
sonId++;
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++) {
let card = sonlei.child[c];
cardId++;
......@@ -132,18 +295,21 @@ class GameManager {
}
console.log(this._allClass);
}
getTitle() {
return this._title.title;
}
getZhuClass() {
return this._allClass[0];
}
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) {
return this._sonArray.filter(son => son.id == id)[0];
}
getCards() {
//基础卡片列表
return this._cardArray;
return this._cardArray.concat();
}
compareCard(cardId, sonId) {
let sonClass = this.getSonClass(sonId);
......@@ -156,4 +322,6 @@ class GameManager {
//[] [] [] [] [] []sonclass
//() () () () () () () ()card
//() () () () () () () ()
//() () () () () () () ()
\ No newline at end of file
//() () () () () () () ()
export default GameManager;
\ No newline at end of file
......@@ -232,6 +232,9 @@ pg.view = {
skl.setAnimation(0, aniName, loop);
return skl;
},
cloneNode(node) {
return cc.instantiate(node);
}
}
//加载 未封装bundle
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";
import { defaultData } from "../script/defaultData";
import { itemData } from "./data";
import { hyLoader } from "./hyLoader";
import CardManager from "./cardManager";
import GameManager from "./gameManager";
import pg from "./pg";
import ani from "./ani";
import { asyncDelay, RandomInt, showFireworks } from "../script/utils";
......@@ -133,11 +133,13 @@ cc.Class({
//---------------------------------项目代码开始---------------------------------
loadEnd() {
// this.initData();
// this.initSingleData();
// this.initAudio();
// this.initView();
this.initButton();
this.initData();
this.initSingleData();
this.initAudio();
this.initView();
// this.initButton();
},
initButton() {
//触碰判断
......@@ -204,9 +206,9 @@ cc.Class({
_gameCode: null,
initData() {
//数据解析
CardManager.getIns().initCards(this.data);
CardManager.getIns().resetPageNum();
CardManager.getIns().randomPageCards();
GameManager.getIns().parseData(this.data);
// GameManager.getIns().resetPageNum();
// GameManager.getIns().randomPageCards();
this._gameCode = 0;
},
//单局游戏
......@@ -216,22 +218,25 @@ cc.Class({
_cardTouchItems: null,
_successItems: null,
initSingleData() {
this._title = GameManager.getIns().getTitle();
this._zhuClass = GameManager.getIns().getZhuClass();
// 所有全局变量 默认都是null
this._cantouch = true;
//界面用数据
this._cardTouchItems = [];
this._successItems = [];
this._cardPage = CardManager.getIns().getPage();
cc.log(this._cardPage);
// this._cardPage = CardManager.getIns().getPage();
// cc.log(this._cardPage);
},
initAudio() {
},
initView() {
this.btn_replay = pg.view.find(this, "btn_replay");
pg.view.visible(this.btn_replay, false);
pg.view.touchOn(this.btn_replay, this.onTouchReplay, this);
this.initStars();
// this.btn_replay = pg.view.find(this, "btn_replay");
// pg.view.visible(this.btn_replay, false);
// pg.view.touchOn(this.btn_replay, this.onTouchReplay, this);
// this.initStars();
this.initLayout();
},
initStars() {
......@@ -239,123 +244,202 @@ cc.Class({
this.addStar();
},
initLayout() {
pg.view.visible(this.btn_replay, false);
pg.view.visible(pg.view.find(this, `layout_card_4`), false);
pg.view.visible(pg.view.find(this, `layout_card_6`), false);
pg.view.visible(pg.view.find(this, `layout_card_8`), false);
pg.view.visible(pg.view.find(this, `layout_card_10`), false);
this._cardLayout = pg.view.find(this, `layout_card_${this._cardPage.length}`);
ani.scaleIn(this._cardLayout);
pg.view.visible(this._cardLayout, true);
for (let i = 0; i < this._cardPage.length; i++) {
let data = this._cardPage[i];
let item = pg.view.find(this._cardLayout, `item_${i}`);
if (!data || !item || data.type == CardManager.TYPE_NULL) continue;
this.updateItem(item, data);
//根据当前显示用数据来执行对应的效果
pg.view.setString(pg.view.find(this, "title/txt"), this._title);
//刷新主类
pg.view.setString(pg.view.find(this, "box/main/txt"), this._zhuClass.title);
//刷新分类
pg.view.setString(pg.view.find(this, "box/sub_0/txt"), this._zhuClass.child[0].title);
pg.view.setString(pg.view.find(this, "box/sub_1/txt"), this._zhuClass.child[1].title);
this.initSon();
this.initBox();
this.initItems();
},
initSon() {
//刷新子类
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) {
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);
initBox() {
//刷新子类
let son = pg.view.find(this, "box/box_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;//-290
let addX = 190;
let y = -62;
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);
}
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;
});
});
});
},
initItems() {
//刷新子类
let son = pg.view.find(this, "items/item");
let box = pg.view.find(this, "items");
let sonleis = GameManager.getIns().getCards();
if (sonleis.length <= 14) {
let x = -500;
let addX = 165;
let y = -210;
let addY = -90;
for (let i = 0; i < sonleis.length; i++) {
let sonClone = cc.instantiate(son);
sonClone.active = true;
let posX = x + addX * (i % 7);
let posY = y + addY * Math.floor(i / 7);
sonClone.x = posX;
sonClone.y = posY;
box.addChild(sonClone);
}
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;
let scale = 0.7;
let x = -500;
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) {
return new Promise((resolve, reject) => {
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