2016-08-26 16:53:56 +02:00
|
|
|
|
|
|
|
|
|
|
2021-12-12 09:37:03 +01:00
|
|
|
|
function MapCharacterTable(characterUse) {
|
2016-08-26 16:53:56 +02:00
|
|
|
|
var characterArray = characterUse.textContent.split('\n');
|
2021-12-12 09:37:03 +01:00
|
|
|
|
var table = this.table = {};
|
|
|
|
|
for (var i=0, l=characterArray.length; i<l; i++) {
|
|
|
|
|
if (characterArray[i]) {
|
|
|
|
|
table[characterArray[i].substr(1)] = characterArray[i].charAt(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-08-29 06:05:41 +02:00
|
|
|
|
}
|
2016-08-26 16:53:56 +02:00
|
|
|
|
|
2021-12-12 09:37:03 +01:00
|
|
|
|
MapCharacterTable.prototype = {
|
|
|
|
|
constructor: MapCharacterTable,
|
|
|
|
|
findAlphabet: function (character) {
|
|
|
|
|
var table = this.table
|
|
|
|
|
for (var i in table) if (table[i] === character) return i;
|
|
|
|
|
return undefined;
|
2016-08-29 06:05:41 +02:00
|
|
|
|
},
|
2021-12-12 09:37:03 +01:00
|
|
|
|
getCharacterAndAlphabet: function (oldAlphabet) {
|
|
|
|
|
var table = this.table;
|
|
|
|
|
table[oldAlphabet] = undefined;
|
|
|
|
|
for (var i in table) {
|
|
|
|
|
if (typeof(table[i]) == 'string' && table[i].length == 1) {
|
|
|
|
|
return [table[i], i];
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-08-29 06:05:41 +02:00
|
|
|
|
return false;
|
|
|
|
|
},
|
2021-12-12 09:37:03 +01:00
|
|
|
|
findCharacter: function (alphabet) {
|
|
|
|
|
return this.table[alphabet]
|
2016-08-29 06:05:41 +02:00
|
|
|
|
},
|
|
|
|
|
};
|
2016-08-26 16:53:56 +02:00
|
|
|
|
|
|
|
|
|
var alphabetTable = { a:'日', b:'月', c:'金', d:'木', e:'水', f:'火', g:'土', h:'竹', i:'戈', j:'十', k:'大', l:'中', m:'一', n:'弓', o:'人', p:'心', q:'手', r:'口', s:'尸', t:'廿', u:'山', v:'女', w:'田', x:'難', y:'卜', z:'重' };
|
|
|
|
|
|
2016-08-29 06:05:41 +02:00
|
|
|
|
var tabler = {
|
2021-12-12 09:37:03 +01:00
|
|
|
|
getCurrentId: function () {
|
|
|
|
|
var hash = window.location.hash.substr(1);
|
|
|
|
|
var id = Number(hash);
|
|
|
|
|
if (0 <= id && id < 32) return id;
|
|
|
|
|
else return 0;
|
2016-08-29 06:05:41 +02:00
|
|
|
|
},
|
2021-12-12 09:37:03 +01:00
|
|
|
|
setTable: function () {
|
2016-08-29 06:05:41 +02:00
|
|
|
|
document.getElementById('characterUse').textContent =
|
2021-12-12 09:37:03 +01:00
|
|
|
|
document.getElementById(this.getCurrentId())
|
|
|
|
|
.textContent.replace(/[a-z]*\n/g,' ');
|
2016-08-29 06:05:41 +02:00
|
|
|
|
},
|
|
|
|
|
};
|
2016-08-26 16:53:56 +02:00
|
|
|
|
|
|
|
|
|
var characterTable;
|
|
|
|
|
|
2021-12-12 09:37:03 +01:00
|
|
|
|
var respondWindow = {
|
|
|
|
|
node: document.getElementById('respond'),
|
|
|
|
|
say: function (sentence, type) {
|
|
|
|
|
if ( /^[ \t\n]*$/.test(sentence) ) return false;
|
2016-08-28 18:42:50 +02:00
|
|
|
|
|
2021-12-12 09:37:03 +01:00
|
|
|
|
var paragraph = document.createElement('p');
|
|
|
|
|
paragraph.textContent = sentence ;
|
|
|
|
|
paragraph.className = type || '';
|
2016-08-28 18:42:50 +02:00
|
|
|
|
|
2021-12-12 09:37:03 +01:00
|
|
|
|
this.node.appendChild(paragraph);
|
|
|
|
|
this.node.scrollTop += 150;
|
2016-08-27 06:35:52 +02:00
|
|
|
|
|
2016-08-28 18:42:50 +02:00
|
|
|
|
return true;
|
2021-12-12 09:37:03 +01:00
|
|
|
|
},
|
|
|
|
|
show: function (node) {
|
|
|
|
|
if (node && this.node.appendChild(node)) {
|
|
|
|
|
this.node.scrollTop += 150;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2016-08-28 18:42:50 +02:00
|
|
|
|
|
2021-12-12 09:37:03 +01:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2016-08-27 11:42:12 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2021-12-12 09:37:03 +01:00
|
|
|
|
var visualBar = {node: document.getElementById('visual')};
|
2016-08-26 16:53:56 +02:00
|
|
|
|
var inputBar = document.getElementById('input');
|
2021-12-12 09:37:03 +01:00
|
|
|
|
var questCharacter = {node: document.getElementById('quest')};
|
|
|
|
|
var hintBar = {node: document.getElementById('hint')};
|
2016-08-26 16:53:56 +02:00
|
|
|
|
|
2021-12-12 09:37:03 +01:00
|
|
|
|
hintBar.newHintState = function() {
|
|
|
|
|
var answerAlphabetLength = questCharacter.node.title.length;
|
2016-08-29 06:05:41 +02:00
|
|
|
|
var hintState = [];
|
2021-12-12 09:37:03 +01:00
|
|
|
|
for (var i=0, l=answerAlphabetLength; i<l; i++) hintState.push('*');
|
|
|
|
|
this.node.textContent = hintState.join(' ');
|
2016-08-26 16:53:56 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
hintBar.hintCharacter = function(){
|
|
|
|
|
|
2021-12-12 09:37:03 +01:00
|
|
|
|
var answerAlphabet = questCharacter.node.title;
|
|
|
|
|
var hintState = this.node.textContent.split(' ');
|
2016-08-26 16:53:56 +02:00
|
|
|
|
|
2021-12-12 09:37:03 +01:00
|
|
|
|
if (hintState.indexOf('*') == -1) return true;
|
2016-08-26 16:53:56 +02:00
|
|
|
|
|
2021-12-12 09:37:03 +01:00
|
|
|
|
var hideState = [];
|
|
|
|
|
for (var i=0; i<hintState.length; i++) {
|
|
|
|
|
if (hintState[i] == '*') hideState.push(i);
|
|
|
|
|
}
|
|
|
|
|
var newIndex = hideState[Math.floor(Math.random() * hideState.length)];
|
2016-08-29 06:05:41 +02:00
|
|
|
|
|
|
|
|
|
hintState[newIndex] = alphabetTable[answerAlphabet.charAt(newIndex)];
|
2016-08-26 16:53:56 +02:00
|
|
|
|
|
2021-12-12 09:37:03 +01:00
|
|
|
|
this.node.textContent = hintState.join(' ');
|
|
|
|
|
return false
|
2016-08-26 16:53:56 +02:00
|
|
|
|
};
|
|
|
|
|
|
2021-12-12 09:37:03 +01:00
|
|
|
|
questCharacter.nextCharacter = function () {
|
2016-08-26 16:53:56 +02:00
|
|
|
|
var characterAndAlphabet =
|
2021-12-12 09:37:03 +01:00
|
|
|
|
characterTable.getCharacterAndAlphabet(this.node.title);
|
2016-08-26 16:53:56 +02:00
|
|
|
|
|
2021-12-12 09:37:03 +01:00
|
|
|
|
if (characterAndAlphabet) {
|
|
|
|
|
this.node.textContent = characterAndAlphabet[0];
|
|
|
|
|
this.node.title = characterAndAlphabet[1];
|
2016-08-29 06:05:41 +02:00
|
|
|
|
hintBar.newHintState();
|
2021-12-12 09:37:03 +01:00
|
|
|
|
}
|
|
|
|
|
else respondRobot.endStage();
|
2016-08-26 16:53:56 +02:00
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2021-12-12 09:37:03 +01:00
|
|
|
|
visualBar.generateCharacter = function (allAlphabet) {
|
2016-08-26 16:53:56 +02:00
|
|
|
|
var allAlphabetArray = allAlphabet.split('');
|
2021-12-12 09:37:03 +01:00
|
|
|
|
var visualString = '';
|
2016-08-26 16:53:56 +02:00
|
|
|
|
|
2021-12-12 09:37:03 +01:00
|
|
|
|
for (var i=0, l=allAlphabetArray.length; i<l; i++) {
|
|
|
|
|
visualString += (
|
|
|
|
|
alphabetTable[ allAlphabetArray[i] ] ||
|
2016-08-28 05:46:21 +02:00
|
|
|
|
allAlphabetArray[i]
|
2021-12-12 09:37:03 +01:00
|
|
|
|
) + ' ';
|
|
|
|
|
}
|
2016-08-26 16:53:56 +02:00
|
|
|
|
|
2021-12-12 09:37:03 +01:00
|
|
|
|
this.node.textContent = visualString + '_' ;
|
2016-08-26 16:53:56 +02:00
|
|
|
|
};
|
|
|
|
|
|
2021-12-12 09:37:03 +01:00
|
|
|
|
visualBar.verifyCharacter = function () {
|
|
|
|
|
switch (this.node.textContent) {
|
|
|
|
|
case '_':
|
2016-08-27 11:42:12 +02:00
|
|
|
|
respondRobot.inputRespond(2);
|
2016-08-27 03:11:11 +02:00
|
|
|
|
return false;
|
2016-08-26 16:53:56 +02:00
|
|
|
|
break;
|
2021-12-12 09:37:03 +01:00
|
|
|
|
case questCharacter.node.textContent:
|
2016-08-27 11:42:12 +02:00
|
|
|
|
respondRobot.inputRespond(0);
|
2016-08-27 03:11:11 +02:00
|
|
|
|
return true;
|
2016-08-26 16:53:56 +02:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2016-08-27 11:42:12 +02:00
|
|
|
|
respondRobot.inputRespond(1);
|
2016-08-27 03:11:11 +02:00
|
|
|
|
return false;
|
2016-08-27 15:13:22 +02:00
|
|
|
|
break;
|
2016-08-26 16:53:56 +02:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2016-08-27 11:42:12 +02:00
|
|
|
|
var respondRobot = {
|
2021-12-12 09:37:03 +01:00
|
|
|
|
current: 0,
|
2016-08-29 03:19:51 +02:00
|
|
|
|
inputTimes: 0,
|
2016-08-27 11:42:12 +02:00
|
|
|
|
cumulateTimes: 0,
|
2021-12-12 09:37:03 +01:00
|
|
|
|
doCumulate: function () {
|
2016-08-27 15:13:22 +02:00
|
|
|
|
var current = this.current, cumulateTimes = this.cumulateTimes;
|
2021-12-12 09:37:03 +01:00
|
|
|
|
if (current == 0) {
|
|
|
|
|
if (cumulateTimes >= 0) this.cumulateTimes++;
|
2016-08-27 14:11:01 +02:00
|
|
|
|
else {
|
2021-12-12 09:37:03 +01:00
|
|
|
|
if (cumulateTimes <= -3) respondWindow.say("耶!對了!",'good');
|
2016-08-27 15:13:22 +02:00
|
|
|
|
else respondWindow.say("對。",'good');
|
2016-08-27 14:11:01 +02:00
|
|
|
|
this.cumulateTimes = 0;
|
|
|
|
|
}
|
2021-12-12 09:37:03 +01:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (cumulateTimes <= 0) this.cumulateTimes--;
|
2016-08-27 14:11:01 +02:00
|
|
|
|
else {
|
2021-12-12 09:37:03 +01:00
|
|
|
|
if (cumulateTimes >= 5) respondWindow.say("啊,錯了?",'bad');
|
2016-08-27 15:13:22 +02:00
|
|
|
|
else respondWindow.say("錯了。",'bad');
|
2016-08-27 14:11:01 +02:00
|
|
|
|
this.cumulateTimes = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-08-27 11:42:12 +02:00
|
|
|
|
},
|
2021-12-12 09:37:03 +01:00
|
|
|
|
chatBack: function () {
|
2016-08-29 06:56:03 +02:00
|
|
|
|
function chatBackLater(){
|
|
|
|
|
var respond = document.getElementById('chatBack').children[0]
|
|
|
|
|
respond.className = 'gm';
|
|
|
|
|
respondWindow.show(respond);
|
|
|
|
|
}
|
|
|
|
|
setTimeout(chatBackLater, 1000 + 2000*Math.random());
|
|
|
|
|
},
|
2021-12-12 09:37:03 +01:00
|
|
|
|
cumulateRespond: function () {
|
2016-08-27 15:13:22 +02:00
|
|
|
|
var sentence, point, cumulateTimes = this.cumulateTimes;
|
|
|
|
|
if(cumulateTimes > 0) {
|
|
|
|
|
sentence = '對!';
|
2016-08-27 14:11:01 +02:00
|
|
|
|
point = 'good';
|
2016-08-27 15:13:22 +02:00
|
|
|
|
} else if(cumulateTimes < 0){
|
2016-08-27 14:11:01 +02:00
|
|
|
|
sentence = '錯。';
|
|
|
|
|
point = 'bad';
|
2016-08-27 11:42:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-27 15:13:22 +02:00
|
|
|
|
switch(cumulateTimes){
|
2021-12-12 09:37:03 +01:00
|
|
|
|
case 3: sentence = '不錯喔!';
|
2016-08-27 14:11:01 +02:00
|
|
|
|
break;
|
2021-12-12 09:37:03 +01:00
|
|
|
|
case 5: sentence = '欸唷,這個屌!';
|
2016-08-27 14:11:01 +02:00
|
|
|
|
break;
|
2021-12-12 09:37:03 +01:00
|
|
|
|
case -2: sentence = '又錯了。';
|
2016-08-27 14:11:01 +02:00
|
|
|
|
break;
|
2021-12-12 09:37:03 +01:00
|
|
|
|
case -3: sentence = '還是錯……';
|
2016-08-27 11:42:12 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
2021-12-12 09:37:03 +01:00
|
|
|
|
if (Math.random() < 0.07) sentence = '幫我撐十秒!';
|
2016-08-27 11:42:12 +02:00
|
|
|
|
|
2016-08-27 17:57:02 +02:00
|
|
|
|
sentence && respondWindow.say(sentence,point);
|
2016-08-27 11:42:12 +02:00
|
|
|
|
},
|
2021-12-12 09:37:03 +01:00
|
|
|
|
hintRespond: function () {
|
|
|
|
|
if (this.inputTimes%7 == 6 && this.current == 0) {
|
2016-08-29 03:19:51 +02:00
|
|
|
|
function sayHint(){
|
2021-12-12 09:37:03 +01:00
|
|
|
|
var paragraph = document.getElementById('respondMaterial').children[0] ||
|
|
|
|
|
false;
|
2016-08-29 06:56:03 +02:00
|
|
|
|
paragraph.className = 'gm';
|
2016-08-29 03:19:51 +02:00
|
|
|
|
respondWindow.show(paragraph);
|
|
|
|
|
}
|
|
|
|
|
window.setTimeout(sayHint, 3 + Math.random()*3);
|
2016-08-27 17:57:02 +02:00
|
|
|
|
}
|
|
|
|
|
},
|
2021-12-12 09:37:03 +01:00
|
|
|
|
endStage: function () {
|
2016-08-29 06:05:41 +02:00
|
|
|
|
var currentStage = tabler.getCurrentId(), paragraph = [];
|
2021-12-12 09:37:03 +01:00
|
|
|
|
for (var i=0; i<3; i++) {
|
2016-08-28 05:46:21 +02:00
|
|
|
|
paragraph[i] = document.getElementById(
|
|
|
|
|
'nextStage'
|
|
|
|
|
).children[i].cloneNode(true);
|
|
|
|
|
|
|
|
|
|
paragraph[i].className = 'system';
|
|
|
|
|
}
|
2016-08-27 17:57:02 +02:00
|
|
|
|
|
2016-08-28 05:46:21 +02:00
|
|
|
|
var paragraphText = paragraph[1].textContent;
|
2016-08-29 06:05:41 +02:00
|
|
|
|
paragraphText = paragraphText.replace('tableId',currentStage);
|
2016-08-28 05:46:21 +02:00
|
|
|
|
paragraphText = paragraphText.replace('leftTable',31-currentStage);
|
|
|
|
|
paragraph[1].textContent = paragraphText;
|
2016-08-27 17:57:02 +02:00
|
|
|
|
|
2016-08-28 05:46:21 +02:00
|
|
|
|
var anchor = paragraph[2].children[0];
|
2016-08-27 17:57:02 +02:00
|
|
|
|
anchor.href = '#' + (currentStage + 1) ;
|
|
|
|
|
|
2016-08-28 05:46:21 +02:00
|
|
|
|
var anchorText = anchor.textContent;
|
|
|
|
|
anchorText = anchorText.replace('nextTableId',currentStage+1);
|
|
|
|
|
anchor.textContent = anchorText;
|
2016-08-27 17:57:02 +02:00
|
|
|
|
|
2021-12-12 09:37:03 +01:00
|
|
|
|
for (i=0; i<3; i++) respondWindow.show(paragraph[i]);
|
2016-08-27 11:42:12 +02:00
|
|
|
|
},
|
2021-12-12 09:37:03 +01:00
|
|
|
|
inputRespond: function (state) {
|
2016-08-29 03:19:51 +02:00
|
|
|
|
this.current = state;
|
|
|
|
|
this.inputTimes++;
|
|
|
|
|
this.hintRespond();
|
|
|
|
|
this.doCumulate();
|
|
|
|
|
this.cumulateRespond();
|
|
|
|
|
},
|
2016-08-27 11:42:12 +02:00
|
|
|
|
};
|
|
|
|
|
|
2016-08-28 05:46:21 +02:00
|
|
|
|
|
2016-08-29 06:56:03 +02:00
|
|
|
|
var fontPx = document.getElementById('fontPx').children[1];
|
|
|
|
|
|
2021-12-12 09:37:03 +01:00
|
|
|
|
fontPx.oninput = function () {
|
2016-08-29 06:56:03 +02:00
|
|
|
|
document.body.style.fontSize = this.value + 'pt';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-08-27 06:35:52 +02:00
|
|
|
|
inputBar.oninput = function(){
|
2016-08-28 18:42:50 +02:00
|
|
|
|
var allAlphabet = this.value;
|
2021-12-12 09:37:03 +01:00
|
|
|
|
if (allAlphabet.substr(-1) === '\n') {
|
|
|
|
|
if (respondWindow.say(allAlphabet)) respondRobot.chatBack();
|
2016-08-28 18:42:50 +02:00
|
|
|
|
this.value = '';
|
2021-12-12 09:37:03 +01:00
|
|
|
|
}
|
|
|
|
|
else if (allAlphabet.charAt(0) == ':') ;
|
|
|
|
|
else if (allAlphabet.substr(-1) === ' ') {
|
2016-08-27 06:35:52 +02:00
|
|
|
|
this.value = '';
|
2021-12-12 09:37:03 +01:00
|
|
|
|
visualBar.node.textContent = characterTable.findCharacter(
|
|
|
|
|
allAlphabet.substr(0, allAlphabet.length-1)
|
|
|
|
|
) || '_';
|
2016-08-28 18:42:50 +02:00
|
|
|
|
|
2021-12-12 09:37:03 +01:00
|
|
|
|
if (visualBar.verifyCharacter()) questCharacter.nextCharacter();
|
2016-08-26 16:53:56 +02:00
|
|
|
|
else hintBar.hintCharacter();
|
2021-12-12 09:37:03 +01:00
|
|
|
|
}
|
|
|
|
|
else visualBar.generateCharacter(allAlphabet);
|
2016-08-27 06:35:52 +02:00
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2016-08-26 16:53:56 +02:00
|
|
|
|
|
2021-12-12 09:37:03 +01:00
|
|
|
|
function init() {
|
2016-08-27 03:11:11 +02:00
|
|
|
|
tabler.setTable();
|
2021-12-12 09:37:03 +01:00
|
|
|
|
characterTable = new MapCharacterTable(
|
2016-08-29 06:05:41 +02:00
|
|
|
|
document.getElementById( tabler.getCurrentId() )
|
|
|
|
|
);
|
|
|
|
|
|
2021-12-12 09:37:03 +01:00
|
|
|
|
if (!characterTable.findCharacter(questCharacter.node.title)) {
|
2016-08-26 16:53:56 +02:00
|
|
|
|
questCharacter.nextCharacter();
|
2021-12-12 09:37:03 +01:00
|
|
|
|
}
|
2016-08-26 16:53:56 +02:00
|
|
|
|
hintBar.newHintState();
|
|
|
|
|
inputBar.focus();
|
|
|
|
|
inputBar.select();
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-27 06:35:52 +02:00
|
|
|
|
window.onhashchange = init;
|
2016-08-26 16:53:56 +02:00
|
|
|
|
|
2016-08-28 05:46:21 +02:00
|
|
|
|
document.body.onload = init;
|
2016-08-26 16:53:56 +02:00
|
|
|
|
|