Back

Modelling levels - 2

We need to write a detailed plan for our program, an algorithm. We are going to need some libraries. The sys library and the turtle library will give us all of the extra functions we need. A first attempt at writing our algorithm might go like this:

Set up the program.
Write the function to draw and move the alien.
Display a menu.
The user chooses an option.
Load the values into the function and run the program.

This is fine as a first attempt as it paints the overview for us but there isn't enough detail to write a program from. Let's do that now in pseudo-code.

Import the turtle and sys libraries
Initialise the variables you will need
Make a window that the game will run in
Set the window background to be light yellow.
Set the window size to be 800 by 800

Create a turtle called Fred

Define a function called alien (size, colour, speed)
    Fredx = Fred's x coord, the starting position
    Fredy = Fred's y coord, the starting position
   Set Fred's starting position to be (Fredx, Fredy)

    While Fred's x coord < 360:
           delay (speed) milliseconds
           add 10 to Fred's x coord
           set Fred's new position to (Fredx, Fredy)
           Draw the dot (size, colour)

Display the level options
Read in the player's selection.

If level1 selected:
    size = 100
    colour = blue
    speed = 25

If level2 selected:
    size = 30
    colour = red
    speed = 10

If level3 selected:
    size = 10
    colour = black
    speed = 1

Call alien(size, colour, speed) 

Challenge!
Without looking at the next section, can you use the pseudo-code above to write the program? You can use the Python documentation for the turtle module to help you as well as referring to the Pelican Crossing modelling project if you have completed that.

Back