diff --git a/minato2014/Bingo.css b/minato2014/Bingo.css new file mode 100644 index 0000000..b542b67 --- /dev/null +++ b/minato2014/Bingo.css @@ -0,0 +1,92 @@ +html,body { + width: 100%; + height: 100%; +} +div.outflam{ + width: 720px; + height: 1240px; + margin-left: auto; + margin-right: auto; + padding: 0 auto; + } + +div.top{ + background:#1d38ff; + border:thin solid #1155ff; + width: 100%; + height: 25%; + margin-top:0 auto; + margin-bottom:0 auto; + margin-left: auto; + margin-right: auto; + +} + +p {margin-top: 20%; + margin-left: 1%; +} + +/* ------------------------- +div.center-l{ + background:#67bdff; + width: 100px; + height: 100%; + border: thin solid; + float:left; +} +============================ */ + +div.center{ + border: thin solid #fff567; + background:white; + width: 100%; + height: 45%; + margin-left: auto; + margin-right: auto; +} + +table { + border: thin solid #f55555; + margin-left: auto; + margin-right: auto; + margin-top: 1%; + margin-bottom: auto; +} + +/* ------------------------ +div.center-c li{ + width: 150px; + height: 150px; + float: left; + margin: auto; + border: thin solid; + list-style-type: none; +} +=========================== */ + +/* ------------------------- +div.center-r{ + background:#67bdff; + width: 100px; + height: 100%; + border: thin solid; + float: right; +} +============================ */ + +div.bottom{ + background:#1d38ff; + border:thin solid #55678f; + width: 100%; + height: 25%; + margin-left: auto; + margin-right: auto; +} + +div.bottom img { + float: left; +} + +div.charSTATUS { + margin-top: 10%; +} diff --git a/minato2014/Bingo.rb b/minato2014/Bingo.rb new file mode 100755 index 0000000..9aa0b51 --- /dev/null +++ b/minato2014/Bingo.rb @@ -0,0 +1,396 @@ +#!/usr/bin/env ruby +# -*- coding: utf-8 -*- + +require 'sqlite3' +require 'cgi' +require 'date' +require './sub.rb' +require 'net/http' + +c = CGI.new(:tag_maker => "html5", :accept_charest => "UTF-8") +db = SQLite3::Database.new("sql/stamp.sq3") + +#id = c[id] # uidの取得 +id = c.cookies["id"][0].to_i +#id = 1 # test +err = 0 # 不正な動きであれば負の値になる +sidesize = 3 +message = "はりきって行きましょう!" # ビンゴ用テキスト + +print("Content-type: text/html; charset=UTF-8 \n\n") + +#p id +##### CHECKING UID ##### + +sql = "SELECT stamp_status, stamp_img, name, job, sex, exp FROM main WHERE id=?" +user_data = db.execute(sql, id) +if user_data == [] # ログインエラー(-1) + err -= 1 +end + +### LOGIN ERROR HTML ### + +if err == -1 + print' + + + + + +たいとる + +' +print' +

ログインに失敗しました。

+

+アカウント登録ページへ接続中…
+* 3秒経っても移動しない場合はこちらから移動して下さい。 +

+ + +' + exit +end + +###### + +########## + +##### RE-ARRAYING STAMP_STATUS AND STAMP_IMG ##### + +# stamp status +stamp_st = user_data[0][0] +stamp_st = stamp_st.split(//) # 一文字ずつ分けて配列にする +stamp_st = stamp_st.map {|s| s.to_i} # 配列内の文字列を数列になおす + +# stamp img +stamp_img = user_data[0][1] +stamp_img = stamp_img.split(",") # 文字列を","で区切って配列にする + +########## + +##### STAMPPING ##### + +### Making randam number ### + +def taiou(sidesize) + srand(123456789) + stamp = Hash.new("n") + stamp_name = ["kamo", "kite", "mame", "mo2usa", "inuwasi", "hanabu", "be", "UMIMARU", "murakamibot"] + (sidesize**2).times do |n| + stamp[rand(10000000)] = stamp_name[n] + end + stamp +end + +###### + +##### Checking bingo method ##### + +def bingocheck(start, sidesize, stepon, stamp, decision, bingo) + nbox = [] + setbox = Hash.new + if sidesize == stepon + x = sidesize + else + x = 1 + end + x.times do |m| + start.step(sidesize*sidesize - 1, stepon) do |n| + nbox << n + m + if nbox.length == sidesize + dbox = Array.new(0) # next bingo or reach numbers(bingoed -> nothing) + for i in nbox + if stamp[i] == 0 + dbox << i + end + end + # sidesizeにdecisionの値を加えることで、ビンゴ、次ビンゴ、リーチをそれぞれdecisionに0,1,2を加えることで表現。 + if dbox.length == decision + setbox[dbox] = nbox + bingo << setbox + setbox = Hash.new + nbox = [] + else + nbox = [] + end + end + end + end +end +# bingo[{[ビンゴまたはリーチに必要な番号] => [ビンゴまたはリーチのラインを形成する番号]}] +########## + +bingo = # 現在のビンゴ数 + +### Checking Access Cord(AC) ### + +getAC = ARGV[0].to_i # URL?以降の引数を取得 +rightAC = taiou(sidesize) # taiouで生成したACのハッシュ +#p rightAC +rightAC = rightAC[getAC] # ACが正しければスタンプ名が入り、異なる場合はn + +##### ACCESS LOG ##### +t = Time.now +time = (t.hour * 3600) + (t.min * 60) + t.sec + +## Checking sql_master table. If sqlite_master don't have tablename, it create. + +sql_master = "SELECT name FROM sqlite_master WHERE name='logs';" +check_master = db.execute(sql_master) +sql_logs = 'CREATE TABLE logs( +id INTEGER PRIMARY KEY AUTOINCREMENT, +uid INTEGER, +ac TEXT, +time INTEGER); +' +if check_master == [] + db.execute(sql_logs) +end + +########## + +begin + get_log = 'SELECT ac, time FROM logs WHERE uid=(SELECT MAX(id) FROM logs WHERE uid=?);' # ユーザーの最新のログ情報を取得 + log_check = db.execute(get_log, id) +rescue + print'GETTING LOG ERROR!' +end +begin + log = 'INSERT INTO logs(uid, ac, time) VALUES(?, ?, ?)' + db.execute(log, id, rightAC, time) +rescue + print'INSERT LOG ERROR!' +end +# /* memo: 再度同じようなシステムを作る際はスタンプ用のテーブルがほしい。 */ # + +########## + +### ビンゴしたラインを判定(decision = 0) ### +bingo = [] +# 横 +bingocheck(0, sidesize, 1, stamp_st, 0, bingo) +# 縦 +bingocheck(0, sidesize, sidesize, stamp_st, 0, bingo) +# 左斜め +bingocheck(0, sidesize, sidesize+1, stamp_st, 0, bingo) +# 右斜め +bingocheck(sidesize-1, sidesize, sidesize-1, stamp_st, 0, bingo) +####### + +bingo = bingo.length # ビンゴの数 + + +if rightAC != "n" # rightACが正しければ + + ### Update Stamp_status And Stamp_img ### + + # Replacing Image # + + index_st = [] + stamp_st.length.times { |c| + if stamp_st[c] == 0 + index_st << c + end + } + + ### リーチ(decision = 1)# [{[ビンゴの番号] => [リーチを構成する数]}] + reach = [] + # 横 + bingocheck(0, sidesize, 1, stamp_st, 1, reach) + # 縦 + bingocheck(0, sidesize, sidesize, stamp_st, 1, reach) + # 左斜め + bingocheck(0, sidesize, sidesize+1, stamp_st, 1, reach) + # 右斜め + bingocheck(sidesize-1, sidesize, sidesize-1, stamp_st, 1, reach) + ####### + + begin + reach = reach[0].flatten(2)[0] # ビンゴの番号のみ抽出 + rescue + reach = [] + end + + # Updating stamp_st # + if stamp_img.include?(rightAC) == true # 既に同名のスタンプが入っていたら + if stamp_st[stamp_img.index(rightAC)] < 9 + stamp_st[stamp_img.index(rightAC)] += 1 # 対応するスタンプの位置に1足す + message = "スタンプカウントが「1」増えました!(スタンプカウントは「9」が上限です)" + else + message="スタンプカウントMAX!!(※これ以上このスタンプのカウントは増えません)" + end + else + if reach != [] && bingo == 0 # はじめのビンゴは必ず3回で完成 + stamp_st[reach] # ビンゴになる数字を代入 + stamp_img[reach] = rightAC + else + randam_number = index_st[rand(index_st.length)] # スタンプの入っていない個所のなかからランダムにひとつ選ぶ + stamp_st[randam_number] += 1 # 選ばれた個所に1足す + stamp_img[randam_number] = rightAC # stamp_stと同じ個所にstamp_imgにスタンプの名前を代入 + message = "新しいスタンプをGETしました!" # Top message + end + end + ## + + ## + + ### ビンゴしたラインを判定(decision = 0) ### + bingo = [] + # 横 + bingocheck(0, sidesize, 1, stamp_st, 0, bingo) + # 縦 + bingocheck(0, sidesize, sidesize, stamp_st, 0, bingo) + # 左斜め + bingocheck(0, sidesize, sidesize+1, stamp_st, 0, bingo) + # 右斜め + bingocheck(sidesize-1, sidesize, sidesize-1, stamp_st, 0, bingo) + ####### + + bingo = bingo.length # ビンゴの数 + + # Convert to string # + + stamp_st_string = stamp_st.join + stamp_img_string = stamp_img.join(",") + + ## + + sql_update = "UPDATE main SET stamp_status=?, stamp_img=? WHERE id=?;" + db.execute(sql_update, stamp_st_string, stamp_img_string, id) +end + +###### + +########## + +##### HTML ##### +print' + + + +たいとる + + + +' +### TOP ### + +sql_rank = 'select rank from main where id=?;' +rank = db.execute(sql_rank, id).flatten(2)[0].to_i + +print' +
+' +if rank > 0 + print'
' +else + print'
' +end +# - ビンゴステータス処理 - # + +if rank > 0 + printf("

おめでとうございます!!
☆ %d等 ☆が当選しました!!

", rank) + # print'

抽選は終了しましたが、引続きゆる☆スタをお楽しみ下さい!!

' +end +printf("

%s

",message) + +# End of top +print' +
+' +###### + + + +### CENTER ### +print' +
+ +' +for i in 0..2 + print'' + 3.times do |n| + if stamp_st[3*i+n].to_i > 0 + printf("\n", stamp_img[3*i+n], stamp_st[3*i+n]) + else + print"\n" + end + end + print'' +end +# End of center +print' +
\"stamped\"%d
+
+' +###### + +### BOTTOM ### +print' +
+' +# - RPGの表示 - # + +job = user_data[0][3] +sex = user_data[0][4] +exp = user_data[0][5] + +## GETTING EXP SUM ## + +sum_sql = 'SELECT SUM(exp) FROM main ;' +sumexp = db.execute(sum_sql).flatten(2)[0] + +#### + +stamp = stamp_st.inject(:+) # 配列内の値を全て足す + +charST = rpg(job, sex, stamp, bingo, sumexp) # ユーザーのキャラクタステータス + +## GETTING EXP SUM ## + +sum_sql = 'SELECT SUM(exp) FROM main ;' +sumexp = db.execute(sum_sql).flatten(2)[0] + + +#### + +stamp = stamp_st.inject(:+) # 配列内の値を全て足す + +charST = rpg(job, sex, stamp, bingo, sumexp) # ユーザーのキャラクタステータス + +## UPDATE EXP ## + +update_exp = 'UPDATE main SET exp=? WHERE id=?;' +db.execute(update_exp, charST[2], id) + +#### +#p charST[2] +#p sumexp + +printf(" + +
+ +
+
+ID:%04d
+Lv: %d / 全Lv: %d
+当選確率: %3.3f \% +
+", charST[0], id,charST[2],sumexp , charST[1]) + +# End of bottom +print'
' + +# End of outflam +print'
' +###### + +print' + + +' +########## diff --git a/minato2014/account.html b/minato2014/account.html index 92a6544..7ffbf76 100644 --- a/minato2014/account.html +++ b/minato2014/account.html @@ -3,7 +3,6 @@ ゆるスタ登録ページ - diff --git a/minato2014/accountcheck.rb b/minato2014/accountcheck.rb index 9bf83a8..d88a063 100755 --- a/minato2014/accountcheck.rb +++ b/minato2014/accountcheck.rb @@ -3,9 +3,10 @@ require 'sqlite3' require 'cgi' +require './magic.rb' c = CGI.new(:tag_maker => "html5", :accept_charest => "UTF-8") -db = SQLite3::Database.new("sql/stump.sq3") +db = SQLite3::Database.new("sql/stamp.sq3") begin result = db.execute("select * from main;") @@ -21,28 +22,31 @@ sex = c["sex"] aria = c["aria"] +code = magic() id = result.length -printf("%04d",id) +#printf("%04d",id) -mg = 0 +mg = code[id] sql = "insert into main values (?,?,?,?,?,?,?,?,?,?,?);" -db.execute(sql,id,name,aria,sex,age,job,'000010000','n,n,n,n,kamo,n,n,n,n','0','0',mg); #初期値 +db.execute(sql,id,name,sex,age,aria,job,'000010000','n,n,n,n,kamo,n,n,n,n','5','0',mg); #初期値 -printf("Set-Cookie:id=%d; magic=%s\n",id,mg) -print"Content-type: text/html; charset=UTF-8 \n\n" +expires = "Sun, 27 Jul 2016 00:00:00 GMT" -print' +printf("Content-type: text/html; charset=UTF-8 +Set-Cookie:id=%s ;expires=%s +Set-Cookie:magic=%s;expires=%s\n\n",id.to_s,expires,mg.to_s,expires) + +print' Registering Account ' -printf' -

登録が完了しました。下記リンクからスタンプラリーカードを入手して下さい!

-

>> Let\'s go to Stamp Rally <<

+print' +

登録が完了しました。下記リンクからスタンプラリーを開始して下さい!

+

>> Let\'s go to Stamp Rally <<

-

>> アカウント登録画面に戻る <<

+ ' diff --git a/minato2014/magic.rb b/minato2014/magic.rb new file mode 100644 index 0000000..f8e9d8d --- /dev/null +++ b/minato2014/magic.rb @@ -0,0 +1,13 @@ +#!/usr/bin/env ruby +# -*- coding: utf-8 -*- + +def magic() + srand(123456789) + hoge = Array.new + while hoge.length < 100 + hoge << rand(1000000) + hoge.uniq! + end + return hoge +end + diff --git a/minato2014/png/UMIMARU.png b/minato2014/png/UMIMARU.png new file mode 100644 index 0000000..6ac6225 --- /dev/null +++ b/minato2014/png/UMIMARU.png Binary files differ diff --git a/minato2014/png/be.png b/minato2014/png/be.png new file mode 100644 index 0000000..87f9fa0 --- /dev/null +++ b/minato2014/png/be.png Binary files differ diff --git a/minato2014/png/inuwasi.png b/minato2014/png/inuwasi.png new file mode 100644 index 0000000..59c54f9 --- /dev/null +++ b/minato2014/png/inuwasi.png Binary files differ diff --git a/minato2014/png/kamo.png b/minato2014/png/kamo.png new file mode 100644 index 0000000..481a06f --- /dev/null +++ b/minato2014/png/kamo.png Binary files differ diff --git a/minato2014/png/kite.png b/minato2014/png/kite.png new file mode 100644 index 0000000..40c9719 --- /dev/null +++ b/minato2014/png/kite.png Binary files differ diff --git a/minato2014/png/mame.png b/minato2014/png/mame.png new file mode 100644 index 0000000..9ce0212 --- /dev/null +++ b/minato2014/png/mame.png Binary files differ diff --git a/minato2014/png/mo2usa.png b/minato2014/png/mo2usa.png new file mode 100644 index 0000000..5361bc7 --- /dev/null +++ b/minato2014/png/mo2usa.png Binary files differ diff --git a/minato2014/png/murakamibot.png b/minato2014/png/murakamibot.png new file mode 100644 index 0000000..fdbe81b --- /dev/null +++ b/minato2014/png/murakamibot.png Binary files differ diff --git a/minato2014/sub.rb b/minato2014/sub.rb new file mode 100755 index 0000000..5d9426a --- /dev/null +++ b/minato2014/sub.rb @@ -0,0 +1,21 @@ +#!/usr/koeki/bin/ruby +# -*- coding:utf-8 -*- + +def rpg(job,sex,stump,bingo,sumexp) + lv = [1,4,10,16,24,33,49] + exp = stump + (bingo * 5) + iro = 0 + for hoge in lv + if exp > hoge + iro += 1 + end + end + per = (exp.to_f)*100 / (sumexp.to_f+exp.to_f) + png = job + "" + sex + "" + iro.to_s + ret = [png,per,exp] + return ret +end +#job = "sensi" +#sex = "G" +#hoge = rpg(job,sex,5,2,100) #職業,性別,スタンプ数,ビンゴ数,総経験値 +#puts hoge