1. 퀴즈에 대한 데이터베이스가 필요했다.
API 를 일일히 요청하기 번거롭기에 로컬 데이터를 찾아보던 도중 끝말잇기 게임 "끄투" github 저장소에서 다음과 같은 자료를 찾았다.
github.com/JJoriping/KKuTu/blob/master/Server/lib/data/proverbs.txt
JJoriping/KKuTu
글자로 놀자! 끄투 온라인. Contribute to JJoriping/KKuTu development by creating an account on GitHub.
github.com
2. 해당 데이터를 한국어와 영어로 파일을 분리하였다. 밑에 올려드립니다.
proverb_ko.txt
0.05MB
proverb_en.txt
0.04MB
3. 수많은 시행 착오가 필요했다. 많은 버그들과 싸웠으며 이겨낸 결과이다.
위 파일을 아래 소스와 곁들이면 금상천화 ( •̀ ω •́ )✧
main.ms
| 
 1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
 | 
 include('proc.ms') 
bind('player_chat', null, null, @Data){ 
    @prefix = '[AutoQuiz] ' 
    if (import('autoquiz.status') == 0, exit()) 
    if (@Data['message'] == import('autoquiz.question_answer')) { 
        cancel() 
        @player = @Data['player'] 
        if (array_contains(_getUser(), @player)) { 
            msg(@prefix'§6이미 보상을 받으셨습니다.') 
            die() 
        } 
        @reward = import('autoquiz.reward') 
        @chance = import('autoquiz.chance') 
        if (@reward < 1, @reward = 1) 
        if (@chance == 1, @message = "§e+".@reward."원", @message = "§a경험치 +".@reward) 
        @size = array_size(_getUser()) 
        if (@size == 0) { 
            if (@chance == 3 || @chance == 4) { 
                broadcast(@prefix @player'님이 가장 빠르게 문장을 입력하셨습니다!') 
                export('autoquiz.settime', time() + 5000) 
            } else { 
                broadcast(@prefix @player'님이 가장 빠르게 문제의 정답을 맞추셨습니다!') 
                export('autoquiz.settime', time() + 4000) 
            } 
            broadcast(@prefix'§7보상 : '.@message) 
            export('autoquiz.status', 2) 
        } else { 
            @size = @size + 1 
            if (@chance == 3 || @chance == 4) { 
                msg(@prefix'당신은 '.@size.'번째로 문장을 입력하셨습니다!') 
            } else { 
                msg(@prefix'당신은 '.@size.'번째로 정답을 맞추셨습니다!') 
            } 
            msg(@prefix'§7보상 : '.@message) 
        } 
        if (@chance == 1, acc_add(@player, @reward), runas('~console', '/giveexp'@player @reward)) 
        export('autoquiz.reward', round(@reward / 1.4, 3)) 
        _addUser(@player) 
    } 
} 
 | 
cs | 
proc.ms
| 
 1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 
61 
62 
63 
64 
65 
66 
67 
68 
69 
70 
71 
72 
73 
74 
75 
76 
77 
78 
79 
80 
81 
82 
83 
84 
85 
86 
87 
88 
89 
90 
91 
92 
93 
94 
95 
96 
97 
98 
99 
100 
101 
102 
103 
104 
105 
106 
107 
108 
109 
110 
111 
112 
113 
114 
115 
116 
117 
118 
119 
120 
121 
122 
123 
124 
125 
126 
127 
128 
129 
130 
131 
132 
133 
134 
135 
136 
137 
138 
139 
140 
141 
142 
143 
144 
145 
146 
147 
148 
149 
150 
151 
152 
153 
154 
155 
156 
157 
158 
159 
160 
161 
162 
163 
164 
165 
166 
167 
168 
169 
170 
171 
172 
173 
174 
175 
176 
177 
178 
179 
180 
181 
182 
183 
184 
185 
186 
187 
188 
189 
190 
191 
192 
193 
194 
195 
196 
197 
198 
199 
200 
201 
202 
203 
204 
205 
206 
207 
208 
209 
210 
211 
212 
213 
214 
215 
216 
217 
218 
219 
220 
221 
222 
223 
224 
225 
226 
227 
228 
229 
230 
231 
232 
233 
234 
235 
236 
237 
238 
239 
240 
241 
242 
243 
244 
245 
246 
247 
248 
249 
250 
251 
252 
253 
254 
255 
256 
257 
258 
259 
260 
261 
262 
263 
264 
265 
266 
267 
268 
269 
270 
271 
272 
273 
274 
275 
276 
277 
278 
279 
 | 
 export('autoquiz.answer', '') 
