Lab Dates: Thursday, 15 & Wednesday, 21 November 2012

Today's lab looks at nested loops and indefinite loops from Chapter 8.

Mystery Point Game

Today, we are going to write a simple game where the user tries to find our mystery point in the graphics window. Lets first go through the program section by section:

Try running the program. How easy is it to win?

Giving Hints

Could you find the point without peeking at the IDLE shell? To make the game a bit easier, we will add hints. The first hint will be to tell the user if they need to click more to the left (or right) to find the point. Here is the pseudocode:

	if point clicked is to the left of mystery point
		give message "Too far left"
	else 
		give message "Too far right"

How can you tell if the point clicked is to the left of the mystery point? The x-coordinate tells how far left or right a point is, so, we compare the x-coordinates of the two points:

        if p.getX() < mysteryPoint.getX():
            t.setText("Click again! You were too far left")
        else:
            t.setText("Click again! You were too far right")

Now, add in the code that will give a hint to move up (or down) depending on where they clicked with respect to the mystery point. Your completed program should have a "left/right" hint and an "low/high" hint to make the game possible to do without looking at our diagonostics on the python shell.

Hint: Before the loop, set up another Text object, t2 to display the message about being too low or too high:

    t2 = Text(Point(0,-230), "")
    t2.setSize(16)
    t2.draw(w)

After completing your program, go to Assignments in Blackboard and click on the link: Lab 9. Use the file upload interface to upload your program. Remember to click the Submit button before closing the lab exercise.

With the remaining time, start Problem Set 8.