view oasis2015/prof.rb @ 2506:0376af46d1c2

placeholder
author ARAKI Tsuyohito <c113007@e.koeki-u.ac.jp>
date Fri, 10 Jul 2015 17:22:23 +0900
parents 3b4765a58a7d
children 4f7639e3fa22
line wrap: on
line source

#!/usr/bin/env ruby22
# -*- 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 = ?"
data2 = "select * from test where id = ?"
#idが?(後で代入)のデータをtest票から探す。という命令をdataにしくむ。全てがほしい場合は「*」。「*」を「name」に変えると該当データのnameだけとりだす。
cook = db.execute(data, person)               #dataに仕組んでいた命令を、personを代入しつつ実行。
cook2 = db.execute(data2, 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 = ?"
ins4 = 'insert into time values(?, 61, "n")'

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秒以内なら追加ポイント####
kpt = 0
bom = c["bom"]                        ####<form ~~ name="bom">より

begin
  jikan2 = db.execute(jikan1, "j")
  now1 = jikan2[0][1]
rescue
  db.execute(ins4, "a")
  db.execute(ins4, "b")
  db.execute(ins4, "c")
  db.execute(ins4, "d")
  db.execute(ins4, "e")
  db.execute(ins4, "f")
  db.execute(ins4, "g")
  db.execute(ins4, "h")
  db.execute(ins4, "i")
  db.execute(ins4, "j")
end

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 < 2                 ####2秒以内なら~
    pt += 50
    kpt += 50
  end
  pt += 1
  kpt += 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
    kpt += 2
  end
  pt += 10
  kpt += 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
    kpt += 2
  end
  pt += 10
  kpt += 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
    kpt += 2
  end
  pt += 10
  kpt += 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
    kpt += 2
  end
  pt += 10
  kpt += 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
    kpt += 2
  end
  pt += 10
  kpt += 10
end


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

kkget = ""
if kpt > 0
  kkget = "#{kpt}ポイントゲット!!"
end



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

if cal == "inu"
  image = "./img/inu#{lv}.png"
  alt = "inu#{lv}"
  m1 = "ドッグフード"
  mimg1 = "./img/food.png"
  m2 = "にく"
  mimg2 = "./img/niku.png"
elsif cal == "sisip"
  image = "./img/sisip#{lv}.png"
  alt = "sisip#{lv}"
  m1 = "ぱん"
  mimg1 = "./img/pan.png"
  m2 = "きゃべつ"
  mimg2 = "./img/kyabetsu.png"
elsif cal == "kamon"
  image = "./img/kamon#{lv}.png"
  alt = "kamon#{lv}"
  m1 = "かい"
  mimg1 = "./img/kai.png"
  m2 = "とびうお"
  mimg2 = "./img/fish.png"
elsif cal == "boy"
  image = "./img/boy#{lv}.png"
  alt = "boy#{lv}"
  m1 = "つやひめ"
  mimg1 = "./img/tsuya.png"
  m2 = "ふね"
  mimg2 = "./img/ship.png"
elsif cal == "girl"
  image = "./img/girl#{lv}.png"
  alt = "girl#{lv}"
  m1 = "へや"
  mimg1 = "./img/room.png"
  m2 = "れんしゅう"
  mimg2 = "./img/exp.png"
else
  image = "./img/snail.png"
  m1 = "たまごのから"
  mimg1 = "./img/tamago.png"
  m2 = "きゃべつ"
  mimg2 = "./img/cabage.png"
end



if lv == 1
color = "black"
elsif lv == 2
color = "navy"
elsif lv == 3
color = "green"
elsif lv == 4
color = "red"
elsif lv == 5
color = "yellow"
else
color = "pink"
end
#expが10あがる毎にlvが1あがる。
#expの1の位*10で、次のレベルアップに必要な経験値の割合が出る。
#(exp=12の場合、2*10=『20%』、次のレベルアップまであと80%が必要、と分かる。)
#(exp=35の場合、5*10=『50%』、次のレベルアップまであと50%が必要、と分かる。)
gage = 0
exp2 = exp
if lv < 5
  while exp2 >= 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, color, kkget, image, alt, name, person, cal, lv, pt, m1, mimg1, m2, mimg2)


<!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;
}
div.cal div{float:left; border:solid %s;}

-->
</style>
<link rel="stylesheet" type="text/css" href="profeel.css">
</head>

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

<div class="cal">
<div>
<img src=%s alt=%s width="172" height="172">
</div>
<table class="state"><tr><td>name</td><td>:%s</td></tr>
<tr><td>id</td><td>:%04d</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">%s:1pt<img src=%s width="16" height="16"><br>
<input type="radio" name="gohan" value="g2">%s:3pt<img src=%s width="16" height="16"><br><br>
<input type="text" name="gohan" placeholder="ひみつ の こたえ を いれてね!"><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