Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Validate the position of the placed robot against the table coordinates
- Loading branch information
Showing
with
5 additions
and
2 deletions.
-
+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 |
|
|