view mackey/academy/ans.rb @ 3221:0fe4cf973d32

higawari²èÁü¹¹¿·
author GOTO Sakuya <c113061@e.koeki-u.ac.jp>
date Tue, 19 Jan 2016 18:03:46 +0900
parents 2ee6e6efc0dd
children
line wrap: on
line source

#!/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)

yatex.org