summaryrefslogtreecommitdiff
path: root/sample/mine.rb
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-08-13 05:45:20 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-08-13 05:45:20 +0000
commit65a5162550f58047974793cdc8067a970b2435c0 (patch)
tree082bb7d5568f3b2e36e3fe166e9f3039394fcf44 /sample/mine.rb
parentfcd020c83028f5610d382e85a2df00223e12bd7e (diff)
1.4.0
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@520 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sample/mine.rb')
-rw-r--r--sample/mine.rb42
1 files changed, 21 insertions, 21 deletions
diff --git a/sample/mine.rb b/sample/mine.rb
index b9557d54a2..fd326482a5 100644
--- a/sample/mine.rb
+++ b/sample/mine.rb
@@ -10,19 +10,19 @@ class Board
end
def put(x, y, col, str)
pos(x,y); colorstr(43,str)
- pos(0,@hi); print "$B;D$j(B:",@mc,"/",@total," "
+ pos(0,@hi); print "残り:",@mc,"/",@total," "
pos(x,y)
end
private :clr, :pos, :colorstr, :put
- CHR=["$B!&(B","$B#1(B","$B#2(B","$B#3(B","$B#4(B","$B#5(B","$B#6(B","$B#7(B","$B#8(B","$B!z(B","$B!|(B","@@"]
+ CHR=["・","1","2","3","4","5","6","7","8","★","●","@@"]
COL=[46,43,45] # default,opened,over
def initialize(h,w,m)
- # $B%2!<%`HW$N@8@.(B(h:$B=D!$(Bw:$B2#!$(Bm:$BGzCF$N?t(B)
+ # ゲーム盤の生成(h:縦,w:横,m:爆弾の数)
@hi=h; @wi=w; @m=m
reset
end
def reset
- # $B%2!<%`HW$r(B($B:F(B)$B=i4|2=$9$k(B
+ # ゲーム盤を(再)初期化する
srand()
@cx=0; @cy=0; @mc=@m
@over=false
@@ -44,7 +44,7 @@ class Board
pos(@cx,@cy)
end
def mark
- # $B8=:_$N%+!<%=%k0LCV$K%^!<%/$r$D$1$k(B
+ # 現在のカーソル位置にマークをつける
if @state[@wi*@cy+@cx] != nil then return end
@state[@wi*@cy+@cx] = "MARK"
@mc=@mc-1;
@@ -52,8 +52,8 @@ class Board
put(@cx, @cy, COL[1], CHR[9])
end
def open(x=@cx,y=@cy)
- # $B8=:_$N%+!<%=%k0LCV$r%*!<%W%s$K$9$k(B
- # $BGzCF$,$"$l$P%2!<%`%*!<%P!<(B
+ # 現在のカーソル位置をオープンにする
+ # 爆弾があればゲームオーバー
if @state[@wi*y+x] =="OPEN" then return 0 end
if @state[@wi*y+x] == nil then @total=@total-1 end
if @state[@wi*y+x] =="MARK" then @mc=@mc+1 end
@@ -73,7 +73,7 @@ class Board
pos(@cx,@cy)
end
def fetch(x,y)
- # (x,y)$B$N0LCV$NGzCF$N?t(B(0 or 1)$B$rJV$9(B
+ # (x,y)の位置の爆弾の数(0 or 1)を返す
if x < 0 then 0
elsif x >= @wi then 0
elsif y < 0 then 0
@@ -83,13 +83,13 @@ class Board
end
end
def count(x,y)
- # (x,y)$B$KNY@\$9$kGzCF$N?t$rJV$9(B
+ # (x,y)に隣接する爆弾の数を返す
fetch(x-1,y-1)+fetch(x,y-1)+fetch(x+1,y-1)+
fetch(x-1,y) + fetch(x+1,y)+
fetch(x-1,y+1)+fetch(x,y+1)+fetch(x+1,y+1)
end
def over(win)
- # $B%2!<%`$N=*N;(B
+ # ゲームの終了
quit
unless win
pos(@cx,@cy); print CHR[11]
@@ -100,8 +100,8 @@ class Board
end
end
def over?
- # $B%2!<%`$N=*N;%A%'%C%/(B
- # $B=*N;=hM}$b8F$S=P$9(B
+ # ゲームの終了チェック
+ # 終了処理も呼び出す
remain = (@mc+@total == 0)
if @over || remain
over(remain)
@@ -111,8 +111,8 @@ class Board
end
end
def quit
- # $B%2!<%`$NCfCG(B($B$^$?$O=*N;(B)
- # $BHWLL$rA4$F8+$;$k(B
+ # ゲームの中断(または終了)
+ # 盤面を全て見せる
@hi.times do|y|
pos(0,y)
@wi.times do|x|
@@ -122,19 +122,19 @@ class Board
end
end
def down
- # $B%+!<%=%k$r2<$K(B
+ # カーソルを下に
if @cy < @hi-1 then @cy=@cy+1; pos(@cx, @cy) end
end
def up
- # $B%+!<%=%k$r>e$K(B
+ # カーソルを上に
if @cy > 0 then @cy=@cy-1; pos(@cx, @cy) end
end
def left
- # $B%+!<%=%k$r:8$K(B
+ # カーソルを左に
if @cx > 0 then @cx=@cx-1; pos(@cx, @cy) end
end
def right
- # $B%+!<%=%k$r1&$K(B
+ # カーソルを右に
if @cx < @wi-1 then @cx=@cx+1; pos(@cx, @cy) end
end
end
@@ -143,7 +143,7 @@ bd=Board.new(10,10,10)
system("stty raw -echo")
begin
loop do
- case getc
+ case STDIN.getc
when ?n # new game
bd.reset
when ?m # mark
@@ -163,11 +163,11 @@ begin
break
end
if bd.over?
- if getc == ?q then break end
+ if STDIN.getc == ?q then break end
bd.reset
end
end
ensure
- system("stty -raw echo")
+ system("stty -raw echo")
end
print "\n"