comparison event/oasis2017/quiz/quiz.rb @ 1712:afcc7ed107e7

Add GPS quiz program
author houtin <c115080@g.koeki-u.ac.jp>
date Fri, 28 Jul 2017 15:20:41 +0900
parents 835f5f6fe824
children 3a7d6850fe1e
comparison
equal deleted inserted replaced
1711:310e3b803ad7 1712:afcc7ed107e7
71 playname = dbn[0] # データベースからのの名前をプレイ名とする 71 playname = dbn[0] # データベースからのの名前をプレイ名とする
72 end 72 end
73 end 73 end
74 if playname == "" || ARGV[0] == "reset" 74 if playname == "" || ARGV[0] == "reset"
75 print(<<-EOF) 75 print(<<-EOF)
76 <form action="#{myname}" method="POST"> 76 <!DOCTYPE html>
77 <p>プレイ名を入れてください: 77 <html lang="ja">
78 <input type="text" name="playname"> 78 <head><title>登録</title>
79 <link rel="stylesheet" type="text/css" href="quizpg.css" >
80 <meta name="viewport" content="width=device-width,initial-scale=1">
81 </head>
82 <body>
83 <form action="#{myname}" method="POST">
84 <h1 class="eleg">庄内クイズへようこそ!</h1>
85 <p class=\"big\">プレイヤー名を入れてください</p><br>
86 <input type="text" name="playname">
79 <input type="submit" value="送信"> 87 <input type="submit" value="送信">
80 <input type="reset" value="リセット"> 88 <input type="reset" value="リセット">
81 </form> 89 </form>
90 <p>ゲームを進める上での注意</p>
91 <ol><li>画像を押すと大きくなりますが、通信量を消費するのでご了承ください。動画再生も同じく。</li>
92 <li>3問正解したら他のQRコードを探しに行こう。</li></ol>
93
94 </body></html>
82 EOF 95 EOF
83 exit 96 exit
84 end 97 end
85 printf("<h1>%sさんのチャレンジ</h1>\n", playname) 98 printf("<h1><a class=\"name\">%s</a>さんのチャレンジ!</h1>\n", playname)
86 ################################################################## 初回処理 99 ################################################################## 初回処理
87 100
88 number = c["rd"] 101 number = c["rd"]
89 def outinput(value, label) 102 def outinput(value, label)
90 printf("<label><input type=\"radio\" name=\"rd\" value=\"%s\">%s</label>", value, label) 103 printf("<label><input type=\"radio\" name=\"rd\" value=\"%s\">%s</label>", value, label)
91 end 104 end
92 105
93 def imgsrc(img) 106 def imgsrc(img)
94 printf("<a href=\"%s.jpg\"\><img src=\"%s_mini.jpg\"></a>", img, img) 107 printf("<a href=\"%s.jpg\"\><img src=\"%s_mini.jpg\" class=\"shadow\"></a>", img, img)
95 end 108 end
96 109
97 ## 問題情報の読み込み 110 ## 問題情報の読み込み
98 question = {} 111 question = {}
99 n_question = 0 112 n_question = 0
148 ansinfo = q[form_qn] # 今の問の選択肢と解答配列 161 ansinfo = q[form_qn] # 今の問の選択肢と解答配列
149 # ↑で [hiyori,舞鶴公園,日和山公園,飯森山公園,2,skipseikai1.mp4] 各々文字列 162 # ↑で [hiyori,舞鶴公園,日和山公園,飯森山公園,2,skipseikai1.mp4] 各々文字列
150 image, s1, s2, s3, ans, movie = *ansinfo 163 image, s1, s2, s3, ans, movie = *ansinfo
151 164
152 if number == ans then 165 if number == ans then
153 print "<h2>正解!!</h2>" 166 print "<h2 class=\"underline\">正解!!</h2>"
154 db.execute("REPLACE INTO point VALUES(?, ?)", 167 db.execute("REPLACE INTO point VALUES(?, ?)",
155 id, "quiz-" + quiz_mode + "-" + form_qn) # ex. quiz-kantan-1 168 id, "quiz-" + quiz_mode + "-" + form_qn) # ex. quiz-kantan-1
156 printf(<<-EOF, movie, quiz_mode, 1+form_qn.to_i) 169 printf(<<-EOF, movie, quiz_mode, 1+form_qn.to_i)
157 <video controls autoplay width="320" height="240"> 170 <video controls autoplay width="320" height="240">
158 <source src="%s"> 171 <source src="%s">
162 EOF 175 EOF
163 # form_qn を1ふやして hidden に仕込む 176 # form_qn を1ふやして hidden に仕込む
164 if form_qn.to_i < q.length # まだ次の問がある 177 if form_qn.to_i < q.length # まだ次の問がある
165 puts('<p><input type="submit" value="次の問題へ進む"></p>') 178 puts('<p><input type="submit" value="次の問題へ進む"></p>')
166 else # 用意した問すべて終了 179 else # 用意した問すべて終了
167 puts("<p>おめでとう!</p>") 180 # puts("<p>おめでとう!</p>")
168 n_right = db.execute("SELECT count(*) FROM point WHERE id=?", id)[0][0] 181 n_right = db.execute("SELECT count(*) FROM point WHERE id=?", id)[0][0]
169 printf(<<-EOF, n_question, n_right.to_i) 182 printf(<<-EOF, n_question, n_right.to_i)
183 <div class="box5">
170 <p>おめでとう!</p> 184 <p>おめでとう!</p>
171 <p>全%d問中 %d問正解しました。</p> 185 <p>全%d問中 <a class="name">%d問</a>正解しました。</p></div>
172 EOF 186 EOF
173 if n_question == n_right.to_i 187 if n_question == n_right.to_i
174 puts("<p>全問クリア達成!") 188 puts("<p>全問クリア達成!")
175 end 189 end
176 end 190 end
177 else 191 else
178 printf("<h1>第%d問</h1>\n", form_qn) 192 printf("<h1 class=\"eleg\">第%d問</h1>\n", form_qn)
179 if /\d/ =~ number 193 if /\d/ =~ number
180 puts("<h2>残念! もう一度!</h2>") 194 puts("<h2 class=\"underline\">はずれ!もう一度!</h2>")
181 end 195 end
182 printf("<p>") 196 printf("<p>")
183 imgsrc(image) 197 imgsrc(image)
184 printf("</p>") 198 printf("</p>")
185 n=0 199 n=0

yatex.org