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
8
# File 'lib/maze/game/maze_player.rb', line 4

def initialize(current_position, name)
  @current_position = current_position
  @name = name
  @moves = 0
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

#movesObject (readonly)

Returns the value of attribute moves.



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

def moves
  @moves
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



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

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



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

def move_bottom
  do_move [0, 1]
end

#move_leftObject



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

def move_left
  do_move [-1, 0]
end

#move_rightObject



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

def move_right
  do_move [1, 0]
end

#move_topObject



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

def move_top
  do_move [0, -1]
end