#!/usr/bin/env ruby
# coding: utf-8

require "pstore"
x = PStore.new("word.db")
x.transaction do
  x["word"] = x["word"] || Hash.new	# x["word"] ||= Hash.new でも可
  word = x["word"]
   print "名前は?: "
  name = gets.chomp
  print "ひとこと: "
  word[name] = gets.chomp

  for who, wd in word
    printf("%sさんのひとこと「%s」\n", who, wd)
  end
end
cafe.transaction do
require 'cgi'
c = CGI.new(:accept_charset => "UTF-8")
print "Content-type: text/html; charset=UTF-8\n\n"

name = c["namae"]
sentaku = c["waza"]

hiroya = ["飛び込み面","小手","突き","胴","小手面","ひるんだ","小手胴"]
cpu = hiroya.sample
print "<!DOCTYPE html>
<html>
<head><title>剣道</title></head>
<body>\n"
print "<h1>#{name}は「#{sentaku}」を選択した!</h1>\n"
printf("<h1>齋藤浩哉は「%s」!</h1>\n",cpu)

if (sentaku == "飛び込み面" && cpu == "ひるんだ")||(sentaku == "出頭面" && cpu == "飛び込み面")||(sentaku == "出頭小手" && cpu == "飛び込み面")||(sentaku == "出頭小手" && cpu == "胴")||(sentaku == "面返し胴" && cpu == "飛び込み面")||(sentaku == "小手面" && cpu == "小手")
  
  print"<p>#{name}の鮮やかな#{sentaku}が決まったああああ!</p>"
  
elsif (sentaku == "飛び込み面" && cpu == "小手")||(sentaku == "飛び込み面" && cpu == "胴")||(sentaku == "出頭面" && cpu == "小手")||(sentaku == "出頭面" && cpu == "胴") || (sentaku == "出頭小手" && cpu == "小手面")|| (sentaku == "面返し胴" && cpu == "小手")||(sentaku == "小手面" && cpu == "小手胴")
  printf("<p>齋藤浩哉の痛烈な%sが決まってしまった!</p>",cpu )
  
else
 print "<p>うまく決まらなかった!</p>"                             
end

print "</body>\n"
print "</html>\n"
