view oasis2015/prof.rb @ 2441:17da5905bc8e

add image
author ARAKI Tsuyohito <c113007@e.koeki-u.ac.jp>
date Mon, 06 Jul 2015 21:01:34 +0900
parents 94bc6e70229a
children 23fad7087a23
line wrap: on
line source

#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'cgi'
require 'sqlite3'
require 'kconv'
c = CGI.new(:tag_maker => "html5", :accept_charest => "UTF-8")
db = SQLite3::Database.new("sql/main.sq3")

id = c.cookies["id"][0]
person = id.to_i
data = "select * from test where id = ?" #idが?(後で代入)のデータをtest票から探す。という命令をdataにしくむ。全てがほしい場合は「*」。「*」を「name」に変えると該当データのnameだけとりだす。
cook = db.execute(data, person)               #dataに仕組んでいた命令を、personを代入しつつ実行。
jikan1 = "select * from time where cd = ?"
timeupd = "update time set now = ?, id = ? where cd = ?"

que = "select * from toi where id = ?"
queupd = "update toi set q1 = ?, q2 = ?, q3 = ?, q4 = ?, q5 = ? where id = ?"
toi = db.execute(que, person)

bomd = "update test set pt = ? where id = ?"

name = cook[0][1]
cal = cook[0][2]
age = cook[0][3]
sex = cook[0][4]
aria = cook[0][5]
exp = cook[0][6]
pt = cook[0][7]
lv = cook[0][8]


q1 = toi[0][1]
q2 = toi[0][2]
q3 = toi[0][3]
q4 = toi[0][4]
q5 = toi[0][5]

per ="%"

##################--ptを獲得するための乱数生成--#############
##################----#############################

def qrc()
  srand(11223344)
  x = rand(10000000)
  srand(x)
  qrnumber = Hash.new("n")
  qrarr = ["a", "b", "c", "d", "e"]
  qrarr.length.times do |n|
    qrnumber[rand(100000000)] = qrarr[n]
  end
  return qrnumber
end

##################ptを獲得した際の反応。####################
#########前の人が書き込んだ時間と比べて60秒以内なら追加ポイント####

bom = c["bom"]                        ####<form ~~ name="bom">より
if bom == "skip"
jikan2 = db.execute(jikan1, "j")
now1 = jikan2[0][1]
nowper = jikan2[0][2]
now2 = Time.now.to_i
db.execute(timeupd, now2, person, "j")
  if person == nowper
  elsif now1 == nil
  elsif now2-now1 < 3                 ####3秒以内なら~
    pt += 20
  end
  pt += 1
#  db.execute(bomd, pt, person)
end

qrAC = qrc            ###生成したハッシュには、"乱数"=>"記号"が入っている
getAC = ARGV[0].to_i  ###URL?以降の文字(特定の乱数)を取得
qr = qrAC[getAC]      ###特定の"乱数"が一致すると、"乱数"=>"記号"がqrに正しく入力される。
if qr =="a" && q1 == 0
q1 += 1
jikan2 = db.execute(jikan1, "a")
now1 = jikan2[0][1]
nowper = jikan2[0][2]
now2 = Time.now.to_i
db.execute(timeupd, now2, person, "a")
  if person == nowper
  elsif now1 == nil
  elsif now2-now1 < 60
    pt += 2
  end
pt += 10
elsif qr == "b" && q2 == 0
q2 += 1
jikan2 = db.execute(jikan1, "b")
now1 = jikan2[0][1]
nowper = jikan2[0][2]
now2 = Time.now.to_i
db.execute(timeupd, now2, person, "b")
  if person == nowper
  elsif now1 == nil
  elsif now2-now1 < 60
    pt += 2
  end
pt += 10
elsif qr == "c" && q3 == 0
q3 += 1
jikan2 = db.execute(jikan1, "c")
now1 = jikan2[0][1]
nowper = jikan2[0][2]
now2 = Time.now.to_i
db.execute(timeupd, now2, person, "c")
  if person == nowper
  elsif now1 == nil
  elsif now2-now1 < 60
    pt += 2
  end
pt += 10
elsif qr == "d" && q4 == 0
q4 += 1
jikan2 = db.execute(jikan1, "d")
now1 = jikan2[0][1]
nowper = jikan2[0][2]
now2 = Time.now.to_i
db.execute(timeupd, now2, person, "d")
  if person == nowper
  elsif now1 == nil
  elsif now2-now1 < 60
    pt += 2
  end
