Class: Mineswiper::Tile

Inherits:
Object
  • Object
show all
Defined in:
lib/mineswiper/tile.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_bombsObject

Returns the value of attribute adj_bombs.



4
5
6
# File 'lib/mineswiper/tile.rb', line 4

def adj_bombs
  @adj_bombs
end

#bombObject (readonly)

Returns the value of attribute bomb.



5
6
7
# File 'lib/mineswiper/tile.rb', line 5

def bomb
  @bomb
end

#flagObject

Returns the value of attribute flag.



4
5
6
# File 'lib/mineswiper/tile.rb', line 4

def flag
  @flag
end

#hiddenObject

Returns the value of attribute hidden.



4
5
6
# File 'lib/mineswiper/tile.rb', line 4

def hidden
  @hidden
end

#numberObject

Returns the value of attribute number.



4
5
6
# File 'lib/mineswiper/tile.rb', line 4

def number
  @number
end

#posObject (readonly)

Returns the value of attribute pos.



5
6
7
# File 'lib/mineswiper/tile.rb', line 5

def pos
  @pos
end

#stateObject

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

Returns:

  • (Boolean)


18
19
20
# File 'lib/mineswiper/tile.rb', line 18

def bomb?
  @bomb == true
end

#flag_itObject



26
27
28
# File 'lib/mineswiper/tile.rb', line 26

def flag_it
  @flag = true
end

#flagged?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/mineswiper/tile.rb', line 22

def flagged?
  @flag
end

#revealObject



14
15
16
# File 'lib/mineswiper/tile.rb', line 14

def reveal
  @hidden = false
end

#tilerenderObject



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

#unflagObject



30
31
32
# File 'lib/mineswiper/tile.rb', line 30

def unflag
  flag = false
end