今回行うのはレベル制の導入とスコアの導入、ランキング対応の処理です。 早速、レベル制について変更していきましょう。 レベルは2節で導入したステージよりも更にもう1つ大きな括りのことを指しており、 初級レベル3ステージ、中級レベル3ステージ、上級レベル3ステージに分類します。
1 2 3 4 5 6 7 8 9 10 |
dim num, 3, 3 // 1次元目はステージ、2次元目はレベル num.0.0 = 3, 4, 5 // 初級レベル num.0.1 = 5, 6, 7 // 中級レベル num.0.2 = 7, 8, 9 // 上級レベル koma = 50, 35, 20 // レベル毎に表示時間を変更 objsize 100, 25 onkey gosub *push_key randomize mmload "error.wav", 0 mmload "correct.wav", 1 |
1 2 3 4 5 6 7 8 |
*game_init answer = 0, 0 dim question, num.stage.lv foreach question question.cnt = rnd(9) + 1 answer.1 += question.cnt loop return |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
*game_draw clear pos 10, 10 : mes "第 " + (stage + 1) + " / " + length(num) + " 問目" pos 10, 30 : mes "表示数 " + num.stage.lv + "個 pos 10, 50 : mes strf("%1.2f 秒 / コマ", 0.01 * koma.lv) countdown 3 font msmincho, SIZE foreach question color 255, 255, 255 : boxf : color , 150 wait 10 pos (ginfo_winx - SIZE / 2) / 2, (ginfo_winy - SIZE) / 2 mes question.cnt wait koma.lv loop return |
1 2 3 4 5 6 |
*init clear pos 10, 10 : combox lv, , "初級\n中級\n上級" pos 10, 40 : button gosub "開始", *click_button objsel 0 countdown |
1 2 3 4 5 6 7 8 9 10 11 |
*game_main stage = 0 truth = 0 score = 0 // ゲームの度にスコアは初期化する foreach num gosub *game_init gosub *game_draw gosub *game_answer gosub *game_judge loop goto *init |
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 |
*game_judge truth += (answer.0 = answer.1) * click score += answer * (answer.0 = answer.1) // 「if answer.0 = answer.1 : score += answer」と同じ stage++ clear pos 10, 10 : mes "入力:" + answer.0 pos 10, 30 : mes "正解:" + answer.1 pos 10, 50 : mes "正答率 " + strf("%2.2f %", 100.0 * truth / stage) pos 10, 70 : mes "スコア " + score pos 10, 90 : button gosub "次へ", *click_button if click = 0 : pos 90, 10 : mes "( 時間切れ )" pos 90, 30 : mes "(" pos length(question) * 30 + 85, 30 : mes ")" foreach question if cnt : pos cnt * 30 + 85, 30 : mes "+" pos cnt * 30 + 100, 30 : mes question.cnt loop font msmincho, SIZE, 1 tmp = "×○" color (answer.0 ! answer.1 | click = 0) * 255, , (answer.0 = answer.1) * click * 255 pos (ginfo_winx - SIZE) / 2, (ginfo_winy - SIZE) / 2 mes strmid(tmp, (answer.0 = answer.1) * click * 2, 2) mmplay (answer.0 = answer.1) * click countdown return |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#deffunc countdown int count, local i click@ = 0 i = ginfo_winx - SIZE@, ginfo_winy - SIZE@, ginfo_winx + SIZE@, ginfo_winy + SIZE@ font msmincho, SIZE@ / 3 * 2 repeat , 30 if click@ ! 0 | cnt / 30 = count : i = count * 30 - cnt : break // 変数iにカウント残をセット if count ! 0 & cnt \ 30 = 0 { redraw 0 color 255, 255, 255 : boxf i.0 / 2, i.1 / 2 if count - cnt / 30 > 3 : color : else : color 255 circle i.0 / 2, i.1 / 2, i.2 / 2, i.3 / 2 pos (ginfo_winx - SIZE@ / 3 * 2) / 2, (ginfo_winy - SIZE@ / 3 * 2) / 2 mes count - cnt / 30 color 255, 255, 255 circle (i.0 + 15) / 2, (i.1 + 15) / 2, (i.2 - 15) / 2, (i.3 - 15) / 2, 0 pos (ginfo_winx - ginfo_mesx) / 2, (ginfo_winy - ginfo_mesy) / 2 mes count - cnt / 30 redraw 1 } await 33 loop return i // カウント残を返す |
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 |
*game_judge truth += (answer.0 = answer.1) * click score += stat * answer * (answer.0 = answer.1) // 「if answer.0 = answer.1 : score += stat * answer」と同じ stage++ clear pos 10, 10 : mes "入力:" + answer.0 pos 10, 30 : mes "正解:" + answer.1 pos 10, 50 : mes "正答率 " + strf("%2.2f %", 100.0 * truth / stage) pos 10, 70 : mes "スコア " + score pos 10, 90 : button gosub "次へ", *click_button if click = 0 : pos 90, 10 : mes "( 時間切れ )" pos 90, 30 : mes "(" pos length(question) * 30 + 85, 30 : mes ")" foreach question if cnt : pos cnt * 30 + 85, 30 : mes "+" pos cnt * 30 + 100, 30 : mes question.cnt loop font msmincho, SIZE, 1 tmp = "×○" color (answer.0 ! answer.1 | click = 0) * 255, , (answer.0 = answer.1) * click * 255 pos (ginfo_winx - SIZE) / 2, (ginfo_winy - SIZE) / 2 mes strmid(tmp, (answer.0 = answer.1) * click * 2, 2) mmplay (answer.0 = answer.1) * click countdown return |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
dim num, 3, 3 num.0.0 = 3, 4, 5 num.0.1 = 5, 6, 7 num.0.2 = 7, 8, 9 koma = 50, 35, 20 name = "player" // ランキングに保存するプレイヤー初期名 notesel ranking // 全ランキングデータ保持変数をメモリノートパッドの対象に設定 objsize 100, 25 onkey gosub *push_key randomize mmload "error.wav", 0 mmload "correct.wav", 1 gosub *rank_load // ランキングデータ読込 |
1 2 3 4 5 6 7 8 9 |
*rank_load exist "flash.rnk" if strsize = -1 { ranking = "ultimate\t30000\nsatoshi\t22000\nhspbc\t17000\nmiddle\t13000\nlecture\t9500\nflash\t6800" notesave "flash.rnk" } else { noteload "flash.rnk" } return |
1 2 |
#define FILE "flash.rnk" #define SIZE 250 |
1 2 3 4 5 6 7 8 9 |
*rank_load exist FILE if strsize = -1 { ranking = "ultimate\t30000\nsatoshi\t22000\nhspbc\t17000\nmiddle\t13000\nlecture\t9500\nflash\t6800" notesave FILE } else { noteload FILE } return |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
*rank_draw font msmincho, 30 color 255 pos 50, 100 : mes "ランク" pos 180, 100 : mes "名前" pos 450, 100 : mes "スコア" font msmincho, 25 repeat notemax noteget tmp, cnt color , 255 line 50, cnt * 50 + 140, 540, cnt * 50 + 140 color , , 255 pos 50, cnt * 50 + 150 : mes strf("%4d", cnt + 1) pos 180, cnt * 50 + 150 : mes strmid(tmp, 0, instr(tmp, , "\t")) pos 450, cnt * 50 + 150 : mes strf("%6d", int(strmid(tmp, instr(tmp, , "\t") + 1, strlen(tmp) - instr(tmp, , "\t") - 1))) loop return |
1 2 3 4 5 6 7 |
*init clear pos 10, 10 : combox lv, , "初級\n中級\n上級" pos 10, 40 : button gosub "開始", *click_button gosub *rank_draw // ランキングデータ描画 objsel 0 countdown |
1 2 3 4 5 6 7 8 9 10 |
*rank_check i = notemax // ランク外の順位を付けておく repeat notemax noteget tmp, cnt if score >= int(strmid(tmp, instr(tmp, , "\t") + 1, strlen(tmp) - instr(tmp, , "\t") - 1)) { // ランクイン i = cnt break } loop return |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
*rank_entry clear pos 10, 10 : mes "総スコア " + score pos 10, 30 : mes "順位 " + strf("%d位", i + 1) pos 10, 50 if i < notemax { mes "名前" pos 75, 50 : input name, 100, 20, 8 } else { mes "ランク入りしませんでした…。" } pos 10, 80 : button gosub "終了", *click_button countdown return |
1 2 3 4 5 6 7 |
*rank_save if i < notemax { noteadd name + "\t" + score, i // 今回の順位位置に追加 notedel notemax - 1 // 最下位は削除してランク数は変更なし notesave FILE } return |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
*game_main stage = 0 truth = 0 score = 0 foreach num gosub *game_init gosub *game_draw gosub *game_answer gosub *game_judge loop gosub *rank_check // ランキングチェック gosub *rank_entry // ランキング更新 gosub *rank_save // ランキング保存 goto *init |