class Minehunter::Field
A field on a gird representation
@api private
Constants
- BOMB
- COVER
- EMPTY
- FLAG
- MINE_COUNT_TO_COLOR
Mappings of mine counts to colour names
- WRONG
Attributes
mine_count[RW]
The number of mines in nearby fields
@api public
Public Class Methods
new()
click to toggle source
Create a Field
instance
@api public
# File lib/minehunter/field.rb, line 34 def initialize @flag = false @mine = false @cover = true @wrong = false @mine_count = 0 end
Public Instance Methods
cover?()
click to toggle source
Whether or not the field has cover
@return [Boolean]
@api public
# File lib/minehunter/field.rb, line 88 def cover? @cover end
flag()
click to toggle source
Toggle flag for a covered field
@api public
# File lib/minehunter/field.rb, line 45 def flag return unless cover? @flag = !@flag end
flag?()
click to toggle source
Whether or not there is a flag placed
@return [Boolean]
@api public
# File lib/minehunter/field.rb, line 56 def flag? @flag end
mine!()
click to toggle source
Mark as having a mine
@api public
# File lib/minehunter/field.rb, line 63 def mine! @mine = true end
mine?()
click to toggle source
Whether or not the field has mine
@return [Boolean]
@api public
# File lib/minehunter/field.rb, line 72 def mine? @mine end
render(decorator: DEFAULT_DECORATOR)
click to toggle source
Render the field
@param [Proc] decorator
apply style formatting
@return [String]
@api public
# File lib/minehunter/field.rb, line 116 def render(decorator: DEFAULT_DECORATOR) if !cover? if mine? then BOMB elsif flag? && wrong? then decorator[WRONG, :on_red] elsif !mine_count.zero? decorator[mine_count.to_s, MINE_COUNT_TO_COLOR[mine_count]] else EMPTY end elsif flag? then FLAG else COVER end end
uncover()
click to toggle source
Uncover this field
@api public
# File lib/minehunter/field.rb, line 79 def uncover @cover = false end
wrong()
click to toggle source
Mark as having wrongly placed flag
@api public
# File lib/minehunter/field.rb, line 95 def wrong @wrong = true end
wrong?()
click to toggle source
Whether or not a flag is placed wrongly
@return [Boolean]
@api public
# File lib/minehunter/field.rb, line 104 def wrong? @wrong end