• The dictionary data type (we don't really focus on this)
• Key-value pairs
• The keys() and values() dictionary methods (not focussed on much)
• Multiple variable assignment - Something you should know! You'll see it more in the next chapter.
• Artificial intelligence
• List references
• Short-circuit evaluation
• The None value
Let's get programming! You are required to make a two-player version of Tic-Tac-Toe. Begin by creating a flow-chart for the game as a class. There are some hints below (Task 2) which may help in designing the flowchart too.
HINTS:
Refer to the Flowchart under the heading "Designing the Program" in Chapter 10. Yours should be a bit simpler than this, because it will not have a Computer's Turn section!
Don't ask the players who will be X and O, just assign those automatically, if/when you ask for player names.
Write and test your Two-player Tic-Tac-Toe program. You might start with the original code for the One-player version, but 'Save As' a different name before you change anything.
HINTS:
There will be functions in the original code you will not need, such as inputPlayerLetter() and functions which are for the computer's AI. Your code should be much smaller than the 1-player version because of this.
If you are asking for the players' names, perhaps store them in global variables called xName and oName or something similar.
• The random.shuffle() function
• Augmented assignment operators, +=, -=, *=, /=
• The sort() list method
• The join() string method
• String interpolation
• The conversion specifier %s
• Nested loops
Write a program that creates a 3-digit number between 0 and 999, but prints the number as 3 digits. I.e. it adds the leading zeros if the number is less than 100 and less than 10. (e.g. 23 becomes 023 and 7 becomes 007).
Test your code thoroughly.
Change the Bagels program so that it works with your new number generator from Task 1. This will involve modifying the way the clues work so that repeated digits (i.e. 001) are acceptable. WARNING: THIS IS A DIFFICULT CHALLENGE.
Test the generator thoroughly, so that it works according to the following table:
secret guess clues
007 889 Bagels
007 007 (Correct Answer)
007 970 Pico Pico
345 304 Fermi Pico
345 033 Pico
345 555 Fermi
• Cartesian coordinate systems
• The x-axis and y-axis
• Negative numbers
• Pixels
• The commutative property of addition
• Absolute values and the abs() function
• Data structures
• The Pythagorean theorem
• The remove() list method
• The isdigit() string method
• The sys.exit() function
Improve the number system on the top and bottom of the ocean (X-axis)
The program in this chapter isn’t really a game, but it is fun nevertheless. The program will convert normal English into a secret code. It can also do the reverse. Only someone who knows the key to the secret codes will be able to understand the messages.
Because this program manipulates text to convert it into secret messages, you’ll learn several new functions and methods for manipulating strings. You’ll also learn how programs can do math with text strings just as they can with numbers.
We don't focus on this chapter - however if you would like to have a read, the link above still works :)
• The bool() function
• Programming a Reversegam AI
We don't focus on this chapter - however if you would like to have a read, the link above still works :)
• Simulations
• Percentages
• Integer division
• The round() function
• Computer-versus-computer games
• Installing pygame
• Colors and fonts in pygame
• Aliased and anti-aliased graphics
• Attributes
• The pygame.font.Font, pygame.Surface, pygame.Rect, and pygame.PixelArray data types
• Constructor functions
• pygame’s drawing functions
• The blit() method for surface objects
• Events
Change the image so that none of the objects overlap each other, it has a new name and new text and some different colors. Make the background Yellow. Example below.
Task:
Change the program so that there is an extra rectangle moving around. Make it purple.
• Animating objects with the game loop
• Changing the direction of an object
• Clock objects
• Keyboard input in pygame
• Mouse input in pygame
• Collision detection
• Not modifying a list while iterating over it
• Sound and image files
• Drawing and rescaling sprites
• Adding music and sounds
• Toggling sound on and off
• The pygame.FULLSCREEN flag
• The move_ip() Rect method
• Implementing cheat codes
• Modifying the Dodger game