8 printf "\e[%d;%dH", y+1, x*2+1
11 printf "\e[%dm%s\e[0m", id, s
13 def put(x, y, col, str)
14 pos(x,y); colorstr(43,str)
15 pos(0,@hi); print "»Ä¤ê:",@mc,"/",@total," "
18 private :clr, :pos, :colorstr, :put
19 CHR=["¡¦","£±","£²","£³","£´","£µ","£¶","£·","£¸","¡ú","¡ü","@@"]
20 COL=[46,43,45] # default,opened,over
22 # ¥²¡¼¥àÈפÎÀ¸À®(h:½Ä¡¤w:²£¡¤m:ÇúÃƤοô)
27 # ¥²¡¼¥àÈפò(ºÆ)½é´ü²½¤¹¤ë
31 @data=Array.new(@hi*@wi)
32 @state=Array.new(@hi*@wi)
34 @total.times {|i| @data[i]=0}
45 @hi.times{|y| pos(0,y); colorstr(COL[0],CHR[0]*@wi)}
49 # ¸½ºß¤Î¥«¡¼¥½¥ë°ÌÃ֤˥ޡ¼¥¯¤ò¤Ä¤±¤ë
50 if @state[@wi*@cy+@cx] != nil then return end
51 @state[@wi*@cy+@cx] = "MARK"
54 put(@cx, @cy, COL[1], CHR[9])
57 # ¸½ºß¤Î¥«¡¼¥½¥ë°ÌÃÖ¤ò¥ª¡¼¥×¥ó¤Ë¤¹¤ë
58 # ÇúÃƤ¬¤¢¤ì¤Ð¥²¡¼¥à¥ª¡¼¥Ð¡¼
59 if @state[@wi*y+x] =="OPEN" then return 0 end
60 if @state[@wi*y+x] == nil then @total=@total-1 end
61 if @state[@wi*y+x] =="MARK" then @mc=@mc+1 end
62 @state[@wi*y+x]="OPEN"
63 if fetch(x,y) == 1 then @over = 1; return end
65 put(x, y, COL[1], CHR[c])
67 if x > 0 && y > 0 then open(x-1,y-1) end
68 if y > 0 then open(x, y-1) end
69 if x < @wi-1 && y > 0 then open(x+1,y-1) end
70 if x > 0 then open(x-1,y) end
71 if x < @wi-1 then open(x+1,y) end
72 if x > 0 && y < @hi-1 then open(x-1,y+1) end
73 if y < @hi -1 then open(x,y+1) end
74 if x < @wi-1 && y < @hi-1 then open(x+1,y+1) end
78 # (x,y)¤Î°ÌÃÖ¤ÎÇúÃƤοô(0 or 1)¤òÊÖ¤¹
88 # (x,y)¤ËÎÙÀܤ¹¤ëÇúÃƤοô¤òÊÖ¤¹
89 fetch(x-1,y-1)+fetch(x,y-1)+fetch(x+1,y-1)+
90 fetch(x-1,y) + fetch(x+1,y)+
91 fetch(x-1,y+1)+fetch(x,y+1)+fetch(x+1,y+1)
97 pos(@cx,@cy); print CHR[11]
100 if win then print "*** YOU WIN !! ***"
101 else print "*** GAME OVER ***"
105 # ¥²¡¼¥à¤Î½ªÎ»¥Á¥§¥Ã¥¯
107 remain = (@mc+@total == 0)
116 # ¥²¡¼¥à¤ÎÃæÃÇ(¤Þ¤¿¤Ï½ªÎ»)
121 colorstr(if @state[y*@wi+x] == "MARK" then COL[1] else COL[2] end,
122 if fetch(x,y)==1 then CHR[10] else CHR[count(x,y)] end)
128 if @cy < @hi-1 then @cy=@cy+1; pos(@cx, @cy) end
132 if @cy > 0 then @cy=@cy-1; pos(@cx, @cy) end
136 if @cx > 0 then @cx=@cx-1; pos(@cx, @cy) end
140 if @cx < @wi-1 then @cx=@cx+1; pos(@cx, @cy) end
144 bd=Board.new(10,10,10)
145 system("stty raw -echo")
163 when ?q,?\C-c # quit game
168 if STDIN.getc == ?q then break end
173 system("stty -raw echo")