Class: Minehunter::Field Private
- Inherits:
-
Object
- Object
- Minehunter::Field
- Defined in:
- lib/minehunter/field.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
A field on a gird representation
Constant Summary collapse
- BOMB =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
"*"
- COVER =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
"░"
- EMPTY =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
" "
- FLAG =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
"F"
- WRONG =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
"X"
- MINE_COUNT_TO_COLOR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Mappings of mine counts to colour names
{ 1 => :cyan, 2 => :green, 3 => :red, 4 => :blue, 5 => :magenta, 6 => :yellow, 7 => :bright_cyan, 8 => :bright_green }.freeze
Instance Attribute Summary collapse
-
#mine_count ⇒ Object
The number of mines in nearby fields.
Instance Method Summary collapse
-
#cover? ⇒ Boolean
Whether or not the field has cover.
-
#flag ⇒ Object
Toggle flag for a covered field.
-
#flag? ⇒ Boolean
Whether or not there is a flag placed.
-
#initialize ⇒ Field
constructor
Create a Field instance.
-
#mine! ⇒ Object
Mark as having a mine.
-
#mine? ⇒ Boolean
Whether or not the field has mine.
-
#render(decorator: DEFAULT_DECORATOR) ⇒ String
Render the field.
-
#uncover ⇒ Object
Uncover this field.
-
#wrong ⇒ Object
Mark as having wrongly placed flag.
-
#wrong? ⇒ Boolean
Whether or not a flag is placed wrongly.
Constructor Details
#initialize ⇒ Field
Create a Field instance
34 35 36 37 38 39 40 |
# File 'lib/minehunter/field.rb', line 34 def initialize @flag = false @mine = false @cover = true @wrong = false @mine_count = 0 end |
Instance Attribute Details
#mine_count ⇒ Object
The number of mines in nearby fields
29 30 31 |
# File 'lib/minehunter/field.rb', line 29 def mine_count @mine_count end |
Instance Method Details
#cover? ⇒ Boolean
Whether or not the field has cover
88 89 90 |
# File 'lib/minehunter/field.rb', line 88 def cover? @cover end |
#flag ⇒ Object
Toggle flag for a covered field
45 46 47 48 49 |
# File 'lib/minehunter/field.rb', line 45 def flag return unless cover? @flag = !@flag end |
#flag? ⇒ Boolean
Whether or not there is a flag placed
56 57 58 |
# File 'lib/minehunter/field.rb', line 56 def flag? @flag end |
#mine! ⇒ Object
Mark as having a mine
63 64 65 |
# File 'lib/minehunter/field.rb', line 63 def mine! @mine = true end |
#mine? ⇒ Boolean
Whether or not the field has mine
72 73 74 |
# File 'lib/minehunter/field.rb', line 72 def mine? @mine end |
#render(decorator: DEFAULT_DECORATOR) ⇒ String
Render the field
116 117 118 119 120 121 122 123 124 125 |
# 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 ⇒ Object
Uncover this field
79 80 81 |
# File 'lib/minehunter/field.rb', line 79 def uncover @cover = false end |
#wrong ⇒ Object
Mark as having wrongly placed flag
95 96 97 |
# File 'lib/minehunter/field.rb', line 95 def wrong @wrong = true end |
#wrong? ⇒ Boolean
Whether or not a flag is placed wrongly
104 105 106 |
# File 'lib/minehunter/field.rb', line 104 def wrong? @wrong end |