nerobritish.blogg.se

Dieroll coding
Dieroll coding












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. If a 1 is rolled, the value in TurnTotalValue#is set to 0 and the turn is switched. This function generates a random number between 1 and 6. 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""" ("Pig Game") """Display the main window""" id( padx = 200, pady = 100 ) self.CreateWidgets() def CreateWidgets(self): """Create the Turn Total text""" self.TurnTotal = Label( self, text = "Turn Total" ) ( row = 0, column = 0 ) self.PlayerOne = Label( self, text = "Player 1" ) ( row = 0, column = 12 ) self.PlayerTwo = Label( self, text = "Player 2" ) ( row = 0, column = 24 ) self.Winner = Label( self, text = "Winner" ) ( 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 ) ( row = 4, column = 0 ) #Takes the returned value from checkWinner and places it on the screen underneath "Winner" self.WinnerValue = Label( self, text = Winner ) ( row = 4, column = 36 ) self.PlayerOneScore = Label( self, text = "Place Holder" ) #Updated with Player1Score ( row = 4, column = 12 ) self.PlayerTwoScore = Label( self, text = "Place Holder" ) #Updated with Player2Score ( 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 ) ( 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 ) ( row = 8, column = 12 )#This is the function that is called when btnRoll is pressed.

dieroll coding

Import randomfrom Tkinter import *import tkMessageBoxitems = 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.














Dieroll coding