豊福@パパイヤです。 前橋さんの mine と名前がかぶるので subject を sweeper に変えました。 酒本さん >> 昔のメールを読んでいたら酒本さんのキャラクタ版 >> マインスイーパというのがあったので動してみたら >> 面白かったので少し拡張しました。 > > ruby-list7005 の中村さんがおっしゃるようにタイマーが > つけばもっと面白くなると思うのですが Thread の勉強もかねて秒数を表示するように してみました。 *** sweeper.rb.orig Wed May 27 11:25:27 1998 --- sweeper.rb Wed May 27 12:08:56 1998 *************** *** 1,4 **** --- 1,10 ---- #!/usr/local/bin/ruby + require "thread" + + def flush + $stdout.flush + end + def clr "\e[2J" end *************** *** 47,52 **** --- 53,59 ---- print clr , pos(0,0) 0.upto(@hi-1){|y| print pos(0,y),clrstr(46,"・"*@wi)} print pos(@cx,@cy) + @stime = Time.now.to_i end def mark xy = [@cx,@cy] *************** *** 113,118 **** --- 120,129 ---- print pos(0,@hi),"残り:",@mc,"/",@total," " print pos(@cx,@cy) end + def update_time + print pos(0,@hi+1),"time: ",(Time.now.to_i - @stime) + print pos(@cx,@cy) + end def trymove(dx, dy) newx = @cx + dx; newy = @cy + dy if @state[[newx,newy]] != :border *************** *** 132,138 **** --- 143,162 ---- system("stty raw -echo") + m = Mutex.new + + Thread.start { + while TRUE + m.synchronize { + bd.update_time + flush + } + sleep 0.5 + end + } + while(c=getc).chr != "q" + m.synchronize { case c.chr when "n" # new game bd.reset *************** *** 150,164 **** bd.open_neighbor when " " if bd.open == 1 then bd.over(1) ! if (c=getc).chr == "q" then break end bd.reset end end if bd.remain==0 then bd.over(0) ! if (c=getc).chr == "q" then break end bd.reset end end bd.quit system("stty -raw echo") --- 174,192 ---- bd.open_neighbor when " " if bd.open == 1 then bd.over(1) ! flush ! if (c=getc).chr == "q" then ungetc(?q); break end bd.reset end end if bd.remain==0 then bd.over(0) ! flush ! if (c=getc).chr == "q" then ungetc(?q); break end bd.reset end + flush + } end bd.quit system("stty -raw echo") --- 豊福@パパイヤ unbound / papaya.juice.or.jp toyofuku / juice.or.jp