#!/usr/bin/env ruby
# coding: euc-jp
require 'rubygems'
require 'pg'
require 'cgi'
c = CGI.new(:accept_charset => "euc-jp")
print"ontent-type: text/html; charset=euc-jp\n\n"
kaito = c["answer"]
ans = c["dat"]
ber = c["num"]
tai = c["hp"]
tekihp = c["thp"]
dthp = c["defothp"]
dhp = c["defohp"]
nn = c["namae"]
lvl = c["level"]
ep = c["exp"]
idnum = c["id"]
sum = tai.to_i
tsum = tekihp.to_i
nb = ber.to_i
cu = c["count"]
cou = cu.to_i
ct = cou + 1
quest = []
wordone = []
wordtwo = []
wordthi = []
wordfou = []
subject = []
x = 0
y = 0
begin
conn = PGconn.connect('broy.e.koeki-u.ac.jp','','','','c112085','mackeyacademy','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
if ans.to_s == kaito.to_s
srand
attack = rand(90) + 10
tsum -= attack
else
srand
tekiat = rand(20) + 5
sum -= tekiat
end
if tsum >= 0 && sum >= 0
srand
number = rand(x)
srand
check = rand(4)
print"<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 #{tsum} / #{dthp}</h1>
<img border=\"1\" src=\""
if ans.to_s == kaito.to_s
print"atack.gif"
else
print"damage.gif"
end
print"\" width=\"480\" height=\"320\" alt=\"背景\" title=\"背景\">\n"
if ans.to_s == kaito.to_s
print"<h1>攻撃成功!</h1>\n"
else
print"<h1>攻撃失敗</h1>\n"
end
printf("<h1>体力: #{sum} / #{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=\"#{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=\"#{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=\"#{wordthi[number]}\">#{wordthi[number]}</button>
<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>\n"
end
printf("<input type=\"hidden\" name=\"dat\" value=\"%s\">
<input type=\"hidden\" name=\"num\" value=\"#{number}\">
<input type=\"hidden\" name=\"hp\" value=\"#{sum}\">
<input type=\"hidden\" name=\"thp\" value=\"#{tsum}\">
<input type=\"hidden\" name=\"count\" value=\"#{cou}\">
<input type=\"hidden\" name=\"defohp\" value=\"#{dhp}\">
<input type=\"hidden\" name=\"defothp\" value=\"#{dthp}\">
<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}\">
</form>
</div>
</body>
</html>\n", wordone[number])
elsif tsum <= 0 && sum > 0
if ct == 4
print"<html>
<head>
<title>ドラゴンをたおした!</title>
<link rel=\"stylesheet\" href=\"style.css\" type=\"text/css\">
</head>
<body>
<h1>ドラゴンをたおした!</h1>
<div class=\"center01\">
<div>
<img border=\"1\" src=\"forest.jpg\" width=\"480\" height=\"320\" alt=\"背景\" title=\"背景\">
<h1>攻撃成功!</h1>
<h1>体力: #{sum} / #{dhp}</h1>
<h2>探索完了!</h2>"
#<form method=\"POST\" action=\"boss.rb\">
#<button class=\"css3button\" type=\"submit\" name=\"Battle\" value=\"1\">Start</button>
#<input type=\"hidden\" name=\"hp\" value=\"#{sum}\"><input type=\"hidden\" name=\"thp\" value=\"500\">
#<input type=\"hidden\" name=\"count\" value=\"#{ct}\">
#</form>
print"</div>
</body>
</html>\n"
else
print"<html>
<head>
<title>ドラゴンをたおした!</title> <link rel=\"stylesheet\" href=\"style.css\" type=\"text/css\"> </head> <body> <h1>ドラゴンをたおした!</h1>
<div class=\"center01\">
<div>
<img border=\"1\" src=\"forest.jpg\" width=\"480\" height=\"320\" alt=\"背景\" title=\"背景\">
<h1>攻撃成功!</h1>
<h1>体力: #{sum} / #{dhp}</h1>
<h2>探索を続けよう!</h2>
<form method=\"POST\" action=\"battle.rb\">
<button class=\"css3button\" type=\"submit\" name=\"Battle\" value=\"1\">Start</button>
<input type=\"hidden\" name=\"hp\" value=\"#{sum}\">
<input type=\"hidden\" name=\"thp\" value=\"#{dthp}\">
<input type=\"hidden\" name=\"count\" value=\"#{ct}\">
<input type=\"hidden\" name=\"defohp\" value=\"#{dhp}\">
<input type=\"hidden\" name=\"defothp\" value=\"#{dthp}\">
<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}\">
</form>
</div>
</body>
</html>\n"
end
else
print"<html><head><title>負けてしまった</title>
<link rel=\"stylesheet\" href=\"style.css\" type=\"text/css\">
</head>
<body>
<h1>負けてしまった</h1>
<div class=\"center01\">
<div>
<img border=\"1\" src=\"forest.jpg\" width=\"480\" height=\"320\" alt=\"背景\" title=\"背景\">
<h1>体力: 0 / #{dhp}</h1>
<h2>もう一度探索!</h2>
<form method=\"POST\" action=\"login.rb\">
<button class=\"css3button\" type=\"submit\" name=\"Battle\" value=\"1\">Start</button>
<input type=\"hidden\" name=\"id\" value=\"#{idnum}\">
</form>
</a>
</div>
</body>
</html>\n"
end