Mercurial > hgrepos > hgweb.cgi > skipweb
view opencampus2015/prof.rb @ 2596:11e291bdd90a
hoge
author | ARAKI Tsuyohito <c113007@e.koeki-u.ac.jp> |
---|---|
date | Thu, 22 Oct 2015 18:40:12 +0900 |
parents | b852990ac567 |
children | 5a7fdc570aa9 |
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")' printf("Content-type: text/html; charset=UTF-8\n\n") begin 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] rescue printf(<<_EOS_) <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html><head> <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"> <meta name="format-detection" content="telephone=no"> <link media="only screen and (max-device-width:480px)" href="smart.css" type="text/css" rel="stylesheet" /> <link media="screen and (min-device-width:481px)" href="profeel.css" type="text/css" rel="stylesheet" /> <link rel="shortcut icon" href="./img/cabage.png"/> <title>Miyazac Quest</title> <style type="text/css"> <!-- --> </style> </head> <body> <header></header> <h1>データがみつかりません!</h1><h2>クッキーを消してやりなおしてください!</h2> <div class="f1"><a href="index.html"><div class="lets"><span>とうろく画面へ!</span></div></a></div> <div class="f1"><a href="cookie.rb"><div class="lets"><span>くっきーをけす!</span></div></a></div> <address>skip@xxxx.co.jp</address> <footer></footer> </body> </html> _EOS_ exit(0) ##プログラム終了! これがないと以降のプログラムが動いてしまう。 end 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(4567845678) x = rand(10000000) srand(x) qrnumber = Hash.new("n") qrarr = ["a", "b", "c", "d", "e"] qrarr.length.times do |i| qrnumber[rand(100000000)] = qrarr[i] end return qrnumber end ##################ptを獲得した際の反応。#################### #########前の人が書き込んだ時間と比べて60秒以内なら追加ポイント#### kpt = 0 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 qrAC = qrc ###生成したハッシュには、"乱数"=>"記号"が入っている getAC = ARGV[0].to_i ###URL?以降の文字(特定の乱数)を取得してgetACに代入 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 < 40 pt += 5 kpt += 5 end pt += 7 kpt += 7 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 < 20 pt += 2 kpt += 2 end pt += 12 kpt += 12 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 < 25 pt += 10 kpt += 10 end pt += 3 kpt += 3 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 += 15 kpt += 15 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 < 50 pt += 4 kpt += 4 end pt += 10 kpt += 10 end db.execute(bomd, pt, person) db.execute(queupd, q1, q2, q3, q4, q5, person) kkget = "" ########################~ここまでpt処理~################### ####################################################### m1 = "馬小屋" mimg1 = "./img/food.png" m2 = "客室" mimg2 = "./img/niku.png" image = "./img/#{cal}#{lv}.png" alt = "#{cal}.png" 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" image = "./img/snail.png" alt = "snails_bug" end #expが10あがる毎にlvが1あがる。 #expの1の位*10で、次のレベルアップに必要な経験値の割合が出る。 #(exp=12の場合、2*10=『20%』、次のレベルアップまであと80%が必要、と分かる。) #(exp=35の場合、5*10=『50%』、次のレベルアップまであと50%が必要、と分かる。) gage = 0 exp2 = exp esa = "<br><br><br>" if lv < 5 while exp2 >= 10 exp2 -= 10 end gage = 100-exp2*10 esa ='<input type="reset" value="とりけし"> <input type="submit" value="こうかんする!"><br> <input type="text" name="gohan" placeholder="ひみつ の こたえ を いれてね!">:0pt' end ######################## ###lv==5のとき画像を変える### comm = "" kakunin = "" ######################### ######################### ###################################--HTML--################## ###################################--------################## printf(<<_EOS_, per, gage, per, per, per, color, kakunin, kkget, image, alt, name, person, cal, lv, comm, pt, m1, mimg1, m2, mimg2, esa) <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"> <meta name="format-detection" content="telephone=no"> <link media="only screen and (max-device-width:480px)" href="smart.css" type="text/css" rel="stylesheet" /> <link media="screen and (min-device-width:481px)" href="profeel.css" type="text/css" rel="stylesheet" /> <link rel="shortcut icon" href="./img/cabage.png"/> <title>ほげほげ!</title> <style type="text/css"> <!-- p.gage{ background:#adf; margin-left:0%s; margin-right:%d%s; text-align:left; border-radius: 10ex; } div.gage{ background:#ddf; margin-left:20%s; margin-right:20%s; border-radius: 10ex; } div.cal div{float:left; border:solid %s;} --> </style> </head> <body> <header><p>%s</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>cara</td><td>:%s</td></tr> <tr><td>lv.</td><td>%d</td></tr> </table> </div> <div class="gage"> <p class="gage">exp</p> </div> %s <p>こうえきポイント:%dp</p> <table><tr><td> <form method="POST" action="gohan.rb"> <label><input type="checkbox" name="hdn">ごはんをあげる!<div><br> <label><input type="radio" name="gohan" value="g1">%s:2pt<img src=%s width="16" height="16"></label><br> <label><input type="radio" name="gohan" value="g2">%s:5pt<img src=%s width="16" height="16"></label><br> %s </div></label></form> </td><td> <form method="POST" action="gets.rb"> <label><input type="checkbox" name="hdn">しょうひんと交換!<div><br> <label><input type="radio" name="sho" value="s1">おかし:?pt</label><br> <input type="reset" value="とりけし"> <input type="submit" value="こうかんする!"></div></label><br> </form> </td></tr></table> <address>skip@xxxx.co.jp</address> <footer></footer> </body> </html> _EOS_