Class: Maze

Inherits:
Object
  • Object
show all
Defined in:
lib/maze/game/maze.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#fieldsObject (readonly)

Returns the value of attribute fields.



4
5
6
# File 'lib/maze/game/maze.rb', line 4

def fields
  @fields
end

#heightObject (readonly)

Returns the value of attribute height.



4
5
6
# File 'lib/maze/game/maze.rb', line 4

def height
  @height
end

#widthObject (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

Returns:

  • (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_sObject



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