BotPlay!

Inspiration

Goals

 

Step #1: Download the Supplied Code and Tell DrJava Where It Is

Note: Step 2 to 4 must be done in the Dr Java interactions pane

Step #2: Create a BotWorld and a Bot

> BotWorld world = new BotWorld();  // Create a BotWorld. A cartoon world should appear on your screen.
> Bot bot = new Bot(world);         // Create a Bot; it should appear in the cartoon world.
                                    // Now the Bot and BotWorld know about each other. 

Step #3: Give the Bot Commands and Ask it Questions

> bot.move();   // Command the Bot to move by "calling" its move method. Next we'll get it to eat the Dot in front of it.
> bot.move();
> bot.eatDot();
> bot.move();   // You should see that the Dot disappeared.
> bot.move()    // If you leave out the semicolon, DrJava tells you the value "returned"/output by a method.
true            // If it's facing a (green) wall, it won't move, and it will return false.
> bot.turnLeft()    // A Bot can turn left, and it's now facing north. 
'n'
> bot.turnRight()   // But there is no turnRight() method.
Error: No 'turnRight' method in 'Bot' with arguments: ()


Further Exploration

  1. Can just make the bot turn right just knowing that it can only turn left?
  2. Create a second Bot, and then a third. Each one has its own state/data (X, Y position, orientation, etc.). Prove to yourself that you can move them independently.
  3. Can more than one Bot occupy the same position in the world?
  4. Write a loop that will make the Bot move forward 5 times.
  5. Write a loop that will make the Bot travel in a 3 x 3 square (it's your choice about whether to go clockwise or counterclockwise).

Step #4: Wishlist