class MazePlayer
Attributes
current_position[R]
moves[R]
name[R]
Public Class Methods
new(current_position, name)
click to toggle source
# File lib/maze/game/maze_player.rb, line 4 def initialize(current_position, name) @current_position = current_position @name = name @moves = 0 end
Public Instance Methods
move(orientation)
click to toggle source
# 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_bottom()
click to toggle source
# File lib/maze/game/maze_player.rb, line 27 def move_bottom do_move [0, 1] end
move_left()
click to toggle source
# File lib/maze/game/maze_player.rb, line 31 def move_left do_move [-1, 0] end
move_right()
click to toggle source
# File lib/maze/game/maze_player.rb, line 35 def move_right do_move [1, 0] end
move_top()
click to toggle source
# File lib/maze/game/maze_player.rb, line 23 def move_top do_move [0, -1] end
Private Instance Methods
do_move(diff)
click to toggle source
# File lib/maze/game/maze_player.rb, line 40 def do_move(diff) @current_position = [@current_position[0] + diff[0], @current_position[1] + diff[1]] @moves += 1 end