Mercurial > hgrepos > hgweb.cgi > skipweb
view mackey/academy/battle.rb~ @ 2849:a222fe462b1b
merge
author | ARAKI Tsuyohito <c113007@e.koeki-u.ac.jp> |
---|---|
date | Tue, 01 Dec 2015 19:07:02 +0900 |
parents | 2ee6e6efc0dd |
children |
line wrap: on
line source
#!/usr/bin/ruby # coding: euc-jp require 'rubygems' require 'pg' require 'cgi' c = CGI.new(:accept_charset => "utf-8") print"ontent-type: text/html; charset=utf-8\n\n" tai = c["hp"] dhp = c["defohp"] tekihp = c["thp"] ct = c["count"] nn = c["namae"] lvl = c["level"] idnum = c["id"] ep = c["exp"] cou = ct quest = [] wordone = [] wordtwo = [] wordthi = [] wordfou = [] subject = [] x = 0 begin conn = PGconn.connect('127.0.0.1','','','','semi','masahiro','l3nl3q1u') q = "select question, word1, word2, word3, word4 from quiz" res = conn.exec(q) res.each do |row| quest << row["question"].to_s wordone << row["word1"].to_s wordtwo << row["word2"].to_s wordthi << row["word3"].to_s wordfou << row["word4"].to_s x += 1 end end srand number = rand(x) check = rand(4) printf("<html> <head> <title>きみのこうげきだよ!</title> <link rel=\"stylesheet\" href=\"style.css\" type=\"text/css\"> </head> <body> <h1>きみのこうげきだよ</h1> <p>No.#{number}</p> <div class=\"center01\"> <div> <h1>てき HP #{tekihp} / #{tekihp} <img border=\"1\" src=\"battle.jpg\" width=\"480\" height=\"320\" alt=\"背景\" title=\"背景\"> <h1>体力: #{tai} / #{dhp} <h2>問題</h2> <p>%s</p> <form method=\"POST\" action=\"battle2.rb\">\n", quest[number]) if check == 0 print"<button class=\"css3button\" type=\"submit\" name=\"answer\" value=\"#{wordone[number]}\">#{wordone[number]}</button> <button class=\"css3button\" type=\"submit\" name=\"answer\" value=\"#{wordtwo[number]}\">#{wordtwo[number]}</button> <button class=\"css3button\" type=\"submit\" name=\"answer\" value=\"#{wordthi[number]}\">#{wordthi[number]}<br></button> <button class=\"css3button\" type=\"submit\" name=\"answer\" value=\"#{wordfou[number]}\">#{wordfou[number]}<br></bu\ tton>\n" elsif check == 1 print"<button class=\"css3button\" type=\"submit\" name=\"answer\" value=\"#{wordtwo[number]}\">#{wordtwo[number]}</button> <button class=\"css3button\" type=\"submit\" name=\"answer\" value=\"#{wordone[number]}\">#{wordone[number]}</button> <button class=\"css3button\" type=\"submit\" name=\"answer\" value=\"#{wordthi[number]}\">#{wordthi[number]}<br></button> <button class=\"css3button\" type=\"submit\" name=\"answer\" value=\"#{wordfou[number]}\">#{wordfou[number]}<br></button>\n" elsif check == 2 print"<button class=\"css3button\" type=\"submit\" name=\"answer\" value=\"#{wordthi[number]}\">#{wordthi[number]}</button> <button class=\"css3button\" type=\"submit\" name=\"answer\" value=\"#{wordone[number]}\">#{wordone[number]}</button> <button class=\"css3button\" type=\"submit\" name=\"answer\" value=\"#{wordtwo[number]}\">#{wordtwo[number]}</button> <button class=\"css3button\" type=\"submit\" name=\"answer\" value=\"#{wordfou[number]}\">#{wordfou[number]}</button>\n" elsif check == 3 print"<button class=\"css3button\" type=\"submit\" name=\"answer\" value=\"#{wordfou[number]}\">#{wordfou[number]}</button> <button class=\"css3button\" type=\"submit\" name=\"answer\" value=\"#{wordone[number]}\">#{wordone[number]}</button> <button class=\"css3button\" type=\"submit\" name=\"answer\" value=\"#{wordtwo[number]}\">#{wordtwo[number]}</button> <button class=\"css3button\" type=\"submit\" name=\"answer\" value=\"#{wordthi[number]}\">#{wordthi[number]}</button>\n" end printf("<input type=\"hidden\" name=\"dat\" value=\"%s\"> <input type=\"hidden\" name=\"num\" value=\"#{number}\"> <input type=\"hidden\" name=\"hp\" value=\"#{tai}\"> <input type=\"hidden\" name=\"thp\" value=\"#{tekihp}\"> <input type=\"hidden\" name=\"defohp\" value=\"#{dhp}\"> <input type=\"hidden\" name=\"defothp\" value=\"#{tekihp}\"> <input type=\"hidden\" name=\"namae\" value=\"#{nn}\"> <input type=\"hidden\" name=\"level\" value=\"#{lvl}\"> <input type=\"hidden\" name=\"exp\" value=\"#{ep}\"> <input type=\"hidden\" name=\"id\" value=\"#{idnum}\"> <input type=\"hidden\" name=\"count\" value=\"#{cou}\"> </form> </div> </div> </body> </html>\n", wordone[number])