Hardware Reference
In-Depth Information
Adding a menu for the game
The next step is to add a menu for the game. As discussed in the previous task, we will make of
the menu cla ss available at http://www.pygame.org/project-Menu Class-1260-.html
1. The first step is to import the menu class into the Connect Four game's Python script:
from menu import *
2.
Let's create a menu object with the Start Game opions to launch the game and
Exit to quit the game. We will integrate the menu from the first task of this project.
We will get started by adding the menu that needs to be drawn on the surface:
menu = cMenu(50,50,20,5,'vertical',100, DISPLAYSURF,
[('Start Game' ,1,None),
('Exit' ,2,None)])
3.
Let's set the background of the menu to a blue color:
DISPLAYSURF.fill(BGCOLOR)
4. Using the menu design discussed in the previous task, let's add a line to launch the
game when the Start Game opion is selected. The game is launched by calling the
runGame(isFirstGame) method:
if state == 0:
rect_list,state = menu.update(e,state)
elif state == 1:
runGame(isFirstGame)
isFirstGame = False
state = 0
elif state == 2 :
print 'Exit'
pygame.quit()
sys.exit()
pygame.display.update()
Adding sounds to the game
While the game is in progress, the sounds can be played using pygame.mixer . Refer to the
following steps to find out how to do this:
1. Let's get started by imporing pygame.mixer :
import pygame.mixer
2. This is followed by iniializing pygame.mixer :
pygame.mixer.init()
 
Search WWH ::




Custom Search