#a module storing a class to store #all main functions/attributes that #allow the game to work import pygame import sys #a class to store all logic/values #that allow the game to work class gamefunctions: #set the default values #and load images for the game #the game parameter is an instance #of the TicTacToe class def __init__(self, game): #creating a screen attribute to work with self.screen = game.screen #create an attribute called move #which stores the numerical value #of the move the user makes (1-9) self.move = 0 #a list containing all available moves self.availableMoves = [1, 2, 3, 4, 5, 6, 7, 8, 9] #a function that allows #the player to make a move def makeMove(self): self.move = 0 while self.move not in range(1,10): for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_1: self.move = 1 elif event.key == pygame.K_2: self.move = 2 elif event.key == pygame.K_3: self.move = 3 elif event.key == pygame.K_4: self.move = 4 elif event.key == pygame.K_5: self.move = 5 elif event.key == pygame.K_6: self.move = 6 elif event.key == pygame.K_7: self.move = 7 elif event.key == pygame.K_8: self.move = 8 elif event.key == pygame.K_9: self.move = 9 if self.move in self.availableMoves: self.availableMoves.remove(self.move) return self.move else: self.move = 0
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter