Class: Robotoy::Game

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

Instance Method Summary collapse

Constructor Details

#initialize(robot: Robot.new, table: Table.new, move: Services::Move, place: Services::Place, orientation: Services::Orientation, report: Services::Report) ⇒ Game

Returns a new instance of Game.



3
4
5
6
7
8
9
10
# File 'lib/robotoy/game.rb', line 3

def initialize(robot: Robot.new, table: Table.new, move: Services::Move, place: Services::Place, orientation: Services::Orientation, report: Services::Report)
  @robot = robot
  @table = table
  @move = move
  @place = place
  @orientation = orientation
  @report = report
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object (private)



47
48
49
# File 'lib/robotoy/game.rb', line 47

def method_missing(name, *args)
  raise Robotoy::NotValidMethodError
end

Instance Method Details

#perform(method, *args) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/robotoy/game.rb', line 12

def perform(method, *args)
  send(method.downcase, *args.flatten)
  @action.perform
rescue NotValidMoveError
  puts "Not a valid place unfortunately"
rescue NotValidOrientationError
  puts "Not a valid orientation unfortunately"
rescue NotPlacedError
  puts "Not placed yet"
rescue NotValidMethodError
  puts "Not a valid method"
end