Class: Maze
- Inherits:
-
Object
- Object
- Maze
- Defined in:
- lib/maze/game/maze.rb
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #exit?(position) ⇒ Boolean
-
#initialize(width, height) ⇒ Maze
constructor
A new instance of Maze.
- #possible_directions(position) ⇒ Object
- #to_s ⇒ Object
- #to_s_for_player(player_number = nil, player_position) ⇒ Object
Constructor Details
#initialize(width, height) ⇒ Maze
Returns a new instance of Maze.
6 7 8 9 10 |
# File 'lib/maze/game/maze.rb', line 6 def initialize(width, height) @width = width @height = height @fields = MazeGenerator.new(width, height).create end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
4 5 6 |
# File 'lib/maze/game/maze.rb', line 4 def fields @fields end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
4 5 6 |
# File 'lib/maze/game/maze.rb', line 4 def height @height end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
4 5 6 |
# File 'lib/maze/game/maze.rb', line 4 def width @width end |
Instance Method Details
#exit?(position) ⇒ Boolean
21 22 23 |
# File 'lib/maze/game/maze.rb', line 21 def exit?(position) @fields[position] == :exit end |
#possible_directions(position) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/maze/game/maze.rb', line 12 def possible_directions(position) way_fields = [] way_fields << :top if way_or_exit_field? position, [0, -1] way_fields << :bottom if way_or_exit_field? position, [0, +1] way_fields << :left if way_or_exit_field? position, [-1, 0] way_fields << :right if way_or_exit_field? position, [+1, 0] way_fields end |
#to_s ⇒ Object
29 30 31 |
# File 'lib/maze/game/maze.rb', line 29 def to_s field_to_s end |
#to_s_for_player(player_number = nil, player_position) ⇒ Object
25 26 27 |
# File 'lib/maze/game/maze.rb', line 25 def to_s_for_player(player_number = nil, player_position) field_to_s(player_number, player_position) end |