pt += 10
elsif qr == "e" && q5 == 0
q5 += 1
jikan2 = db.execute(jikan1, "e")
now1 = jikan2[0][1]
nowper = jikan2[0][2]
now2 = Time.now.to_i
db.execute(timeupd, now2, person, "e")
  if person == nowper
  elsif now1 == nil
  elsif now2-now1 < 60
    pt += 2
  end
pt += 10
end

db.execute(bomd, pt, person)
db.execute(queupd, q1, q2, q3, q4, q5, person)





########################~ここまでpt処理~###################
#######################################################

if cal == "inu"
  image = "./img/inu#{lv}.png"
  alt = "inu#{lv}"
elsif cal == "sisip"
  image = "./img/sisip#{lv}.png"
  alt = "sisip#{lv}"
elsif cal == "kamon"
  image = "./img/kamon#{lv}.png"
  alt = "kamon#{lv}"
elsif cal == "boy"
  image = "./img/boy#{lv}.png"
  alt = "boy#{lv}"
elsif cal == "girl"
  image = "./img/girl#{lv}.png"
  alt = "girl#{lv}"
else
  image = "./img/snail.png"
end





#expが10あがる毎にlvが1あがる。
#expの1の位*10で、次のレベルアップに必要な経験値の割合が出る。
#(exp=12の場合、2*10=『20%』、次のレベルアップまであと80%が必要、と分かる。)
#(exp=35の場合、5*10=『50%』、次のレベルアップまであと50%が必要、と分かる。)
gage = 100
exp2 = exp
if lv < 5
while exp > 10
exp2 -= 10
end
gage = 100-exp2*10
end



###################################--HTML--##################
###################################--------##################

#以下のprintfについて
#pre*4はstyleの部分、<h2>{margin(本来OS_,per,gage,per,per,per,name...)
printf(<<_EOS_, per, gage, per, per, per, image, alt, name, cal, lv, pt)


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
	"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>さかたっち</title>
<style type="text/css">
<!--
p.gage{
background:#adf;
margin-left:0%s;
margin-right:%d%s;
text-align:left;
}
div.gage{
background:#ddf;
margin-left:20%s;
margin-right:20%s;
}
-->
</style>
<link rel="stylesheet" type="text/css" href="profeel.css">
</head>

<body>
<header><p></p></header>
<h1>さかたっち</h1>


<div class="cal">
<div>
<img src=%s alt=%s width="133" height="133">
</div>
<table class="state"><tr><td>name</td><td>:%s</td></tr>
<tr><td>cal</td><td>:%s</td></tr>
<tr><td>lv.</td><td>%d</td></tr>
</table>
</div>

<div class="gage">
<p class="gage">exp</p>
</div>


<form method="POST" action="prof.rb">
<input type="text" name="bom" size="8">
<input type="submit">
</form>

<p>さかたポイント:%dp</p>
<table><tr><td>
<form method="POST" action="gohan.rb">
<input type="checkbox" name="hdn">ごはん!<span><br>
<input type="radio" name="gohan" value="g1">たまごのから:1pt<img src="./img/tamago.png" width="32" height="32"><br>
<input type="radio" name="gohan" value="g2">きゃべつ:3pt<img src="./img/cabage.png" width="32"height="32"><br><br>
<input type="text" name="gohan" value="ひみつ の こたえ を いれてね!"><br>
<input type="reset" value="とりけし">
<input type="submit" value="こうかんする!"></span>
</form>
</td><td>
<form method="POST" action="gets.rb">
<input type="checkbox" name="hdn">しょうひん!<span><br>
<input type="radio" name="sho" value="s1">おちゃ:3pt<br>
<input type="radio" name="sho" value="s2">おんせんのもと:10pt<br>
<input type="radio" name="sho" value="s3">せんたくせんざい:20pt<br>
<input type="reset" value="とりけし">
<input type="submit" value="こうかんする!"></span><br>
</span>
</form>
</td></tr></table>



<address>skip&#x40;xxxx.co.jp</address>
<footer></footer>
</body>
</html>

_EOS_

#<p><a href="gohan.rb" name="trade1"><img src="./img/gohan.png"
#alt="trade1" width="100"height="60"></a>
#<a href="gets.rb" name="trade2"><img src="./img/gets.png" alt="trade2" width="100" height="60"></a>
#</p>

#<address>skip&#x40;xxxx.co.jp</address>
#</body>
#</html>

#_EOS_

yatex.org