Methods
Constants
| CHR | = | ["・","1","2","3","4","5","6","7","8","★","●","@@"] |
| COL | = | [46,43,45] |
Class Public methods
new(h,w,m)
Link
Instance Public methods
count(x,y)
Link
down()
Link
fetch(x,y)
Link
left()
Link
mark()
Link
open(x=@cx,y=@cy)
Link
# File sample/mine.rb, line 56 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 @state[@wi*y+x]="OPEN" if fetch(x,y) == 1 then @over = 1; return end c = count(x,y) put(x, y, COL[1], CHR[c]) return 0 if c != 0 if x > 0 && y > 0 then open(x-1,y-1) end if y > 0 then open(x, y-1) end if x < @wi-1 && y > 0 then open(x+1,y-1) end if x > 0 then open(x-1,y) end if x < @wi-1 then open(x+1,y) end if x > 0 && y < @hi-1 then open(x-1,y+1) end if y < @hi -1 then open(x,y+1) end if x < @wi-1 && y < @hi-1 then open(x+1,y+1) end pos(@cx,@cy) end
over(win)
Link
over?()
Link
quit()
Link
reset()
Link
# File sample/mine.rb, line 26 def reset # ゲーム盤を(再)初期化する srand() @cx=0; @cy=0; @mc=@m @over=false @data=Array.new(@hi*@wi) @state=Array.new(@hi*@wi) @total=@hi*@wi @total.times {|i| @data[i]=0} @m.times do loop do j=rand(@total-1) if @data[j] == 0 then @data[j]=1 break end end end clr; pos(0,0) @hi.times{|y| pos(0,y); colorstr(COL[0],CHR[0]*@wi)} pos(@cx,@cy) end
right()
Link