Class: Mineswiper::Tile
- Inherits:
-
Object
- Object
- Mineswiper::Tile
- Defined in:
- lib/mineswiper/tile.rb
Instance Attribute Summary collapse
-
#adj_bombs ⇒ Object
Returns the value of attribute adj_bombs.
-
#bomb ⇒ Object
readonly
Returns the value of attribute bomb.
-
#flag ⇒ Object
Returns the value of attribute flag.
-
#hidden ⇒ Object
Returns the value of attribute hidden.
-
#number ⇒ Object
Returns the value of attribute number.
-
#pos ⇒ Object
readonly
Returns the value of attribute pos.
-
#state ⇒ Object
Returns the value of attribute state.
Instance Method Summary collapse
- #bomb? ⇒ Boolean
- #flag_it ⇒ Object
- #flagged? ⇒ Boolean
-
#initialize(pos, bomb = false) ⇒ Tile
constructor
A new instance of Tile.
- #reveal ⇒ Object
- #tilerender ⇒ Object
- #unflag ⇒ Object
Constructor Details
#initialize(pos, bomb = false) ⇒ Tile
Returns a new instance of Tile.
7 8 9 10 11 12 |
# File 'lib/mineswiper/tile.rb', line 7 def initialize(pos, bomb=false) @pos, @bomb = pos, bomb @hidden = true @flag = false @adj_bombs = 0 end |
Instance Attribute Details
#adj_bombs ⇒ Object
Returns the value of attribute adj_bombs.
4 5 6 |
# File 'lib/mineswiper/tile.rb', line 4 def adj_bombs @adj_bombs end |
#bomb ⇒ Object (readonly)
Returns the value of attribute bomb.
5 6 7 |
# File 'lib/mineswiper/tile.rb', line 5 def bomb @bomb end |
#flag ⇒ Object
Returns the value of attribute flag.
4 5 6 |
# File 'lib/mineswiper/tile.rb', line 4 def flag @flag end |
#hidden ⇒ Object
Returns the value of attribute hidden.
4 5 6 |
# File 'lib/mineswiper/tile.rb', line 4 def hidden @hidden end |
#number ⇒ Object
Returns the value of attribute number.
4 5 6 |
# File 'lib/mineswiper/tile.rb', line 4 def number @number end |
#pos ⇒ Object (readonly)
Returns the value of attribute pos.
5 6 7 |
# File 'lib/mineswiper/tile.rb', line 5 def pos @pos end |
#state ⇒ Object
Returns the value of attribute state.
4 5 6 |
# File 'lib/mineswiper/tile.rb', line 4 def state @state end |
Instance Method Details
#bomb? ⇒ Boolean
18 19 20 |
# File 'lib/mineswiper/tile.rb', line 18 def bomb? @bomb == true end |
#flag_it ⇒ Object
26 27 28 |
# File 'lib/mineswiper/tile.rb', line 26 def flag_it @flag = true end |
#flagged? ⇒ Boolean
22 23 24 |
# File 'lib/mineswiper/tile.rb', line 22 def flagged? @flag end |
#reveal ⇒ Object
14 15 16 |
# File 'lib/mineswiper/tile.rb', line 14 def reveal @hidden = false end |
#tilerender ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/mineswiper/tile.rb', line 34 def tilerender if flagged? return "\u2691".encode('utf-8') elsif @hidden return "\u25A0".encode('utf-8') elsif bomb? return "\u2622".encode('utf-8') else return self.adj_bombs.to_s end end |
#unflag ⇒ Object
30 31 32 |
# File 'lib/mineswiper/tile.rb', line 30 def unflag flag = false end |