Newer
Older
skip-web / staff / mackey / academy / ans.rb
#!/usr/bin/ruby
# coding: utf-8

require 'cgi'
c = CGI.new(:accept_charset => "utf-8")
print "Content-type: text/html; charset=utf-8\n\n"

check = c["answer"]
quiznum = c["dat"]

srand
number=rand(1060)
num = 0
damage = ""
quiz = ""
ansone = ""
anstwo = ""
ansthi = ""
ansfou = ""
anstrue = ""
open("data.txt", "r:utf-8") do |list|
  while line = list.gets
    if /(\d+),(\S+),(\S+),(\S+),(\S+),(\S+),(\d)/ =~ line
      if quiznum.to_i == $1.to_i
        if check.to_i == $7.to_i
          damage = "攻撃成功!"
          else 
          damage = "攻撃失敗!"
        end
      end
      if number.to_i == $1.to_i
        num = $1.to_i
        quiz = $2.to_s
        ansone = $3.to_s
        anstwo = $4.to_s
        ansthi = $5.to_s
        ansfou = $6.to_s
        anstrue = $7.to_i
      end
    end
  end
end



printf("<html>
<head>
<title>きみのこうげきだよ!</title>
<link rel=\"stylesheet\" href=\"style.css\" type=\"text/css\">
</head>
<body>
<h1>きみのこうげきだよ</h1>
<h2>#{damage}</h2>
<p>No.#{number}</p>
<div class=\"main\">
<div>
<img border=\"1\" src=\"maou.png\" width=\"480\" height=\"320\"                         
alt=\"まおうのがぞうっぽいよ\" title=\"まおう\">

<h2>問題</h2>
<p>%s</p>

<form method=\"POST\" action=\"ans.rb\">
<button class=\"css3button\" type=\"submit\" name=\"answer\" value=\"1\">%s</bu\
tton>
<button class=\"css3button\" type=\"submit\" name=\"answer\" value=\"2\">%s</bu\
tton>
<button class=\"css3button\" type=\"submit\" name=\"answer\" value=\"3\">%s<br></bu\
tton>
<button class=\"css3button\" type=\"submit\" name=\"answer\" value=\"4\">%s<br></bu\
tton>
<input type=\"hidden\" name=\"dat\" value=\"%d\">
</form>
</div>
</div>
</body>
</html>", quiz, ansone, anstwo, ansthi, ansfou, num)