summaryrefslogtreecommitdiff
path: root/sample/mine.rb
diff options
context:
space:
mode:
Diffstat (limited to 'sample/mine.rb')
-rw-r--r--sample/mine.rb40
1 files changed, 20 insertions, 20 deletions
diff --git a/sample/mine.rb b/sample/mine.rb
index 4ef0066..a8711a2 100644
--- a/sample/mine.rb
+++ b/sample/mine.rb
@@ -1,5 +1,5 @@
-#! /usr/bin/ruby -Ke
-# -*- encoding: euc-jp -*-
+#! /usr/bin/ruby -Ku
+# -*- encoding: utf-8 -*-
class Board
def clr
@@ -13,19 +13,19 @@ class Board
end
def put(x, y, col, str)
pos(x,y); colorstr(43,str)
- pos(0,@hi); print "Ĥ:",@mc,"/",@total," "
+ pos(0,@hi); print "残り:",@mc,"/",@total," "
pos(x,y)
end
private :clr, :pos, :colorstr, :put
- CHR=["","","","","","","","","","","","@@"]
+ CHR=["・","1","2","3","4","5","6","7","8","★","●","@@"]
COL=[46,43,45] # default,opened,over
def initialize(h,w,m)
- # פ(h:ġw:m:Ƥο)
+ # ゲーム盤の生成(h:縦,w:横,m:爆弾の数)
@hi=h; @wi=w; @m=m
reset
end
def reset
- # פ()
+ # ゲーム盤を(再)初期化する
srand()
@cx=0; @cy=0; @mc=@m
@over=false
@@ -47,7 +47,7 @@ class Board
pos(@cx,@cy)
end
def mark
- # ߤΥ֤˥ޡĤ
+ # 現在のカーソル位置にマークをつける
if @state[@wi*@cy+@cx] != nil then return end
@state[@wi*@cy+@cx] = "MARK"
@mc=@mc-1;
@@ -55,8 +55,8 @@ class Board
put(@cx, @cy, COL[1], CHR[9])
end
def open(x=@cx,y=@cy)
- # ߤΥ֤򥪡ץˤ
- # ƤХ४С
+ # 現在のカーソル位置をオープンにする
+ # 爆弾があればゲームオーバー
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
@@ -76,7 +76,7 @@ class Board
pos(@cx,@cy)
end
def fetch(x,y)
- # (x,y)ΰ֤Ƥο(0 or 1)֤
+ # (x,y)の位置の爆弾の数(0 or 1)を返す
if x < 0 then 0
elsif x >= @wi then 0
elsif y < 0 then 0
@@ -86,13 +86,13 @@ class Board
end
end
def count(x,y)
- # (x,y)ܤƤο֤
+ # (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)
- # νλ
+ # ゲームの終了
quit
unless win
pos(@cx,@cy); print CHR[11]
@@ -103,8 +103,8 @@ class Board
end
end
def over?
- # νλå
- # λƤӽФ
+ # ゲームの終了チェック
+ # 終了処理も呼び出す
remain = (@mc+@total == 0)
if @over || remain
over(remain)
@@ -114,8 +114,8 @@ class Board
end
end
def quit
- # (ޤϽλ)
- # ̤Ƹ
+ # ゲームの中断(または終了)
+ # 盤面を全て見せる
@hi.times do|y|
pos(0,y)
@wi.times do|x|
@@ -125,19 +125,19 @@ class Board
end
end
def down
- # 򲼤
+ # カーソルを下に
if @cy < @hi-1 then @cy=@cy+1; pos(@cx, @cy) end
end
def up
- #
+ # カーソルを上に
if @cy > 0 then @cy=@cy-1; pos(@cx, @cy) end
end
def left
- # 򺸤
+ # カーソルを左に
if @cx > 0 then @cx=@cx-1; pos(@cx, @cy) end
end
def right
- # 򱦤
+ # カーソルを右に
if @cx < @wi-1 then @cx=@cx+1; pos(@cx, @cy) end
end
end