CSC 172 
Homework assignment 1

Spring, 1999

Multiple Buggles

Assigned 29 Jan; due 9 Feb.

Download the WalkingBuggles folder from my download directory on panther.  It should contain

A refresher: programming a TickBuggle

Version 1

For Version 1 of this homework, open the BishopBuggle.java file and change the tick() method so the Buggle "walks diagonally". For example, if it were facing east, at each tick() it would take one step east and one step north, ending up facing the same direction it started.


Version 2

If you try more than a few ticks on one of these BishopBuggles, it'll hit a wall and get stuck, as in the above picture. So for Version 2, modify the tick() method so that the Buggle "bounces off walls" at a 90-degree angle to the angle at which it hit the wall, as in the picture at left.
Note that your BishopBuggle should bounce off walls regardless of whether it's going counterclockwise (as in the above example) or clockwise (as in this example).


Version 3

As you play with this BishopBuggle, you may wonder what it'll do if it walks into a corner. Before you try it, draw a picture of what you think it'll do (or what you hope it'll do). Try a couple of examples. It turns out that, since a BishopBuggle's path is two squares wide, there are two different ways for a Buggle to "walk into a corner":

  • with the right half of the path hitting the corner square, in which case it should bounce out with the right half of the path emerging from the corner square, or


  • with the left half of the path hitting the corner square, in which case it should bounce out with the left half of the path emerging from the corner square.
  • For Version 3 of the program, make sure your BishopBuggle does both of these properly. Try my solution.


    Double your Pleasure

    Version 4

    For Version 4 of the program, we'll change the way the WalkingBuggleWorld works, so that whenever we hit the "Run" button, it creates not one but two BishopBuggles at two random locations on the screen, and every time we hit the "Tick" button, both of them move. This shouldn't require any further changes to the BishopBuggle.java file, but you'll need to modify the WalkingBuggleWorld.java file (and perhaps look at, but not modify, the TickBuggleWorld.java file). To help keep the two buggles straight, make them different colors. Try my solution.


    Version 5

    In Version 5, we'll generalize what we've done above to handle a number of BishopBuggles, stored in a Vector (see chapter 8 of the textbook). When the user hits the "Run" button, your program should create at least three BishopBuggles (for now, you may simply always create three, or always four, or you may use a Randomizer to decide how many to create), and store them in a Vector rather than giving them each its own name. Then when the user hits "Tick", all the BishopBuggles in the Vector will be sent a tick() message.

    Try my solution. Note: I originally wrote this to create three Buggles, but one time I tried hitting "reset" and "run" again to get a more interesting set of initial positions, and found to my surprise that I now had six, all moving in lock-step: the original three hadn't gone away when I hit "reset" and "run", and they had now been joined by three more. Not what I had in mind, but an interesting result nonetheless.


    Version 6

    Now let's allow the user to create BishopBuggles interactively. Modify the program so that every time the user hits the "new Buggle()" button, one more BishopBuggle is added to the Vector. (Hint: override the makeNewBuggle method.)

    Try my solution, which also sets the color of each new Buggle randomly. I'm still working on this one....


    Version 7

    Time to get really wild now. So far all the Buggles have been Bishops; let's add a Knight or two to the mix. To do this, you'll need to write another subclass of WalkingBuggle named KnightBuggle, similar to BishopBuggle but with a different tick() method (and of course a different way to bounce off walls). Modify the program so that every time the user hits the "new Buggle()" button, one more Buggle is added to the Vector, but whether it's a BishopBuggle or a KnightBuggle is chosen randomly (with the aid of a Randomizer). You are welcome to define more subclasses of WalkingBuggle if you wish, and see how they all interact.


    Extra credit

    So far the Buggles don't have any way of interacting with one another except by overwriting one another's trails, and each doesn't know the others are there. Try defining some kinds of WalkingBuggles that leave Bagels behind and/or eat one another's Bagels.



    Last modified: Tue Feb 2 13:14:14 EST 1999

    Stephen Bloch / sbloch@adelphi.edu