Mercurial > hgrepos > hgweb.cgi > skipweb
view opencampus2015/prof.rb @ 825:18b0b8ba7cc9
ARGV
author | ARAKI Tsuyohito <c113007@e.koeki-u.ac.jp> |
---|---|
date | Sat, 25 Jul 2015 10:54:36 +0900 |
parents | 0a606921d6cf |
children | 726a89c6df50 |
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>ほげほげ</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 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 == "please skip here" 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?以降の文字(特定の乱数)を取得して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 = "" 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/ship.png" m2 = "つやひめ" mimg2 = "./img/tsuya.png" elsif cal == "girl" image = "./img/girl#{lv}.png" alt = "girl#{lv}" m1 = "さくらんぼ" mimg1 = "./img/room.png" m2 = "つやひめ" mimg2 = "./img/tsuya.png" elsif cal == "snake" image = "./img/snake#{lv}.png" alt = "snake#{lv}" m1 = "かえる" mimg1 = "./img/exp.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" 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 = "" if ARGV[0] == "commandbomd" comm += '<form method="POST" action="prof.rb?commandbomd"> <input type="text" name="bom" size="8"> <input type="submit"> </form>' elsif lv == 5 comm += '<form method="POST" action="prof.rb"> <input type="text" name="bom" size="8"> <input type="submit"> </form>' end if bom == "inu1" image = "./img/inu1.png" elsif bom == "inu2" image = "./img/inu2.png" elsif bom == "inu3" image = "./img/inu3.png" elsif bom == "inu4" image = "./img/inu4.png" elsif bom == "inu5" image = "./img/inu5.png" elsif bom == "sisip1" image = "./img/sisip1.png" elsif bom == "sisip2" image = "./img/sisip2.png" elsif bom == "sisip3" image = "./img/sisip3.png" elsif bom == "sisip4" image = "./img/sisip4.png" elsif bom == "sisip5" image = "./img/sisip5.png" elsif bom == "kamon1" image = "./img/kamon1.png" elsif bom == "kamon2" image = "./img/kamon2.png" elsif bom == "kamon3" image = "./img/kamon3.png" elsif bom == "kamon4" image = "./img/kamon4.png" elsif bom == "kamon5" image = "./img/kamon5.png" elsif bom == "boy1" image = "./img/boy1.png" elsif bom == "boy2" image = "./img/boy2.png" elsif bom == "boy3" image = "./img/boy3.png" elsif bom == "boy4" image = "./img/boy4.png" elsif bom == "boy5" image = "./img/boy5.png" elsif bom == "girl1" image = "./img/girl1.png" elsif bom == "girl2" image = "./img/girl2.png" elsif bom == "girl3" image = "./img/girl3.png" elsif bom == "girl4" image = "./img/girl4.png" elsif bom == "girl5" image = "./img/girl5.png" end if bom == "" else image = "./img/#{bom}.png" end 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">おかし:3pt</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_