Permalink
Browse files

Validate the position of the placed robot against the table coordinates

  • Loading branch information...
SelenaSmall committed Aug 26, 2017
1 parent 0f842b7 commit b39456f4fc8a632a678e8856b60792641c9e7f3f
Showing with 5 additions and 2 deletions.
  1. +5 −2 toy_robot.rb
@@ -1,7 +1,9 @@
#!/usr/bin/ruby
require_relative './lib/table'
require_relative './lib/robot'
table = Table.new
robot = Robot.new
# Keep reading user inputs while the program is running
@@ -11,9 +13,10 @@
unless input == 'EXIT'
position = robot.place(input)
puts "Position: #{position.x},#{position.y}"
# Only update robot if the position is valid on the table
robot.update_robot(position) if table.valid_position?(position.x, position.y)
robot.update_robot(position)
puts "Position: #{position.x},#{position.y}"
puts 'placed' unless robot.not_in_place?
next

0 comments on commit b39456f

Please sign in to comment.