Skip to content

Commit 425f2f4

Browse files
committed
Add the stage 10 check
1 parent 982c6dd commit 425f2f4

5 files changed

Lines changed: 74 additions & 7 deletions

File tree

msg/stages/10/en.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ MSG.subTitle = "Stage 10 : Music Creation with a Buzzer";
33
MSG.demoDescription = "Create another piece of music and play it with the buzzer.";
44
MSG.notes = "Notes:";
55
MSG.tempos = "Tempos:";
6-
MSG.stageHelp = "Music Creation with a Buzzer.";
6+
MSG.stageHelp = "Music Creation with a Buzzer and show the notes and tempo in demo area.";
77
MSG.demoTitle = "Demo Area";

msg/stages/10/zh-hans.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ MSG.subTitle = "关卡 10:小小音乐家";
33
MSG.demoDescription = "尝试用其他的方式制作一首音乐,并用蜂鸣器播放";
44
MSG.notes = "音符:";
55
MSG.tempos = "节奏:";
6-
MSG.stageHelp = "使用积木及模拟器,利用蜂鸣器,播出超级马莉的音乐。";
6+
MSG.stageHelp = "使用积木及模拟器,利用蜂鸣器,播出超级马莉的音乐,并且在网页互动区显示播放的音符及节奏。";
77
MSG.demoTitle = "网页互动区";

msg/stages/10/zh-hant.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ MSG.subTitle = "關卡 10:小小音樂家";
33
MSG.demoDescription = "嘗試用其他的方式製作一首音樂,並用蜂鳴器播放";
44
MSG.notes = "音符:";
55
MSG.tempos = "節奏:";
6-
MSG.stageHelp = "使用積木及模擬器,利用蜂鳴器,播出超級馬莉的音樂。";
6+
MSG.stageHelp = "使用積木及模擬器,利用蜂鳴器,播出超級馬莉的音樂,並且在網頁互動區顯示播放的音符及節奏。";
77
MSG.demoTitle = "網頁互動區";

simulator

Submodule simulator updated from 8e3eda5 to 76dd580

stageCheck.js

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
'stages/06': stage6,
1616
'stages/07': stage7,
1717
'stages/08': stage8,
18-
'stages/09': stage9
18+
'stages/09': stage9,
19+
'stages/10': stage10
1920
};
2021

2122
demoDoc_ = demo.contentDocument;
@@ -460,7 +461,7 @@
460461
}
461462
}
462463

463-
function checkPoint1 () {
464+
function checkPoint1() {
464465
if (check[0]) return;
465466
if (buzzerData[curDistance].length < 2) return;
466467
if (Object.keys(rgbData[curDistance]).length < 2) return;
@@ -470,7 +471,7 @@
470471
});
471472
}
472473

473-
function checkPoint2 () {
474+
function checkPoint2() {
474475
if (check[1]) return;
475476
if (buzzerData[curDistance].length > 2) return;
476477
if (Object.keys(rgbData[curDistance]).length > 1) return;
@@ -670,6 +671,72 @@
670671

671672
}
672673

674+
/**
675+
* 點擊執行後,判斷蜂鳴器是否有執行播放超級瑪麗,及網頁互動區顯示音符及節奏,都符合,則過關
676+
* 做法:
677+
* 1. 是否播放超級瑪麗
678+
* 2. 網頁互動區是否有值
679+
*/
680+
function stage10() {
681+
var buzzers = engine_.list().buzzer;
682+
var buzzerNotes = demoDoc_.querySelector('#buzzerNotes');
683+
var buzzerTempos = demoDoc_.querySelector('#buzzerTempos');
684+
var buzzerData = [];
685+
var regMary = /2051,100,2204,100,2396,100,2618,100,3855,100,3855,100,3855,100,3347,100,3855,100,4954,100,2204,100,3347,100,2204,100,1925,100,2396,100,2618,100,2501,100,2396,100,2204,100,3855,100,4954,100,5332,100,4048,100,4954,100,3855,100,3347,100,3573,100,2618,100,3347,100,2204,100,1925,100,2396,100,2618,100,2501,100,2396,100,2204,100,3855,100,4954,100,5332,100,4048,100,4954,100,3855,100,3347,100,3573,100,2618,100/;
686+
var check = [false, false];
687+
var isPassed = false;
688+
689+
if (!buzzers.length) return;
690+
691+
buzzers.forEach(function (bz) {
692+
bz.setCmdHandler(cmd);
693+
});
694+
695+
// 儲存蜂鳴器送出命令的時間
696+
function cmd(cmd) {
697+
buzzerData.push(cmd);
698+
checkPoint1();
699+
checkPoint2();
700+
checking();
701+
}
702+
703+
function checkPoint1() {
704+
if (check[0]) return;
705+
if (!buzzerNotes.textContent) return;
706+
if (!buzzerTempos.textContent) return;
707+
check[0] = true;
708+
}
709+
710+
function checkPoint2() {
711+
if (check[1]) return;
712+
check[1] = regMary.test(buzzerData.toString());
713+
}
714+
715+
function checking() {
716+
if (isPassed) return;
717+
718+
isPassed = check.reduce(function (acc, val) {
719+
return acc && val;
720+
}, true);
721+
722+
if (isPassed) {
723+
checkOver();
724+
725+
// 考量畫面有些動畫未完成,所以延遲 1 秒執行
726+
setTimeout(function () {
727+
alert('第 10 關 過關!');
728+
}, 1000);
729+
}
730+
}
731+
732+
function checkOver() {
733+
buzzers.forEach(function (bz) {
734+
bz.setCmdHandler(null);
735+
});
736+
}
737+
738+
}
739+
673740
Code.stageCheck = {
674741
init: init
675742
};

0 commit comments

Comments
 (0)