From a very young age, I have heard about all kind of racing games like cars, bikes, horses all the way up to
dogs; on which people bet! But have you ever heard about betting on a turtle racing? If not, then let me show
you where you can!
In this project, we have hands on practice of the an object state and multiple instances. The objective of the project is to
create a game where 6 different colored turtles will race against each other. But before the race begins, an user can bet on
which of the 6 turtle will win. Based on the winner, at the end of the race, the user will get to know whether he/she is a winner
or not.
Initially I've set up the color base with a list of colors and take user input to place a bet on a certain colored turtle.
The while loop terminator is initiated at the beginning of the program so that it prevents our while loop to not start
before the user is still deciding on what to bet on.
After taking the user input, I've set an if..else statement just to check whether the user's bet is a valid color from
our list or not. If it's not valid, the program will exit and let the user know that it's not a valid color from our
colored turtles.
But if the user bets on a color from our color base, the race will begin. For that, at first I've generated 6 turtle
objects with different color from our color base and appended the turtle objects in a list. After that, I've used the
hideturtle() method to hide the
initially created turtle object. Then I've set the position of each turtle at the beginning of race line using the turtle
graphic's built in method goto().
And finally a while loop to set on the racing. With the help of python's random module, I've set the pace
of each turtle binding them inside a for loop.
After the first turtle that crosses the right edge of the screen, the race ends, and the user can see the
result of his/her bet on the result prompt. Here's the code snippet of the whole project -
The full project can be accessed via my github repository.
With this and more, I'll post tomorrow again in sha Allah about some new topic that I'll learn from the course.