CS320n - Assignment 4

This is individual work. You may talk to other students in the course about your design and for ideas, but you are to create the complete Alice program by yourself. You may receive help from the instructor or the TA.

  1. Complete the following world.

    Requirements:

    1. The name of your world shall be your UTEID followed by a dash and a4. For example, my UTEID is scottmd3 so my world would be named scottmd3-a4.

    2. This program is based on problem 14, from page 176 of the book, Frighten Away the Dragon, but is more complicated.

    3. Download the world CrazyKnight.a2w. (Note, sometimes when you download Alice worlds the operating system changes the file extension to .zip. If this happens simply rename the file with the .a2w extension. Also, you cannot open Alice worlds by double clicking on them. You must start Alice and then open the world from within Alice.) This has the initial set up for the world. A knight is positioned between a dragon, a troll, a wizard, and a princess as shown below:


       

    4. The knight has a new method randomMove. When the method is called the knight turns a random direction and moves a random distance between 1 and 10 meters.

    5. Here is the storyboard for the program you are to complete:

      When the space bar is pressed the knight moves randomly
      After the knight moves if he is within 15 meters of the dragon, the dragon runs away from the knight. In other words the minimum safe distance for the dragon is 15 meters. The dragon moves 4 meters away from the knight.
      After the knight moves if he is within 10 meters (minimum safe distance) of the troll, the troll runs away from the knight. The troll moves 3 meters away from the knight.
      After the knight moves if he is within 5 meters of the wizard, the wizard runs away from the knight. The wizard moves 2 meters away from the knight.
      After the knight moves if he is within 3 meters of the princess, the princess runs away from the knight. The princess moves 1 meter away from the knight.
       

    6. The event has already been added to the world so that when the space bar is pressed the world level method moveKnight is called. This method is currently empty.

    7. Make the moveKnight method call the randomMove method on the knight and then check if the knight is too close to any of the four characters. You need to check all four characters because after some movements it is possible the knight will be too close to 2 or more of the characters

    8. To check to see if the knight is too close create a world level function tooClose that returns a boolean. This function should have 2 parameters, an object (who to check) and a distance (minimum safe distance). It returns true if the distance between the object and the knight is less than or equal to the distance.

    9. Create a method runAway. This method should have 2 parameters, an object who to run away  and a number, distance to run. Have who to run away turn to face the knight (use the turn to face method), then have who to run away turn left 1/2 a revolution, then move who to run away forward distance to run  meters.

    10. The movements do not have to be realistic, just use the move method and the characters can glide when they run away.

    11. It is okay if the knight goes off the screen. The camera does not have to follow him. (If you want an extra challenge you can add to the program the ability for the camera to follow the knight. Don't make the camera's vehicle the knight. Instead position an object at the knight's original position and make it invisible. I will refer to this object as the anchor. Every time after the knight moves check the distance between the knight and the anchor. If it is greater than some distance which you need to determine have the camera turn to face the knight. If the knight gets back towards the anchor you could have the camera turn to face the anchor again.)

    12. Be sure to save your world and rename the file with your UTEID and -a4.

     

  2. Turning in your assignment. The assignment must be turned in no later than 11 pm on Monday, March 9. To turn in your assignment you must have your Microlab account id and password. Use these to turn in the program electronically using the Microlab turnin web page. Refer to this web page for instructions on using the turnin web page.