Commit 907b27de authored by 李维's avatar 李维

Dev commit

parent ce50afd9
...@@ -216,7 +216,7 @@ ...@@ -216,7 +216,7 @@
"array": [ "array": [
0, 0,
0, 0,
483.2421753117168, 538.9790290334059,
0, 0,
0, 0,
0, 0,
...@@ -734,7 +734,7 @@ ...@@ -734,7 +734,7 @@
"ctor": "Float64Array", "ctor": "Float64Array",
"array": [ "array": [
601.193, 601.193,
32.791, 36.791,
0, 0,
0, 0,
0, 0,
...@@ -1666,7 +1666,7 @@ ...@@ -1666,7 +1666,7 @@
} }
], ],
"_prefab": null, "_prefab": null,
"_opacity": 255, "_opacity": 0,
"_color": { "_color": {
"__type__": "cc.Color", "__type__": "cc.Color",
"r": 255, "r": 255,
......
...@@ -14,6 +14,7 @@ export default class GameLogic { ...@@ -14,6 +14,7 @@ export default class GameLogic {
m_questionAudioPlayed = false; m_questionAudioPlayed = false;
m_currentQuestion = -1; m_currentQuestion = -1;
m_questionDone = false; m_questionDone = false;
m_currentQuestionArray = []
constructor(formData, systemOption) { constructor(formData, systemOption) {
this.g_systemOption = systemOption; this.g_systemOption = systemOption;
this.g_canvas = cc.find('Canvas'); this.g_canvas = cc.find('Canvas');
...@@ -27,7 +28,7 @@ export default class GameLogic { ...@@ -27,7 +28,7 @@ export default class GameLogic {
this.g_formData = formData.contentObj; this.g_formData = formData.contentObj;
console.log("User saved data =>", this.g_formData) console.log("User saved data =>", this.g_formData)
} }
this.m_currentQuestion = 0;
this.g_cartoon.initLocalAudios([ this.g_cartoon.initLocalAudios([
"test_audio" "test_audio"
]) ])
...@@ -37,6 +38,7 @@ export default class GameLogic { ...@@ -37,6 +38,7 @@ export default class GameLogic {
this.resetPosition(); this.resetPosition();
this.initImageCards(); this.initImageCards();
this.initTitle(); this.initTitle();
this.loadQuestion();
// this.initQuestionPannel(); // this.initQuestionPannel();
// this.initButtons(); // this.initButtons();
// this.initMaskLayer(); // this.initMaskLayer();
...@@ -86,18 +88,22 @@ export default class GameLogic { ...@@ -86,18 +88,22 @@ export default class GameLogic {
const bgNodeTitle= cc.find('Canvas/title'); const bgNodeTitle= cc.find('Canvas/title');
const bgNodeSnow = cc.find('Canvas/bgMain/bg_snow'); const bgNodeSnow = cc.find('Canvas/bgMain/bg_snow');
const bgNodeShuicao = cc.find('Canvas/bgMain/shuicao'); const bgNodeShuicao = cc.find('Canvas/bgMain/shuicao');
bgNodeTitle.y = cc.winSize.height / 2 - bgNodeTitle.height / 2 - 100 bgNodeTitle.y = cc.winSize.height / 2 - bgNodeTitle.height / 2 - 50
bgNodeSnow.y = -cc.winSize.height / 2 + bgNodeSnow.height / 2 bgNodeSnow.y = -cc.winSize.height / 2 + bgNodeSnow.height / 2
bgNodeShuicao.y = -cc.winSize.height / 2 + bgNodeShuicao.height / 2 bgNodeShuicao.y = -cc.winSize.height / 2 + bgNodeShuicao.height / 2
} }
initImageCards() { initImageCards() {
let newIndex = this.getRandomArray(10)
this.m_currentQuestionArray = [1,2,3,4,5,6,7,8,9,10]
for (let index = 0; index < 10; index++) { for (let index = 0; index < 10; index++) {
let dataItem = this.g_formData.dataArray[index]; let dataItem = this.g_formData.dataArray[newIndex[index]];
let card = this.g_cartoon.getCartoonElement(`card_${index+1}`) let card = this.g_cartoon.getCartoonElement(`card_${index+1}`)
let cardNormal = this.g_cartoon.getCartoonElement(`card_${index+1}_normal`) let cardNormal = this.g_cartoon.getCartoonElement(`card_${index+1}_normal`)
let cardSelected = this.g_cartoon.getCartoonElement(`card_${index+1}_selected`) let cardSelected = this.g_cartoon.getCartoonElement(`card_${index+1}_selected`)
let imageContainer = this.g_cartoon.getCartoonElement(`card_${index+1}_image_container`) let imageContainer = this.g_cartoon.getCartoonElement(`card_${index+1}_image_container`)
imageContainer.cardIndex = index;
imageContainer.correctIndex = newIndex[index];
let bellOutline = this.g_cartoon.getCartoonElement(`card_${index+1}_bell_outline`) let bellOutline = this.g_cartoon.getCartoonElement(`card_${index+1}_bell_outline`)
let bellText = this.g_cartoon.getCartoonElement(`card_${index+1}_bell_text`) let bellText = this.g_cartoon.getCartoonElement(`card_${index+1}_bell_text`)
...@@ -123,7 +129,7 @@ export default class GameLogic { ...@@ -123,7 +129,7 @@ export default class GameLogic {
this.g_cartoon.subscribeTouchEvent(`card_${index+1}_image_container`, ()=>{ this.g_cartoon.subscribeTouchEvent(`card_${index+1}_image_container`, ()=>{
for(let i=0; i<10; i++) { for(let i=0; i<10; i++) {
if(i!=index) { if(i!=index && i != this.m_currentQuestion) {
this.g_cartoon.getCartoonElement(`card_${i+1}_normal`).node.opacity = 255; this.g_cartoon.getCartoonElement(`card_${i+1}_normal`).node.opacity = 255;
this.g_cartoon.getCartoonElement(`card_${i+1}_selected`).node.opacity = 0; this.g_cartoon.getCartoonElement(`card_${i+1}_selected`).node.opacity = 0;
} else { } else {
...@@ -131,6 +137,11 @@ export default class GameLogic { ...@@ -131,6 +137,11 @@ export default class GameLogic {
this.g_cartoon.getCartoonElement(`card_${i+1}_selected`).node.opacity = 255; this.g_cartoon.getCartoonElement(`card_${i+1}_selected`).node.opacity = 255;
} }
} }
console.log(this.m_currentQuestion, imageContainer.correctIndex)
if(this.m_currentQuestion == imageContainer.correctIndex ) {
this.switchCard(imageContainer.correctIndex, imageContainer.cardIndex)
this.loadQuestion()
}
}) })
card.tweenHandle = null; card.tweenHandle = null;
...@@ -161,6 +172,30 @@ export default class GameLogic { ...@@ -161,6 +172,30 @@ export default class GameLogic {
} }
} }
switchCard(fromIndex, toIndex) {
fromIndex = this.getCurrentIndex(fromIndex+1)
toIndex = this.getCurrentIndex(toIndex+1)
let card_1 = this.g_cartoon.getCartoonElement(`card_${fromIndex+1}`)
let card_2 = this.g_cartoon.getCartoonElement(`card_${toIndex+1}`)
let x = card_1.node.x
let y = card_1.node.y
card_1.node.x = card_2.node.x
card_1.node.y = card_2.node.y
card_2.node.x = x;
card_2.node.y = y;
console.log("A", fromIndex, toIndex)
let temp = this.m_currentQuestionArray[fromIndex]
this.m_currentQuestionArray[fromIndex] = this.m_currentQuestionArray[toIndex]
this.m_currentQuestionArray[toIndex] = temp;
console.log("B", this.m_currentQuestionArray)
}
getCurrentIndex(index) {
return this.m_currentQuestionArray.indexOf(index)
}
initCenterImage() { initCenterImage() {
let imageContainer = this.g_cartoon.getCartoonElement("center_image_container") let imageContainer = this.g_cartoon.getCartoonElement("center_image_container")
if(!this.g_formData.dataArray[this.m_currentQuestion].question.centerImage_url) { if(!this.g_formData.dataArray[this.m_currentQuestion].question.centerImage_url) {
...@@ -184,6 +219,87 @@ export default class GameLogic { ...@@ -184,6 +219,87 @@ export default class GameLogic {
this.g_cartoon.getCartoonElement("title_text").node.getComponent(cc.Label).fontSize = 32 this.g_cartoon.getCartoonElement("title_text").node.getComponent(cc.Label).fontSize = 32
} }
getRandomArray(length) {
Array.prototype.shuffle = function() {
let m = this.length, i;
while (m) {
i = (Math.random() * m--) >>> 0;
[this[m], this[i]] = [this[i], this[m]]
}
return this;
}
const gameLogicCheck = (array, startIndex) => {
let res = true;
for(let index=startIndex; index<array.length; index++) {
let changeIndex = array.indexOf(index)
if(array[index]==index) {
res = false
break;
}
}
return res;
}
let indexArray = []
for(let index=0; index<length; index++) {
indexArray.push(index)
}
var arr = indexArray.shuffle()
var result = false;
var temp = null;
var count = 0;
var arrayCanUse = []
do{
result = false;
arr = indexArray.shuffle()
arrayCanUse = JSON.parse(JSON.stringify(arr))
for(let index=0; index<arr.length; index++) {
if(index==arr[index]) {
result = true;
break
}
}
if(!result) {
for(let index=0; index<arr.length-2; index++) {
var indexChange = arr.indexOf(index)
temp = arr[index]
arr[index] = index;
arr[indexChange] = temp;
if(!gameLogicCheck(arr, index+1)) {
result = true;
break
}
}
}
if(count>20000) {
console.log("已经尝试超过两万次,终止生成", arr)
result = false
}
} while(result)
return arrayCanUse
}
loadQuestion() {
let index = this.m_currentQuestionArray[this.m_currentQuestion]
console.log("loadQuestion", index, this.m_currentQuestion)
if(this.m_currentQuestion != -1) {
index = this.m_currentQuestionArray[this.m_currentQuestion];
this.g_cartoon.getCartoonElement(`card_${index}_normal`).node.opacity = 255;
this.g_cartoon.getCartoonElement(`card_${index}_selected`).node.opacity = 0;
}
this.m_currentQuestion++;
index = this.m_currentQuestionArray[this.m_currentQuestion]
console.log("loadQuestion", index, this.m_currentQuestion)
this.g_cartoon.getCartoonElement(`card_${index}_normal`).node.opacity = 0;
this.g_cartoon.getCartoonElement(`card_${index}_selected`).node.opacity = 255;
}
initQuestionPannel() { initQuestionPannel() {
let title = this.g_cartoon.getCartoonElement("question_title_pannel") let title = this.g_cartoon.getCartoonElement("question_title_pannel")
let body = this.g_cartoon.getCartoonElement("question_body_pannel") let body = this.g_cartoon.getCartoonElement("question_body_pannel")
......
...@@ -87,7 +87,7 @@ cc.Class({ ...@@ -87,7 +87,7 @@ cc.Class({
}, },
getDefaultData() { getDefaultData() {
const dataJson = '{"contentObj":{"version":"1.0","key":"DataKey_Sbox_FT_08","bgMusic":"","titleText":"TEstd","questionAudio_url":"","dataArray":[{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/51795b0a7c66d61ad85a388c4299f614.jpg","audio_url":"http://staging-teach.cdn.ireadabc.com/3b5540cc95a006dff8c41dba7537075a.mp3"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/c9d60af536380445e48c637acb753d51.gif"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/d3cdc8921c6ae9b4f29b25fbb3a0f2f9.jpg"}]}}' const dataJson = '{"contentObj":{"version":"1.0","key":"DataKey_Sbox_FT_08","bgMusic":"","titleText":"TEstd","questionAudio_url":"","dataArray":[{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/06cc843598a912921f6ca3acfde6220b.png","audio_url":"http://staging-teach.cdn.ireadabc.com/3b5540cc95a006dff8c41dba7537075a.mp3"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/571974922f6678111348a5643dba7e20.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/78579114773af12a7aec6723e3b9d475.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/c99e82e1c3f087c6dc0469e30c624f70.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/5b45c89ac9e899d76522767219b1346b.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/2e28eae8f0e0f01193da6f3677379ed3.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/fad2dac4f8b59a185dc30d42617c2ca8.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/6c3fca11052464102407f173e4a83db9.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/ec82c796af801486548ae98623f614d2.png"},{"text":"","image_url":"http://staging-teach.cdn.ireadabc.com/ac4b9422df1556f80ac5c3058cd3d670.png"}]}}'
const data = JSON.parse(dataJson); const data = JSON.parse(dataJson);
return data; return data;
}, },
......
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