Hangul Quiz Game
Last updated
Was this helpful?
Last updated
Was this helpful?
1) File
2) main.js
const STATE_INIT = 3000;
const STATE_READY = 3001;
const STATE_PLAYING = 3002;
const STATE_JUDGE = 3004;
const STATE_END = 3005;
const WORD_LINES = [
'ํ๊ธ๋ ํด๊ฒ์ ํ๊ธฐ์ฆ ํ๊ดํ ํธ๋ ๋ ํ๋๋ฌธ ํ๋
ธ์ด ํซ๋๊ทธ ํ๋๊นจ ํค๋์
ํด๋์ด ํ๋ผ๋ด ํ๋ผ์ฐ ํธ๋์ด ํ๋ฆฌ๋ ํ๋ฏธ๊ฒฝ ํฐ๋จธ๋ฆฌ ํฉ๋ฌด์ง ํ๋ฒ๊ฑฐ ํ๋ถ๋ชจ ํ๋ฐ์ ํ๋ฒ
์ง ํ์๊ตฌ ํธ์ ์ ํ์์ ํ์น์ด ํ์คํค ํ์คํฐ ํด์ด๋ ํ์ฃผ๋ก ํด์งํต ํ์ฅํ ํ์ด๋ฆฌ ํซํฌ์ธ ํํํ',
'ํผ๊ท์ด ํ๊ฟ์น ํฌ๋์ฃผ ํผ๋ผ๋ ํผ๋ผ๋ฏธ ํผ๋ขฐ์นจ ํ๋ฆฌํฅ ํ๋ผํ ํฌ๋ฏธ๋ ํฅ๋น์ ํ๋ฐฑ์ ํ์๋ฆฌ ํผ์๋ฐฉ ํ์จ๋ฆ ํผ์๋
ธ ํธ์์ ํ์๋ง ํฌ์ฅ์ง ํ์งํ ํ์ถฉ๋ฅ ํ์ถ๋ถ ํ์ถ์ ํฌ์ฒญ์ฒ ํฌํด๋ฝ ํฌ์ผ๋ณผ ํผ์นด์ ํผ์นด์ธ ํญํ์ฃผ ํผํฐํฌ',
'ํ๊ทน๊ธฐ ํ๊ถ๋ ํฑ๊ฑธ์ด ํ
๋์ค ํธ๋ ํฌ ํฐ๋ฏธ๋ ํด๋ง์ฌ ํ ๋งํ ํฌ๋ฒ๋ฆฐ ํฌ์๊ธฐ ํฑ์๋ ํ์์ก ํ ์คํธ ํ์๊ณ ํฐ์๋ผ ํ์ด๋ฐ ํ์์ค ํธ์ํฐ ํด์ง๊ธ ํต์กฐ๋ฆผ ํ์ง์ ํํ์ ํ
ํค๋',
'์บฅ๊ฑฐ๋ฃจ ์ฝง๊ตฌ๋ฉ ์ฝ๋ผ๋ฆฌ ์บ๋๋ค ์ฝฉ๋๋ฌผ ์ฝ๋ํฅ ์ปจ๋์
์ฝ๋ฌ์ค ์นด๋ฉ๋ผ ์นด๋ฉ์ค ํค๋ณด๋ ์ฝค๋ฐ์ธ ์ฝ๋ฟ์ ์ผ์ดํฌ ์ฝ์ฝ๋ ์นดํ๋ฅด ์นตํ
์ผ ์ปคํ๋ง',
'์ฐธ๊ธฐ๋ฆ ์ฒ ๊ฐ๋ฐฉ ์ด๋ฅ๋ ฅ ์ถ๋์ฆ ์ทจ๋๋ถ ์ฒญ๊ณ์ฒ ์ฑ
๊ฐํผ ์ฑ
๊ฝ์ด ์ด๋ฅ๋ ฅ ์ถ๋์ฆ ์ฐฝ๋๊ถ ์ฐจ๋๋ฆฌ ์ต๋ฃจํ ์ต๋ฉด์ ์น ๋ฉด์กฐ ์ฒญ๋ฐ์ง ์ฒญ์๋
์ถ์๋ถ ์ฐน์๋ก ์ฒญ์๋ ์ฒซ์ธ์ ์น์์ ์ด์ธ์ข
์ถ์ดํ ์ด์ํ ์นจ์ ๋ฌผ ์ฒญ์ฒฉ์ฅ ์ด์ฝ๋ฆฟ ์นํธํค ์ถํ์ฌ ์ฑํผ์ธ ์นจํฌ์ง ์ตํ๋ง',
'๊ณ๊ธฐํ ๊ฐ๋๋ฆฌ ๊ธฐ๋ด์ ๊ฐ๋ญ์ฝฉ ๊ต๋๊ด ๊ณ ๋๋ฆ ๊ณจ๋ํ ๊ธฐ๋ฌ๊ธฐ ๊ฐ๋ก๋ฑ ๊ฐ๋๋ก ๊ธ๋ฌ๋ธ ๊ทธ๋ฆผ์ ๊ธฐ๋ชจ๋
ธ ๊ธ๋ฉ๋ฌ ๊ฑฐ๋จธ๋ฆฌ ๊ต๋ฌด์ค ๊ณต๋ฌด์ ๊ฑด๋ง์ฆ ๊ตฌ๋ฏธํธ ๊น๋ณ๋ง ๊ตญ๋ฐฉ๋ถ ๊ฑฐ๋ถ์ ๊ด๋ณต์ ๊ณฑ๋นผ๊ธฐ ๊ฐ์๋ ๊ฐ์ ๋ฏธ ๊ธฐ์์ฌ ๊ฐ์ค๋ฆฌ ๊ฑธ์๋ง ๊ฐ์์ค ๊ฑฐ์ง๋ง ๊ต์ฐจ๋ก ๊ณจํคํผ ๊ณผํ๋ฃ ๊นํ์ ๊นํํฌ ๊ฑดํฌ๋ ๊ณฐํก์ด ๊ณจํ์ง ๊ณตํฌํ ๊นํฅ๊ตญ ๊ดํ๋ฌธ ๊ณตํด์ผ ๊ณ ํ์ ๊ฝน๊ณผ๋ฆฌ ๊น๋๋ฆฌ ๊น๋๊ธฐ ๊ฝ๋ค๋ฐ ๊ฝ๋ฑ์ฌ ๊ผฝ๋ฑ์ด ๊น๋ง๊ท ๊น์น๋ฐ ๊นํ๊ธฐ',
'์ผ์ฒฉ ํน์นด ํน์ฝฉ ์ปจ๋ ์ฑ์ฐ ์ฐฝ๋ฌธ ์ฐธ๊นจ ์ฒ๊ตญ ์ถ๊ตฌ ์ถ๊ทผ ์น๊ตฌ ์น๊ณผ ์ทจ๊ถ ์ฑ๊ถ ์ด๊ณผ ์กฑ๋ฐ ์ ๋ฒฝ ์ ๋ณ ์ฃผ๋ถ ์ ๋ณต ์ค๋ณต ์ ๋ณต ์ ๋ฐ ์กฑ๋ณด ์๋ฐ ์ฃผ๋ฒ ์ข๋น ์ ๋น ์ฌ๊ณผ ์ฌ๊ธฐ ์๊ธ ์๊ณ ์๊ธ ์ ๊ฑฐ ์๋ฅ ์ค๋ ์ค๋',
'๋ชจ๋ ๋ฏธ๋ ๋ฏธ๋ก ๋ง๋ฃจ ๋ก๋ฐฅ ๋ธ๊ธฐ ๋ก๊ตญ ๋์ ๋์ ๋ด์ ๋
ธ์ ๋์ฝ ๋
น์ฉ ๋
ธ์ธ ๋๋ฌผ ๋๋ฉด ๋๋น ๋๋ฐฉ ๊ฐ์ ๊ฑฐ์ธ ๊ทผ์ก ๊ธฐํ ๊นํธ ๊ตฌํ ๊ตด๋ ๊ฐ๋
๊ทธ๋ค ๊ตฌ๋ฆ ๊ธฐ๋ฆฐ ๊ฒฝ๋ง ๊ฒฝ๋งค ๊ณ ๋ง ๊ฐ๋ฐฉ ๊ณต๋ถ ๊ณ ๋ฐฑ ๊ฐ๋ณ ๊ฐ๋น ๊น๋ฐฅ ๊ฑฐ๋ด ๊ตฐ๋ฐค ๊ธฐ๋ถ ๊ฑด๋นต ๊ฐ์'
];
let WORDS = [];
let _state = STATE_INIT;
let _stateTimer = 0;
let _timer = 0;
let _choanswer = '';
let _answer = '';
let _start = false;
let _widget = null; // using for contents UI
let _players = App.player;
let _result = '';
for(let w in WORD_LINES)
WORDS = WORDS.concat(WORD_LINES[w].trim().split(' '));
function cho_hangul(str) {
cho = ["ใฑ","ใฒ","ใด","ใท","ใธ","ใน","ใ
","ใ
","ใ
","ใ
","ใ
","ใ
","ใ
","ใ
","ใ
","ใ
","ใ
","ใ
","ใ
"];
result = "";
for (let i = 0; i < str.length; ++i ) {
code = str.charCodeAt(i)-44032;
if(code>-1 && code<11172) result += cho[Math.floor(code/588)];
else result += str.charAt(i);
}
return result;
}
App.onStart.Add(function(){
startState(STATE_INIT);
});
// when chatting event
// player : person who chatted
// text : chat text
// return : enter chatting box
// return false or true : not appear in chatting box
App.onSay.add(function(player, text) {
if(_state == STATE_PLAYING)
{
if(_answer == text)
{
_result = player.name + '๋ ์ ๋ต!\n์ ๋ต์ ' + _answer;
startState(STATE_JUDGE);
}
}
});
function startState(state) {
_state = state;
_stateTimer = 0;
switch(_state)
{
case STATE_INIT:
if(_widget)
{
_widget.destroy();
_widget = null;
}
_answer = WORDS[Math.floor(Math.random() * WORDS.length)];
_timer = 60;
_choanswer = cho_hangul(_answer);
// called html UI
// param1 : file name
// param2 : position
// [ top, topleft, topright, middle, middleleft, middleright, bottom, bottomleft, bottomright, popup ]
// param3 : width size
// param4 : height size
_widget = App.showWidget('widget.html', 'top', 200, 300);
_widget.sendMessage({
state: _state,
timer: _timer,
answer: _choanswer,
});
startState(STATE_READY);
break;
case STATE_READY:
_start = true;
startState(STATE_PLAYING);
break;
case STATE_PLAYING:
App.showCenterLabel('๋ชฉํ: ์ด์ฑํํธ๋ก ๋จ์ด๋ฅผ ์ฐพ์๋ด์ธ์.',0xFFFFFF, 0x000000, 115);
_widget.sendMessage({
state: _state,
timer: _timer,
answer: _choanswer,
});
break;
case STATE_JUDGE:
break;
case STATE_END:
if(_widget)
{
_widget.destroy();
_widget = null; // must to do for using again
}
_start = false;
break;
}
}
App.onLeavePlayer.Add(function(p) {
p.title = null;
p.sprite = null;
p.moveSpeed = 80;
p.sendUpdated();
});
App.onDestroy.Add(function() {
_start = false;
if(_widget)
{
_widget.destroy();
_widget = null;
}
});
App.onUpdate.Add(function(dt) {
if(!_start)
return;
_stateTimer += dt;
switch(_state)
{
case STATE_INIT:
break;
case STATE_READY:
_start = true;
break;
case STATE_PLAYING:
if(_stateTimer >= 1)
{
_stateTimer = 0;
_timer -= 1;
}
if(_timer == 0)
{
_result = '์ ๋ต์ ' + _answer + ' ์
๋๋ค.';
startState(STATE_JUDGE);
}
break;
case STATE_JUDGE:
App.showCenterLabel(_result, 0xFFFFFF, 0x000000, 115);
if(_stateTimer >= 3)
startState(STATE_END);
break;
case STATE_END:
break;
}
});