Class: MazePlayer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_position, name) ⇒ MazePlayer

Returns a new instance of MazePlayer.



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

def initialize(current_position, name)
  @current_position = current_position
  @name = name
end

Instance Attribute Details

#current_positionObject (readonly)

Returns the value of attribute current_position.



2
3
4
# File 'lib/maze/game/maze_player.rb', line 2

def current_position
  @current_position
end

#nameObject (readonly)

Returns the value of attribute name.



2
3
4
# File 'lib/maze/game/maze_player.rb', line 2

def name
  @name
end

Instance Method Details

#move(orientation) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/maze/game/maze_player.rb', line 9

def move(orientation)
  case orientation
    when :top
      move_top
    when :bottom
      move_bottom
    when :left
      move_left
    when :right
      move_right
  end
end

#move_bottomObject



26
27
28
# File 'lib/maze/game/maze_player.rb', line 26

def move_bottom
  do_move [0, 1]
end

#move_leftObject



30
31
32
# File 'lib/maze/game/maze_player.rb', line 30

def move_left
  do_move [-1, 0]
end

#move_rightObject



34
35
36
# File 'lib/maze/game/maze_player.rb', line 34

def move_right
  do_move [1, 0]
end

#move_topObject



22
23
24
# File 'lib/maze/game/maze_player.rb', line 22

def move_top
  do_move [0, -1]
end