export('autoquiz.question_message', '') 
export('autoquiz.question_math_message', '') 
export('autoquiz.question_type', '') 
export('autoquiz.question_answer', '') 
export('autoquiz.reward', 0) 
export('autoquiz.status', 0) 
export('autoquiz.settime', 0) 
export('autoquiz.chance', 0) 
export('autoquiz.proverb.ko', split('\n', comp_read('proverb_ko.txt'))) 
export('autoquiz.proverb.en', split('\n', comp_read('proverb_en.txt'))) 
export('autoquiz.process_user', array()) 
proc _getUser() { return(import('autoquiz.process_user')) } 
proc _addUser(@value){ 
    @array = import('autoquiz.process_user') 
    array_push(@array, @value) 
    export('autoquiz.process_user', @array) 
} 
proc _initUser() { export('autoquiz.process_user', array()) } 
if (import('autoquiz.settime') == 0) { export('autoquiz.settime', time() + 1500000) } 
proc _initQuiz(){ 
    export('autoquiz.status', 0) 
    _initUser() 
} 
set_interval(1000, closure(){ 
    @prefix = '[AutoQuiz] ' 
    @rand = rand(1500000,1800000) 
    if (import('autoquiz.status') == 2) { 
        if (time() >= import('autoquiz.settime')) { 
            broadcast(@prefix'끝! '.array_size(_getUser()).'명이 참여해주셨습니다.') 
            export('autoquiz.settime', time() + @rand) // 25분 ~ 30분 (UNIX time with nano second) 
            _initQuiz() 
        } 
    } else { 
        if (time() >= import('autoquiz.settime')) { 
            if (import('autoquiz.status') == 1) { 
                export('autoquiz.settime', time() + @rand) // 25분 ~ 30분 (UNIX time with nano second) 
                _initQuiz() 
                broadcast('') 
                @type = import('autoquiz.question_type') 
                if (@type == 'math'){ 
                    broadcast(@prefix.' '.import('autoquiz.question_math_message').' = '.import('autoquiz.question_answer')) 
                } else if (@type == 'math2') { 
                    broadcast(@prefix.' '.import('autoquiz.question_math_message')) 
                } else if (@type == 'kor_hidden_word_match') { 
                    broadcast(@prefix.' "§f'.import('autoquiz.question_answer').'§7"') 
                } 
                broadcast(@prefix'§7정답자가 없어 문제가 취소됩니다.') 
                broadcast('') 
                exit() 
            } 
            export('autoquiz.settime', time() + @rand) 
            export('autoquiz.status', 1) 
            switch(rand(1,8)) { 
                case 1..2: 
                    @chance = 1 
                case 3..4: 
                    @chance = 2 
                case 5..6: 
                    @chance = 3 
                case 7..8: 
                    @chance = 4 
            } 
            export('autoquiz.chance', @chance) 
            if (@chance == 4) { 
                @proverb = import('autoquiz.proverb.en') 
                @cur_proverb = @proverb[array_rand(@proverb)[0]] 
                @reward = rand(13,18) 
                export('autoquiz.question_message', @cur_proverb) 
                export('autoquiz.question_type', 'eng_typing_test') 
                export('autoquiz.question_answer', @cur_proverb) 
                export('autoquiz.reward', @reward) 
                broadcast('') 
                broadcast(@prefix '다음의 문장을 채팅창에 빠르게 입력하세요!') 
                broadcast(@prefix '"§f'.@cur_proverb.'§7"') 
                broadcast('') 
            } else if (@chance == 3) { 
                @proverb = import('autoquiz.proverb.ko') 
                @cur_proverb = @proverb[array_rand(@proverb)[0]] 
                @reward = rand(13,18) 
                export('autoquiz.question_message', @cur_proverb) 
                export('autoquiz.question_type', 'kor_typing_test') 
                export('autoquiz.question_answer', @cur_proverb) 
                export('autoquiz.reward', @reward) 
                broadcast('') 
                broadcast(@prefix '다음의 문장을 채팅창에 빠르게 입력하세요!') 
                broadcast(@prefix '"§f'.@cur_proverb.'§7"') 
                broadcast('') 
            } else if (@chance == 2) { 
                @proverb = import('autoquiz.proverb.ko') 
                @cur_proverb = @proverb[array_rand(@proverb)[0]] 
                @array_cur_proverb = split(' ', @cur_proverb) 
                @length = ceil(divide(array_size(@array_cur_proverb), 4)) 
                @indexs = array_rand(@array_cur_proverb, @length) 
                @answer = array() 
                @length = 1 // 하나 고정 
                for (assign(@i, 0), @i < @length, @i++) { 
                    @cur = @array_cur_proverb[@indexs[@i]] 
                    // @array_cur_proverb[@indexs[@i]] = reg_replace('[ㄱ-ㅎ|ㅏ-ㅣ|가-힣]', 'ㅁ', @cur) 
                    // if(reg_count('[ㄱ-ㅎ|ㅏ-ㅣ|가-힣]', @cur) != length(@cur)) { 
                    // } 
                    @str = '' 
                    @bo = false 
                    for (assign(@n, 0), @n < length(@cur), @n++) { 
                        @cc = substr(@cur, @n, @n+1) 
                        if (@cc != ',') { 
                            @str = @str.'#' 
                        } else { 
                            @str = @str.',' 
                            @bo = true 
                        } 
                    } 
                    if (@bo) { 
                        array_push(@answer, substr(@cur, 0, length(@cur) - 1)) 
                    } else { 
                        array_push(@answer, @cur) 
                    } 
                    @array_cur_proverb[@indexs[@i]] = @str 
                } 
                // for (assign(@i, 0), @i < array_size(@array_cur_proverb), @i++) { 
                //     @cur = @array_cur_proverb[@i].',' 
                //     msg('run' @cur reg_match_all('[ㄱ-ㅎ|ㅏ-ㅣ|가-힣]', @cur) reg_count('[ㄱ-ㅎ|ㅏ-ㅣ|가-힣]', @cur) length(@cur)) 
                //     @r_temp[@i] = reg_replace('[ㄱ-ㅎ|ㅏ-ㅣ|가-힣]', 'ㅁ', @cur) 
                // } 
                // msg(_chprefix('a')@array_cur_proverb) 
                // msg(_chprefix('a')' 'split('\n', comp_read('proverb_ko.txt'))) 
                // msg(_chprefix('a')' 'all_materials()) 
                @message = '' 
                foreach(@s in @array_cur_proverb) { 
                    if (@s == ' ') { 
                        continue(); 
                    } 
                    @message = @message.' '.@s 
                } 
                // @answer_m = '' 
                // foreach(@s in @answer) { 
                //     @answer_m = @answer_m.' '.@s 
                // } 
                if (substr(@message, 0, 1) == ' ') { 
                    @message = substr(@message, 1, length(@message)) 
                } 
                @reward = rand(15,20) 
                export('autoquiz.question_message', @message) 
                export('autoquiz.question_type', 'kor_hidden_word_match') 
                export('autoquiz.question_answer', @answer[0]) 
                export('autoquiz.reward', @reward) 
                broadcast('') 
                broadcast(@prefix '다음 중 빈 문장의 문장을 채팅에 입력하세요!') 
                broadcast(@prefix '"§f'.import('autoquiz.question_message').'§7"') 
                broadcast('') 
            } else if (@chance == 1) { 
                switch(rand(1,20)) { 
                    case 1..2: 
                        @math1 = rand(2,99) 
                        @math2 = rand(0,99) 
                        @reward = rand(3,8) 
                        export('autoquiz.question_message', @math1.' + '.@math2.' = §6???') 
                        export('autoquiz.question_math_message', @math1.' + '.@math2) 
                        export('autoquiz.question_type', 'math') 
                        export('autoquiz.question_answer', @math1 + @math2) 
                        export('autoquiz.reward', @reward) 
                    case 3..4: 
                        @math1 = rand(20,99) 
                        @math2 = rand(0,80) 
                        @reward = rand(3,8) 
                        if (@math1 < @math2) { 
                            @temp = @math1 
                            @math1 = @math2 
                            @math2 = @temp 
                        } 
                        export('autoquiz.question_message', @math1.' - '.@math2.' = §6???') 
                        export('autoquiz.question_math_message', @math1.' - '.@math2) 
                        export('autoquiz.question_type', 'math') 
                        export('autoquiz.question_answer', @math1 - @math2) 
                        export('autoquiz.reward', @reward) 
                    case 5..6: 
                        @math1 = rand(1,12) 
                        @math2 = rand(1,13) 
                        @reward = rand(4,10) 
                        export('autoquiz.question_message', @math1.' X '.@math2.' = §6???') 
                        export('autoquiz.question_math_message', @math1.' X '.@math2) 
                        export('autoquiz.question_type', 'math') 
                        export('autoquiz.question_answer', @math1 * @math2) 
                        export('autoquiz.reward', @reward) 
                    case 7..8: 
                        @math1 = rand(8,99) 
                        @math2 = rand(1,9) 
                        @reward = rand(5,10) 
                        export('autoquiz.question_message', @math1.' ÷ '.@math2.' = §6???§7(자연수)') 
                        export('autoquiz.question_math_message', @math1.' ÷ '.@math2) 
                        export('autoquiz.question_type', 'math') 
                        export('autoquiz.question_answer', integer(@math1 / @math2)) 
                        export('autoquiz.reward', @reward) 
                    case 9..10: 
                        @math1 = rand(9,26) 
                        @math2 = rand(1,4) 
                        @reward = rand(6,12) 
                        export('autoquiz.question_message', @math1.' 의 '.@math2.' 제곱 = §6???') 
                        export('autoquiz.question_math_message', @math1.' 의 '.@math2.' 제곱') 
                        export('autoquiz.question_type', 'math') 
                        export('autoquiz.question_answer', integer(pow(@math1,@math2))) // or ** 
                        export('autoquiz.reward', @reward) 
                    case 11..12: 
                        @math1 = rand(0,150) 
                        @math2 = rand(0,200) 
                        @math3 = rand(0,175) 
                        @reward = rand(4,11) 
                        export('autoquiz.question_message', @math1.' + '.@math2.' - '.@math3.' = §6???') 
                        export('autoquiz.question_math_message', @math1.' + '.@math2.' - '.@math3) 
                        export('autoquiz.question_type', 'math') 
                        export('autoquiz.question_answer', @math1 + @math2 - @math3) 
                        export('autoquiz.reward', @reward) 
                    case 13..14: 
                        @math1 = rand(2,99) 
                        @math2 = rand(0,50) 
                        @result = @math1 + @math2 
                        @reward = rand(4,9) 
                        export('autoquiz.question_message', @math1.' + §6??? §f= '.@result) 
                        export('autoquiz.question_math_message', @math1.' + '.@math2.' = '.@result) 
                        export('autoquiz.question_type', 'math2') 
                        export('autoquiz.question_answer', @math2) 
                        export('autoquiz.reward', @reward) 
                    case 15..16: 
                        @math1 = rand(2,99) 
                        @math2 = rand(0,50) 
                        @result = @math1 + @math2 
                        @reward = rand(4,9) 
                        export('autoquiz.question_message', '§6??? §f+ '.@math2.' = '.@result) 
                        export('autoquiz.question_math_message', @math1.' + '.@math2.' = '.@result) 
                        export('autoquiz.question_type', 'math2') 
                        export('autoquiz.question_answer', @math1) 
                        export('autoquiz.reward', @reward) 
                    case 17..18: 
                        @math1 = rand(3,13) 
                        @math2 = rand(1,@math1) 
                        @result = @math1 * @math2 
                        @reward = rand(4,9) 
                        export('autoquiz.question_message', '§6??? §f* '.@math2.' = '.@result) 
                        export('autoquiz.question_math_message', @math1.' * '.@math2.' = '.@result) 
                        export('autoquiz.question_type', 'math2') 
                        export('autoquiz.question_answer', @math1) 
                        export('autoquiz.reward', @reward) 
                    case 19..20: 
                        @math1 = rand(3,13) 
                        @math2 = rand(0,@math1) 
                        @result = @math1 * @math2 
                        @reward = rand(4,9) 
                        export('autoquiz.question_message', @math1.' * §6??? §f= '.@result) 
                        export('autoquiz.question_math_message', @math1.' * '.@math2.' = '.@result) 
                        export('autoquiz.question_type', 'math2') 
                        export('autoquiz.question_answer', @math2) 
                        export('autoquiz.reward', @reward) 
                } 
                broadcast('') 
                broadcast(@prefix.'§f '.import('autoquiz.question_message')) 
                broadcast('') 
            } 
            foreach(@player in all_players()) { 
                play_named_sound(ploc(@player), array('sound': 'block.note_block.pling', 'pitch': 1.2), array(@player)) 
            } 
            console('[AutoQuiz][Info] Answer : '.import('autoquiz.question_answer')) 
        } 
    } 
}) 
 | 
cs | 
반응형