In this class, students will learn how to create a Turtle race game. Through this project, students will have the opportunity understand how to create a reusable function to create a racer and use it in multiple occasions. The lesson will cover the following topics:
The first step is to import the Turtle module. Place import statements at the top of your code. Next, define the screen and specify its dimension and set the background colour. Type the code as follows:
We will use a for loop to draw lines. We'll start at the initial position x and y
We need to select a colour and position for the first racer and set it to the race line.
The same way we add another racer, we only change the colour, position and the name
To start the race we will create a for loop where we line up all the racers. All the racers will need to move forward, so we will pick the random number of pixels each racser can move forward using randint command.
We will create a function which will simplify adding a new racer, this function will have following parameters:
After we've added a function to create a new racer it is so easy to add new racers to the game. We just need add 2 lines of code to add new racer We will add 3 more racers, r4, r5, r6
You have completed this project.