from pygame.locals import * import GlobVar, random class game(): def Start(self): #set up the game board and load all images, including changing the game board background# GlobVar.screen.fill ((0,0,0)) GlobVar.screen.blit(GlobVar.GameBall,(GlobVar.GBallX,GlobVar.GBallY)) GlobVar.screen.blit(GlobVar.Pad,(GlobVar.PlayerX,GlobVar.PlayerY)) GlobVar.screen.blit(GlobVar.Pad,(GlobVar.CompX,GlobVar.CompY)) self.RandChoice = random.choice([0,1,2,3,4,5]) #draw and control the ball# def Ball(self): self.Directions ["East","West","NEast","NWest","SWest","SEast"] self.Trajectory = self.Directions[RandChoice] if GlobVar.BallSpace == "GameBoard" and self.Direction[1]: GlobVar.screen.blit(GlobVar.EBall,(GlobVar.GBallX,GlobVar,GBallY)) GlobVar.GBallX = GlobVar.GBallX + 5 GlobVar.screen.blit(GlobVar.GameBall,(GlobVar.GBallX,GlobVar.GBallY)) #control the player# def Player(self): #input# for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == K_ESCAPE: exit() if event.key == K_UP and GlobVar.PlayerY > 20: GlobVar.screen.blit(GlobVar.ErasePad,(GlobVar.PlayerX,GlobVar.PlayerY)) GlobVar.PlayerY = GlobVar.PlayerY - 10 GlobVar.screen.blit(GlobVar.Pad,(GlobVar.PlayerX,GlobVar.PlayerY)) if event.key == K_DOWN and GlobVar.PlayerY < 530: GlobVar.screen.blit(GlobVar.ErasePad,(GlobVar.PlayerX,GlobVar.PlayerY)) GlobVar.PlayerY = GlobVar.PlayerY + 10 GlobVar.screen.blit(GlobVar.Pad,(GlobVar.PlayerX,GlobVar.PlayerY)) #draw and control the computer# def Computer(self): GlobVar.screen.blit(GlobVar.Pad,(GlobVar.CompX,GlobVar.CompY))