Commit 953b0d58 authored by Tt's avatar Tt

基础换色完成

parent c31b11a3
...@@ -48,49 +48,39 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -48,49 +48,39 @@ export default class SceneComponent extends MyCocosSceneComponent {
initListener() { initListener() {
} }
private layout_blocks: cc.Node;
private layout_words: cc.Node;
initBlocks() {
this.layout_blocks = pg.view.find(this, 'layout_blocks');
this.layout_blocks.removeAllChildren()
let block = pg.view.find(this, 'block');
//动态创建,并给每一个打上编号
let space = { x: 9 + 80, y: 10 + 80 }
for (let y = 0; y < 9; y++) {
for (let x = 0; x < 12; x++) {
let node = cc.instantiate(block);
let data = { x, y };
node.data = data;
node.x = -495 + space.x * x;
node.y = 365 - space.y * y;
node.active = !!GameNGT14.getIns().getBlockVal(x, y);
this.layout_blocks.addChild(node);
}
}
}
gameStart() { gameStart() {
this.updateQuestion(); this.updateQuestion();
this.updateHightLight();
this.updateWords(); this.updateWords();
} }
//----------------------------------------右上题目部分-----------------------------------
private layout_question: cc.Node; private layout_question: cc.Node;
updateQuestion() { updateQuestion() {
let data = GameNGT14.getIns().getCurrent(); let data = GameNGT14.getIns().getCurrent();
this.layout_question = pg.view.find(this, 'layout_question'); this.layout_question = pg.view.find(this, 'layout_question');
let img_big = pg.view.find(this.layout_question, 'base/img_big');
let img_small = pg.view.find(this.layout_question, 'base/img_small');
let label_big = pg.view.find(this.layout_question, 'base/label_big');
let label_small = pg.view.find(this.layout_question, 'base/label_small');
// 需要处理数据 // 需要处理数据
this.updateItem(this.layout_question,data); this.updateItem(this.layout_question, data);
} }
getLayByOption(option: Option, base) { getLayByOption(option: Option, base, { onlyImg, showCenter }) {
if (onlyImg) {
return cc.instantiate(pg.view.find(base, 'layout_full'))
} else if (showCenter) {
return cc.instantiate(pg.view.find(base, 'layout_center'))
} else {
return option.isDoubleLine() ? cc.instantiate(pg.view.find(base, 'layout_double')) : cc.instantiate(pg.view.find(base, 'layout_single')); return option.isDoubleLine() ? cc.instantiate(pg.view.find(base, 'layout_double')) : cc.instantiate(pg.view.find(base, 'layout_single'));
} }
getNodeByBlock(block: Block, base) { }
getNodeByBlock(block: Block, base, { onlyImg }) {
switch (block.type) { switch (block.type) {
case BLOCK_TYPE.IMG: case BLOCK_TYPE.IMG:
if (onlyImg) {
return cc.instantiate(pg.view.find(base, 'img_big'))
} else {
return cc.instantiate(pg.view.find(base, 'img')) return cc.instantiate(pg.view.find(base, 'img'))
}
case BLOCK_TYPE.TXT: case BLOCK_TYPE.TXT:
return cc.instantiate(pg.view.find(base, 'label')) return cc.instantiate(pg.view.find(base, 'label'))
case BLOCK_TYPE.LINE: case BLOCK_TYPE.LINE:
...@@ -103,19 +93,22 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -103,19 +93,22 @@ export default class SceneComponent extends MyCocosSceneComponent {
pg.view.visible(item, true); pg.view.visible(item, true);
item.data = data; item.data = data;
let board = pg.view.find(item, 'board'); // let board = pg.view.find(item, 'board');
let base = pg.view.find(item, 'base'); let base = pg.view.find(item, 'base');
// 确定基础layout // 确定基础layout
let layout = pg.view.find(item, 'layout'); let layout = pg.view.find(item, 'layout');
let list: Array<Option> = data.getList(); let list: Array<Option> = data.getList();
list.forEach(option => { list.forEach(option => {
let blocks = option.getList();
let showCenter = blocks.length == 1 && blocks[0].type == BLOCK_TYPE.IMG;
let onlyImg = list.length == 1 && showCenter;
//确定使用的单双行 //确定使用的单双行
let lay = this.getLayByOption(option, base); let lay = this.getLayByOption(option, base, { onlyImg, showCenter });
pg.view.addChild(layout, lay); pg.view.addChild(layout, lay);
let blocks = option.getList();
blocks.forEach(block => { blocks.forEach(block => {
//确定使用哪种节点 //确定使用哪种节点
let node = this.getNodeByBlock(block, base); let node = this.getNodeByBlock(block, base, { onlyImg });
node.y = 0;
pg.view.addChild(lay, node); pg.view.addChild(lay, node);
this.updateNode(node, block) this.updateNode(node, block)
}) })
...@@ -124,9 +117,6 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -124,9 +117,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
let height = layout.height; let height = layout.height;
item.height = height + 15; item.height = height + 15;
}, 0); }, 0);
// pg.view.touchOn(item, this.onTouchItem, this)
// let btn_ok = pg.view.find(item, 'btn_ok');
// pg.view.touchOn(btn_ok, this.onTouchOk, this)
} }
updateNode(item, block: Block) { updateNode(item, block: Block) {
item.data = block; item.data = block;
...@@ -146,11 +136,11 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -146,11 +136,11 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
} }
updateImg(item, block: Block) { updateImg(item, block: Block) {
pg.view.setNetImg(item, block.img, { w: 253, h: 174 }) pg.view.setNetImg(item, block.img, { w: item.width, h: item.height })
} }
updateLine(item, block: Block) { updateLine(item, block: Block) {
item.width = block.line * 30; item.width = block.line * 30;
pg.view.visible(pg.view.find(item, 'label/input_cursor'), false) // pg.view.visible(pg.view.find(item, 'label/input_cursor'), false)
// pg.view.touchOn(item, this.onTouchLine, this); // pg.view.touchOn(item, this.onTouchLine, this);
} }
updateLabel(item, block: Block) { updateLabel(item, block: Block) {
...@@ -162,7 +152,52 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -162,7 +152,52 @@ export default class SceneComponent extends MyCocosSceneComponent {
pg.view.setString(pg.view.find(tag_default, 'label'), block.tag) pg.view.setString(pg.view.find(tag_default, 'label'), block.tag)
pg.view.setString(pg.view.find(tag_input, 'label'), block.tag) pg.view.setString(pg.view.find(tag_input, 'label'), block.tag)
} }
//----------------------------------------左侧方块部分-----------------------------------
private layout_blocks: cc.Node;
initBlocks() {
this.layout_blocks = pg.view.find(this, 'layout_blocks');
this.layout_blocks.removeAllChildren()
let block = pg.view.find(this, 'block');
//动态创建,并给每一个打上编号
let space = { x: 9 + 80, y: 10 + 80 }
for (let y = 0; y < 9; y++) {
for (let x = 0; x < 12; x++) {
let node = cc.instantiate(block);
let data = { x, y, val: '' };
node.data = data;
node.x = -495 + space.x * x;
node.y = 365 - space.y * y;
node.active = !!GameNGT14.getIns().getBlockVal(x, y);
this.layout_blocks.addChild(node);
}
}
}
// 更新面板高亮
updateHightLight() {
let list = GameNGT14.getIns().getHightList();
let first = null;
this.layout_blocks.children.forEach(node => {
let point = node.data;
if (list.some(li => li.compare(point))) {
pg.view.visible(pg.view.find(node, 'img_undone'), false)
pg.view.visible(pg.view.find(node, 'img_focus'), true)
if (!point.val && !first) {
first = true;
pg.view.visible(pg.view.find(node, 'img_focus2'), true)
}
} else {
pg.view.visible(pg.view.find(node, 'img_undone'), true)
pg.view.visible(pg.view.find(node, 'img_focus'), false)
pg.view.visible(pg.view.find(node, 'img_focus2'), false)
}
})
}
getBlockNodeByPos(x, y) {
return this.layout_blocks.children.find(node => node.data.x == x && node.data.y == y)
}
//----------------------------------------右下角单词部分-----------------------------------
private layout_words: cc.Node;
updateWords() { updateWords() {
let word = pg.view.find(this, 'word'); let word = pg.view.find(this, 'word');
this.layout_words = pg.view.find(this, 'layout_words'); this.layout_words = pg.view.find(this, 'layout_words');
...@@ -188,8 +223,11 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -188,8 +223,11 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
updateWord(node, data) { updateWord(node, data) {
node.data = data; node.data = data;
pg.view.setString(pg.view.find(node, 'label'), data); node.rotation = data.rotation
pg.view.setString(pg.view.find(node, 'label'), data.word);
for (let i = 1; i <= 5; i++) {
pg.view.visible(pg.view.find(node, 'img_keyboard_' + i), data.color == i);
}
node.on(cc.Node.EventType.TOUCH_START, this.onItemTouchStart, this); node.on(cc.Node.EventType.TOUCH_START, this.onItemTouchStart, this);
node.on(cc.Node.EventType.TOUCH_MOVE, this.onItemTouchMove, this); node.on(cc.Node.EventType.TOUCH_MOVE, this.onItemTouchMove, this);
node.on(cc.Node.EventType.TOUCH_END, this.onItemTouchEnd, this); node.on(cc.Node.EventType.TOUCH_END, this.onItemTouchEnd, this);
...@@ -298,6 +336,19 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -298,6 +336,19 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
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) => {
......
...@@ -80,13 +80,13 @@ export class Option { ...@@ -80,13 +80,13 @@ export class Option {
} }
export class Question { export class Question {
public static id: number = 1000; public static id: number = 1000;
public id: number; public id: string;
public list: Array<Option>; public list: Array<Option>;
public submit: BOARD_STATE; public submit: BOARD_STATE;
public words; public words;
public answer; public answer;
constructor(data) { constructor(data) {
this.id = Question.id++; this.id = data.id;
console.log(data); console.log(data);
this.list = data.options.map(option => new Option(option)); this.list = data.options.map(option => new Option(option));
this.submit = BOARD_STATE.DEFAULT this.submit = BOARD_STATE.DEFAULT
...@@ -96,14 +96,22 @@ export class Question { ...@@ -96,14 +96,22 @@ export class Question {
let str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" let str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
this.words.push(str[Math.floor(Math.random() * str.length)]) this.words.push(str[Math.floor(Math.random() * str.length)])
} }
for (let i = 0; i < 10; i++) {
this.words.sort((A, B) => {
return Math.random() < 0.5
})
}
} }
getWords() { getWords() {
return this.words.concat(); let rand = Math.floor(Math.random() * 100);
let words = this.words.map((w, index) => {
return {
word: w,
color: (index + rand) % 5 + 1,
rotation: Math.random() < 0.5 ? 3 : -3
}
});
for (let i = 0; i < 10; i++) {
words.sort((A, B) => {
return Math.random() - 0.5
});
}
return words;
} }
setSubmit(state) { setSubmit(state) {
this.submit = state this.submit = state
...@@ -124,6 +132,7 @@ export class Question { ...@@ -124,6 +132,7 @@ export class Question {
export class GameNGT14 { export class GameNGT14 {
public questions: Array<Question> public questions: Array<Question>
public blocks: Array<{ val: string }> public blocks: Array<{ val: string }>
public blockStruct: Array<{ pId: string, answer: string, point: { x: number, y: number } }>
public current: number; public current: number;
public title: string; public title: string;
public total: number; public total: number;
...@@ -140,6 +149,7 @@ export class GameNGT14 { ...@@ -140,6 +149,7 @@ export class GameNGT14 {
initData(data) { initData(data) {
console.log(data); console.log(data);
this.questions = data.questions[0].parts.map(part => new Question(part)); this.questions = data.questions[0].parts.map(part => new Question(part));
this.blockStruct = data.blockStruct;
this.blocks = data.blocks; this.blocks = data.blocks;
this.title = data.title; this.title = data.title;
this.startAudio = data.startAudio || ""; this.startAudio = data.startAudio || "";
...@@ -149,7 +159,21 @@ export class GameNGT14 { ...@@ -149,7 +159,21 @@ export class GameNGT14 {
if (!this.blocks[y] || !this.blocks[y][x]) return; if (!this.blocks[y] || !this.blocks[y][x]) return;
return this.blocks[y][x].val; return this.blocks[y][x].val;
} }
getHightList() {
let data = this.getCurrent();
let line = this.blockStruct.find(block => block.pId == data.id);
let list = [];
for (let i = 0; i < line.answer.length; i++) {
list.push({
x: line.point.x + i,
y: line.point.y,
compare: function (p) {
return this.x == p.x && this.y == p.y;
}
})
}
return list
}
getCurrent(): Question { getCurrent(): Question {
return this.questions[this.current]; return this.questions[this.current];
} }
......
...@@ -3,7 +3,7 @@ export const defaultData = { ...@@ -3,7 +3,7 @@ export const defaultData = {
{ {
"parts": [{ "parts": [{
"id": "166668702213640281", "id": "166668702213640281",
"answer": "freedow", "answer": "freedom",
"options": [ "options": [
{ {
"blocks": [ "blocks": [
...@@ -21,7 +21,7 @@ export const defaultData = { ...@@ -21,7 +21,7 @@ export const defaultData = {
}, { }, {
"blocks": [ "blocks": [
{ {
"type": "txt", "txt": "", "line": "", "img": "", "tag": "", "text": "On saturdays freedow" "type": "txt", "txt": "", "line": "", "img": "", "tag": "", "text": "On saturdays freedom"
} }
] ]
}] }]
...@@ -72,7 +72,7 @@ export const defaultData = { ...@@ -72,7 +72,7 @@ export const defaultData = {
{ {
"pId": "166668702213640281", "pId": "166668702213640281",
"point": { "x": 3, "y": 6 }, "point": { "x": 3, "y": 6 },
"answer": "freedow" "answer": "freedom"
}, },
{ {
"pId": "1666687612725869271", "pId": "1666687612725869271",
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
"premultiplyAlpha": false, "premultiplyAlpha": false,
"genMipmaps": false, "genMipmaps": false,
"packable": true, "packable": true,
"width": 79, "width": 82,
"height": 79, "height": 83,
"platformSettings": {}, "platformSettings": {},
"subMetas": { "subMetas": {
"img_undone": { "img_undone": {
...@@ -22,10 +22,10 @@ ...@@ -22,10 +22,10 @@
"offsetY": 0, "offsetY": 0,
"trimX": 0, "trimX": 0,
"trimY": 0, "trimY": 0,
"width": 79, "width": 82,
"height": 79, "height": 83,
"rawWidth": 79, "rawWidth": 82,
"rawHeight": 79, "rawHeight": 83,
"borderTop": 0, "borderTop": 0,
"borderBottom": 0, "borderBottom": 0,
"borderLeft": 0, "borderLeft": 0,
......
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