import randomfrom Tkinter import *import tkMessageBoxitems = [1,2,3,4,5,6]Roll = random.choice(items)#Initialized value to zero, which is used in the dieRoll functionvalue = 0Winner = 5 #Temporary value untill I can get the program working#This tells the program whos turn it is. When true, Player 1's turn. When false, Player 2's turnPlayerTurn = Trueclass GUIFramework(Frame): def __init__( self, master = None ): """Initialise the base class""" Frame.__init__( self, master ) """Set the Window Title""" self.master.title("Pig Game") """Display the main window""" self.grid( padx = 200, pady = 100 ) self.CreateWidgets() def CreateWidgets(self): """Create the Turn Total text""" self.TurnTotal = Label( self, text = "Turn Total" ) self.TurnTotal.grid( row = 0, column = 0 ) self.PlayerOne = Label( self, text = "Player 1" ) self.PlayerOne.grid( row = 0, column = 12 ) self.PlayerTwo = Label( self, text = "Player 2" ) self.PlayerTwo.grid( row = 0, column = 24 ) self.Winner = Label( self, text = "Winner" ) self.Winner.grid( row = 0, column = 36 ) #Takes the value aquired from dieRoll and places it on the screen underneath "Turn Total" self.TurnTotalValue = Label( self, text = value ) self.TurnTotalValue.grid( row = 4, column = 0 ) #Takes the returned value from checkWinner and places it on the screen underneath "Winner" self.WinnerValue = Label( self, text = Winner ) self.WinnerValue.grid( row = 4, column = 36 ) self.PlayerOneScore = Label( self, text = "Place Holder" ) #Updated with Player1Score self.PlayerOneScore.grid( row = 4, column = 12 ) self.PlayerTwoScore = Label( self, text = "Place Holder" ) #Updated with Player2Score self.PlayerTwoScore.grid( row = 4, column = 24 ) #This creates the button which is used by the dieRoll function to generate a random number between 1 and 6 self.btnRoll = Button( self, text = "Roll", command = self.dieRoll ) self.btnRoll.grid( row = 8, column = 0 ) #This creates the button that, when pressed, calls the function updateScore #and puts the value in self.TurnTotalValue to either PlayerOneScore or PlayerTwoScore, depending on whose turn it is self.btnHold = Button( self, text = "Hold", command = self.scoreUpdate ) self.btnHold.grid( row = 8, column = 12 )#This is the function that is called when btnRoll is pressed. This function generates a random number between 1 and 6. If a 1 is rolled, the value in TurnTotalValue#is set to 0 and the turn is switched. If a 2-6 is rolled, the value in TurnTotalValue is updated by adding the new value generated by the dieRoll to the previous#value in TurnTotalValue def dieRoll(self) : value = 0 Roll = random.choice( items ) if Roll == 1 : value = 0 PlayerTurn = False print "You Lose" else : value = value + Roll print Roll TurnTotal = value self.value = ( value ) return ( value ) #This function is called when btnHold is pressed. def scoreUpdate( value ) : if PlayerTurn == True : Player1Score = value value = 0 PlayerTurn = False checkWinner else : Player1Score = value value = 0 PlayerTurn = True checkWinner #This function is called in the updateScore function def checkWinner() : if Player1Score >= 100 : Winner = "Player 1" else : Winner = "Player 2" return ( Winner ) if __name__ == "__main__": guiFrame = GUIFramework() guiFrame.mainloop()"""#Function for the computer's turn. Will be added at later time.def computerTurn() : while (value < 20) : Roll = random.choice(items) if Roll == 1 : print "You Lose" value = 0 Player1Turn = True break else : value = value + Roll print Roll TurnTotal = value print TurnTotal return ( TurnTotal )""" """#Function for starting a new gamedef newGame() : Player1Turn = True TurnTotal = 0 YourScore = 0 ComputerScore = 0 #NewGame.Button = Disabled #Winner.Field = Disabled"""I would have attached the file, but I couldn't where to do it. Like I said, I have no experience coding in high-level programming languages, so I have no idea whats wrong with my code
[Edited by - Leonius on October 6, 2010 4:47:57 PM]