changeset 3243:4d5b4c0e2a86

oasis2016/ Kaisendon added
author HIROSE Yuuji <yuuji@koeki-u.ac.jp>
date Fri, 15 Jul 2016 12:58:53 +0900
parents 2a1a5a1e157c
children a385c660dcb1
files event/oasis2016/don/.htaccess event/oasis2016/don/ckgame.html event/oasis2016/don/ckgame.rb event/oasis2016/don/ckgame2.rb event/oasis2016/don/dbinit.cgi event/oasis2016/don/kaisendon.jpg event/oasis2016/don/kaisendon2-0.jpg event/oasis2016/don/kaisendon2-1.jpg event/oasis2016/don/kaisendon2-2.jpg event/oasis2016/don/kaisendon2-3.jpg event/oasis2016/don/kaisendon2-4.jpg event/oasis2016/don/kaisendon2-5.jpg event/oasis2016/don/kaisendon2-6.jpg event/oasis2016/don/kaisendon2-7.jpg event/oasis2016/don/kaisendon2-8.jpg event/oasis2016/don/rogo.png event/oasis2016/don/umi.png
diffstat 17 files changed, 253 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/event/oasis2016/don/.htaccess	Fri Jul 15 12:58:53 2016 +0900
@@ -0,0 +1,3 @@
+AddHandler cgi-script   .rb .sh
+Options +ExecCGI
+AddType "text/html; charset=utf-8" .html
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/event/oasis2016/don/ckgame.html	Fri Jul 15 12:58:53 2016 +0900
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html lang="ja">
+<head><title>○○ゲーム</title></head>
+<body>
+<h1>もっけ さんのホーム</h1>
+<p></p>
+<p>当てたキーワード(4/4): 「もっけ」, 「げっぱ」, 「はっこ」, 「やばち」
+</p>
+<form action="?" method="POST">
+<p>キーワードを入れてください: <input name="keyword"><br>
+<input type="submit" value="送信">
+<input type="reset" value="リセット"></p>
+</form></body></html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/event/oasis2016/don/ckgame.rb	Fri Jul 15 12:58:53 2016 +0900
@@ -0,0 +1,144 @@
+#!/usr/bin/env ruby
+# -*- coding: utf-8 -*-
+require 'yaml/store'
+file = "db/point.yaml"
+bingoword = %w(きゅうり えび どんぶり さーもん まぐろ ほし わさび たまご まる) # 正解キーワード9つ
+
+require 'cgi'
+c = CGI.new(:accept_charset => "UTF-8")
+
+# 前回のアクセスで既にcookieが定義されていたら取得
+# ブラウザからのcookieは、c.cookies[変数名][0] で受け取る
+cookie_id=c.cookies["id"][0]
+
+# 前回のアクセスで入力された値を取得
+form_name=c["playname"]        # nameをフォームから取得(もしあれば)
+form_kwd=c["keyword"]          # keywordも取得(もしあれば)
+
+if cookie_id == nil             # (1)もしcookieからのidがなければ新規生成
+  # 新規idは、現在時刻を秒(to_i)にした文字列(to_s)と乱数の組み合わせ
+  newid = Time.now.to_i.to_s + "/" + rand(99999).to_s
+  id=newid                      # 新規idをidとする
+else                            # (2)cookieからのidがあればそれをidとする
+  id=cookie_id
+end
+
+# idをすぐcookieで相手ブラウザに送る
+# 変数の期限を24時間に設定し、expire変数に入れる
+expire = (Time.now+24*3600).gmtime.strftime("%a, %d %b %Y %H:%M:%S GMT")
+printf("Content-type: text/html; charset=UTF-8\n")
+printf("Set-Cookie: id=%s; expires=%s\n\n", id, expire)
+
+db = YAML::Store.new(file)
+db.transaction do
+  info = db["info"] = db.fetch("info", Hash.new)
+  if !info[id]              # もしそのユーザ情報が未登録(空)なら
+    info[id] = Hash.new     # 新規ハッシュを割り当てる
+  end
+  if form_name > ""             # formからの名前設定がもしあれば
+    info[id]["name"] = form_name # それをユーザ情報に記録
+    info[id]["bingo"] = Hash.new # 正解した単語保存用のハッシュも作成
+  end
+  point = 0# 開始直後は0点
+  if !info[id]["name"]      # もしユーザのプレイ名が未設定なら
+    umi = '<img src="umi.png" width="600px" height="450px">'
+    title = "ようこそ!"
+    hello = "まちがいさがしスタート"
+    guide = "あなたのプレイ名を決めます"
+    input = '<input name="playname">'
+  else                          # プレイ名設定済みならキーワード入力
+    title = sprintf("%s さんのホーム", info[id]["name"])
+    setumei = "海鮮丼の絵から間違いを3個見つけよう!"
+    setumei2 = "間違っている絵のパネルは全部で9個あるよ♪"
+    guide = "キーワードを入れてください"
+    input = '<input name="keyword">'
+    seikai = '<img src="kaisendon.jpg" width="450px" height="450px">'
+    # プレイ名設定済みで、さらにキーワードが入力されていたら
+    if form_kwd > ""
+      index = bingoword.index(form_kwd) # 配列から入力単語(form_kwd)を探索
+      hello = sprintf("現在のポイントは %dpt です。", 25*point)
+      if index
+        # 見付かった! その単語をハッシュのキーとして適当に値(true)を入れておく
+        info[id]["bingo"][bingoword[index]] = true
+      end
+    end
+    point = info[id]["bingo"].length # ハッシュの長さで正解数が分かる
+    bingos = info[id]["bingo"].keys.collect do |x|
+      "「" + x + "」"# collectメソッドで 「 」 で括った単語を集めて
+    end.join(", ")# joinメソッドで ,(カンマ) 区切りでつなげる
+    kaisen = ""; kaisen2 = ""; kaisen3 = ""; kaisen4 = ""; kaisen5 = ""; kaisen6 = ""; kaisen7 = ""; kaisen8 = ""; kaisen9 = ""
+    info[id]["bingo"].keys.each do |f|
+      if /きゅうり/ =~ f
+        kaisen = '<img src="kaisendon2-0.jpg" width="150px" height="150px">'
+      elsif /えび/ =~ f
+        kaisen2 = '<img src="kaisendon2-1.jpg" width="150px" height="150px">'
+      elsif /どんぶり/ =~ f
+        kaisen3 = '<img src="kaisendon2-2.jpg" width="150px" height="150px">'
+      elsif /さーもん/ =~ f
+        kaisen4 = '<img src="kaisendon2-3.jpg" width="150px" height="150px">'
+      elsif /まぐろ/ =~ f
+        kaisen5 = '<img src="kaisendon2-4.jpg" width="150px" height="150px">'
+      elsif /ほし/ =~ f
+        kaisen6 = '<img src="kaisendon2-5.jpg" width="150px" height="150px">'
+      elsif /わさび/ =~ f
+        kaisen7 = '<img src="kaisendon2-6.jpg" width="150px" height="150px">'
+      elsif /たまご/ =~ f
+        kaisen8 = '<img src="kaisendon2-7.jpg" width="150px" height="150px">'
+      elsif /まる/ =~ f
+        kaisen9 = '<img src="kaisendon2-8.jpg" width="150px" height="150px">'
+      end
+    end
+  end
+printf(<<-EOF,
+<!DOCTYPE html>
+<html lang="ja">
+<head><title>まちがいみつけでみっちゃ</title>
+<style type="text/css">
+<!--
+div.don {
+    position: relative; width: 450px; height: 450px;
+    border: 1px solid #f9f5a9; margin: 1em auto;
+}
+div.don div {width: 150px; height: 150px; margin: 0px;}
+div.don div:first-child {left: 0px; top: 0px}
+div.don div:nth-child(2) {position: absolute; left: 150px; top: 0px;}
+div.don div:nth-child(3) {position: absolute; left: 300px; top: 0px;}
+div.don div:nth-child(4) {position: absolute; left: 0px; top: 150px;}
+div.don div:nth-child(5) {position: absolute; left: 150px; top: 150px;}
+div.don div:nth-child(6) {position: absolute; left: 300px; top: 150px;}
+div.don div:nth-child(7) {position: absolute; left: 0px; top: 300px;}
+div.don div:nth-child(8) {position: absolute; left: 150px; top: 300px;}
+div.don div:nth-child(9) {position: absolute; left: 300px; top: 300px;}
+body{text-align:center;
+background:#f9f5a9;}
+-->
+</style>
+</head>
+<body>
+<img src="rogo.png" width="900px" height="100px">
+<p>%s</p>
+<h1>%s</h1>
+<h2>%s</h2>
+<h2>%s</h2>
+<p>%s</p>
+<p>開けたパネル(%d/%d): %s</p>
+<form action="?" method="GET">
+<p>%s: %s<br>
+<input type="submit" value="送信">
+<input type="reset" value="リセット"></p>
+</form>
+<p>%s</p>
+<div class="don">
+<div>%s</div>
+<div>%s</div>
+<div>%s</div>
+<div>%s</div>
+<div>%s</div>
+<div>%s</div>
+<div>%s</div>
+<div>%s</div>
+<div>%s</div></div>
+</body></html>
+EOF
+         umi, title, setumei, setumei2, hello, point, bingoword.length, bingos, guide, input, seikai, kaisen, kaisen4, kaisen7, kaisen2, kaisen5, kaisen8, kaisen3, kaisen6, kaisen9,)
+end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/event/oasis2016/don/ckgame2.rb	Fri Jul 15 12:58:53 2016 +0900
@@ -0,0 +1,80 @@
+#!/usr/bin/env ruby
+# -*- coding: utf-8 -*-
+
+bingoword = %w(もっけ やばち はっこ げっぱ) # 正解キーワード4つ
+
+require 'cgi'
+c = CGI.new(:accept_charset => "UTF-8")
+
+# 前回のアクセスで既にcookieが定義されていたら取得
+# ブラウザからのcookieは、c.cookies[変数名][0] で受け取る
+cookie_id=c.cookies["id"][0]
+
+# 前回のアクセスで入力された値を取得
+form_name=c["playname"]        # nameをフォームから取得(もしあれば)
+form_kwd=c["keyword"]          # keywordも取得(もしあれば)
+
+if cookie_id == nil             # (1)もしcookieからのidがなければ新規生成
+  # 新規idは、現在時刻を秒(to_i)にした文字列(to_s)と乱数の組み合わせ
+  newid = Time.now.to_i.to_s + "/" + rand(99999).to_s
+  id=newid                      # 新規idをidとする
+else                            # (2)cookieからのidがあればそれをidとする
+  id=cookie_id
+end
+
+# idをすぐcookieで相手ブラウザに送る
+# 変数の期限を24時間に設定し、expire変数に入れる
+expire = (Time.now+24*3600).gmtime.strftime("%a, %d %b %Y %H:%M:%S GMT")
+printf("Content-type: text/html; charset=UTF-8\n")
+printf("Set-Cookie: id=%s; expires=%s\n\n", id, expire)
+
+db = YAML::Store.new(file)
+db.transaction do
+  info = db["info"] = db.fetch("info", Hash.new)
+  if !info[id]              # もしそのユーザ情報が未登録(空)なら
+    info[id] = Hash.new     # 新規ハッシュを割り当てる
+  end
+  if form_name > ""             # formからの名前設定がもしあれば
+    info[id]["name"] = form_name # それをユーザ情報に記録
+    info[id]["bingo"] = Hash.new # 正解した単語保存用のハッシュも作成
+  end
+  point = 0			# 開始直後は0点
+  if !info[id]["name"]      # もしユーザのプレイ名が未設定なら
+    title = "○○ゲームへようこそ!"
+    hello = "ポイントゲームを始めましょう。"
+    guide = "あなたのプレイ名を決めます"
+    input = '<input name="playname">'
+  else                          # プレイ名設定済みならキーワード入力
+    title = sprintf("%s さんのホーム", info[id]["name"])
+    guide = "キーワードを入れてください"
+    input = '<input name="keyword">'
+    # プレイ名設定済みで、さらにキーワードが入力されていたら
+    if form_kwd > ""
+      index = bingoword.index(form_kwd) # 配列から入力単語(form_kwd)を探索
+      hello = sprintf("現在のポイントは %dpt です。", 25*point)
+      if index
+        # 見付かった! その単語をハッシュのキーとして適当に値(true)を入れておく
+        info[id]["bingo"][bingoword[index]] = true
+      end
+    end
+    point = info[id]["bingo"].length # ハッシュの長さで正解数が分かる
+    bingos = info[id]["bingo"].keys.collect do |x|
+      "「" + x + "」"	# collectメソッドで 「 」 で括った単語を集めて
+    end.join(", ")	# joinメソッドで ,(カンマ) 区切りでつなげる
+  end
+  printf(<<-EOF,
+	<!DOCTYPE html>
+	<html lang="ja">
+	<head><title>○○ゲーム</title></head>
+	<body>
+	<h1>%s</h1>
+	<p>%s</p>
+	<p>当てたキーワード(%d/%d): %s</p>
+	<form action="?" method="POST">
+	<p>%s: %s<br>
+	<input type="submit" value="送信">
+	<input type="reset" value="リセット"></p>
+	</form></body></html>
+	EOF
+         title, hello, point, bingoword.length, bingos, guide, input)
+end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/event/oasis2016/don/dbinit.cgi	Fri Jul 15 12:58:53 2016 +0900
@@ -0,0 +1,13 @@
+#!/bin/sh
+mkdir db
+cat>db/.htaccess<<EOF
+<Files *>
+Order	allow,deny
+Deny	from all
+</Files>
+EOF
+cat<<EOF
+Content-Type: text/plain
+
+done
+EOF
Binary file event/oasis2016/don/kaisendon.jpg has changed
Binary file event/oasis2016/don/kaisendon2-0.jpg has changed
Binary file event/oasis2016/don/kaisendon2-1.jpg has changed
Binary file event/oasis2016/don/kaisendon2-2.jpg has changed
Binary file event/oasis2016/don/kaisendon2-3.jpg has changed
Binary file event/oasis2016/don/kaisendon2-4.jpg has changed
Binary file event/oasis2016/don/kaisendon2-5.jpg has changed
Binary file event/oasis2016/don/kaisendon2-6.jpg has changed
Binary file event/oasis2016/don/kaisendon2-7.jpg has changed
Binary file event/oasis2016/don/kaisendon2-8.jpg has changed
Binary file event/oasis2016/don/rogo.png has changed
Binary file event/oasis2016/don/umi.png has changed

yatex.org