Mar-20-2021, 05:10 PM
(This post was last modified: Mar-20-2021, 10:01 PM by Larz60+.
Edit Reason: fixed python tags
)
Ive created this code for a dice game... it is a two player game with an authentication before it, its for a GCSE project.
I want all of the outputs to appear in a seperate tabb i also want to add in a GUI button to roll the dice for each player each round. Can anyone point me in the right directiom. Thankyou in advance
I want all of the outputs to appear in a seperate tabb i also want to add in a GUI button to roll the dice for each player each round. Can anyone point me in the right directiom. Thankyou in advance
print("================================") print(" Enya's Dice game ") print("================================") import time time.sleep(3) player1= input("player 1 what is your name?") #asks the first player for their name print("Hello" , player1)#outputs on the screen hello and then the players name print("") print("$$$================================$$$") print(" password authentication ") print("$$$================================$$$") print("") password1= input("please enter the top secrete password: ")#asks you to enter password if password1 == "dice": print("authentication complete:)")#this is the code for the complete password elif password1 == "quit": #if the password is quit on your first attempt then it will say good bye print("goodbye :(") quit() while password1 != "dice": password1= input("please try again: ")#asks you to enter password if password1 == "quit": #after your first atempt you can quit then it will say good bye print("goodbye :(") quit() elif password1 == "dice": #code for after your first atempt and the password is correct. print("authentication complete") #the following is the authentication process for the second player player2= input("player 2 what is your name?") #asks the first player for their name print("Hello" , player2)#outputs on the screen hello and then the players name print("") print("$$$================================$$$") print(" password authentication ") print("$$$================================$$$") print("") password2= input("please enter the top secrete password: ")#asks you to enter password if password2 == "dice": print("authentication complete:)") #this is the code for the complete password elif password2 == "quit": #if the password is quit on your first attempt then it will say good bye print("goodbye :(") quit() while password2 != "dice": password2= input("please try again: ")#asks you to enter password if password2 == "quit": #after your first atempt you can quit then it will say good bye print("goodbye :(") quit() elif password2 == "dice": #code for after your first atempt and the password is correct. print("authentication complete") #the following will output the rules print(player1, "vs", player2, "you will now take part in 5 rounds of dice game") print("these are the rules: ") print("") print("- 2 six sided dice will be rolled at RANDOM") print("") print("- If the total is an even number, an additional 10 points are added to their score.") print("") print("- If the total is an odd number, 5 points are subtracted from their score.") print("") print("- The person with the highest score at the end of 5 rounds wins") print("") print("good luck!") print("") time.sleep(20) # this gives a time dalay for the next outputs of 10 seconds print("") print("") print("Round 1") print(player1) time.sleep(3) print("Dice rolling...") time.sleep(3) print("") from random import * P1R1N1= randint(1,6) #this generates a random number for the first dice from 1 to 6 and stores it in playe 1 round 1 number 1 variable P1R1N2= randint(1,6) #this generates a random number for the first dice from 1 to 6 and stores it in playe 1 round 1 number 2 variable if P1R1N1 == P1R1N2: #if the dice have both the same number then both dice will role 2 new numbers P1R1N3= randint(1,6) P1R1N4= randint(1,6) totalR1p1= (P1R1N1 + P1R1N2 + P1R1N3 + P1R1N4) #these 2 new numbers will then be aded to form a total print("you rolled a double, you scored a ", P1R1N1, "and a ", P1R1N2, "so we gave you two more rolls you scored a : ", P1R1N3, "and a: ", P1R1N4, "These have been added to your original score your total is: ", totalR1p1) else: totalR1p1= (P1R1N1 + P1R1N2) #if the dice did not role two of the same numbers then the total of the dice are just added up and the total is outputed # it is then stored in the variable totalR1p1 which is the total for the players 1 round this will be later used to add up all of the players totals print("you rolled a ", P1R1N1, "and a ",P1R1N2, "your total is ", totalR1p1) print("") print("") time.sleep(5) print(player2) print("") time.sleep(3) print("Dice rolling...") time.sleep(3) print("") #this repeates the process for player 2 from random import * P2R1N1= randint(1,6) P2R1N2= randint(1,6) if P2R1N1 == P2R1N2: P2R1N3= randint(1,6) P2R1N4= randint(1,6) totalR1p2= (P2R1N1 + P2R1N2 + P2R1N3 + P2R1N4) print("you rolled a double, you scored a ", P2R1N1, "and a ", P2R1N2, "so we gave you two more rolls you scored a : ", P2R1N3, "and a: ", P2R1N4, "These have been added to your original score your total is: ", totalR1p2) else: totalR1p2= (P2R1N1 + P2R1N2) print("you rolled a ", P2R1N1, "and a ",P2R1N2, "your total is ", totalR1p2) print("") time.sleep(3) if totalR1p1 > totalR1p2: print(player1, "wins round 1") else: print(player2, "wins round 1") print("") print("") print("Round 2") print("") print(player1) print("") time.sleep(3) print("Dice rolling...") time.sleep(3) print("") from random import * P1R2N1= randint(1,6) #this generates a random number for the first dice from 1 to 6 and stores it in playe 1 round 1 number 1 variable P1R2N2= randint(1,6) #this generates a random number for the first dice from 1 to 6 and stores it in playe 1 round 1 number 2 variable if P1R2N1 == P1R1N2: #if the dice have both the same number then both dice will role 2 new numbers P1R2N3= randint(1,6) P1R2N4= randint(1,6) totalR2p1= (P1R2N1 + P1R2N2 + P1R2N3 + P1R2N4) #these 2 new numbers will then be aded to form a total print("you rolled a double, you scored a ", P1R2N1, "and a ", P1R2N2, "so we gave you two more rolls you scored a : ", P1R2N3, "and a: ", P1R2N4, "These have been added to your original score your total is: ", totalR2p1) else: totalR2p1= (P1R2N1 + P1R2N2) #if the dice did not role two of the same numbers then the total of the dice are just added up and the total is outputed # it is then stored in the variable totalR1p1 which is the total for the players 1 round this will be later used to add up all of the players totals print("you rolled a ", P1R2N1, "and a ",P1R2N2, "your total is ", totalR2p1) print("") print("") time.sleep(5) print(player2) print("") time.sleep(3) print("Dice rolling...") print("") time.sleep(3) #this repeates the process for player 2 from random import * P2R2N1= randint(1,6) P2R2N2= randint(1,6) if P2R2N1 == P2R1N2: P2R2N3= randint(1,6) P2R2N4= randint(1,6) totalR2p2= (P2R2N1 + P2R2N2 + P2R2N3 + P2R2N4) print("you rolled a double, you scored a ", P2R2N1, "and a ", P2R2N2, "so we gave you two more rolls you scored a : ", P2R2N3, "and a: ", P2R2N4, "These have been added to your original score your total is: ", totalR2p2) else: totalR2p2= (P2R2N1 + P2R2N2) print("you rolled a ", P2R2N1, "and a ",P2R2N2, "your total is ", totalR2p2) print("") time.sleep(3) if totalR2p1 > totalR2p2: print(player1, "wins round 2") else: print(player2, "wins round 2") print("") totalP1= (totalR1p1 + totalR2p1) print(player1, "your total score at the end of round 2 is ", totalP1) totalP2= (totalR1p2 + totalR2p2) print(player2, "your total score at the end of round 2 is ", totalP2) print("") print("") print("Round 3") print("") print(player1) time.sleep(3) print("") print("Dice rolling...") time.sleep(3) print("") from random import * P1R3N1= randint(1,6) #this generates a random number for the first dice from 1 to 6 and stores it in playe 1 round 1 number 1 variable P1R3N2= randint(1,6) #this generates a random number for the first dice from 1 to 6 and stores it in playe 1 round 1 number 2 variable if P1R3N1 == P1R3N2: #if the dice have both the same number then both dice will role 2 new numbers P1R3N3= randint(1,6) P1R3N4= randint(1,6) totalR3p1= (P1R3N1 + P1R3N2 + P1R3N3 + P1R3N4) #these 2 new numbers will then be aded to form a total print("you rolled a double, you scored a ", P1R3N1, "and a ", P1R3N2, "so we gave you two more rolls you scored a : ", P1R3N3, "and a: ", P1R3N4, "These have been added to your original score your total is: ", totalR3p1) else: totalR3p1= (P1R3N1 + P1R3N2) #if the dice did not role two of the same numbers then the total of the dice are just added up and the total is outputed # it is then stored in the variable totalR1p1 which is the total for the players 1 round this will be later used to add up all of the players totals print("you rolled a ", P1R3N1, "and a ",P1R3N2, "your total is ", totalR3p1) print("") print("") time.sleep(5) print(player2) time.sleep(3) print("") print("Dice rolling...") time.sleep(3) #this repeates the process for player 2 from random import * print("") P2R3N1= randint(1,6) P2R3N2= randint(1,6) if P2R3N1 == P2R3N2: P2R3N3= randint(1,6) P2R3N4= randint(1,6) totalR3p2= (P2R3N1 + P2R3N2 + P2R3N3 + P2R3N4) print("you rolled a double, you scored a ", P2R3N1, "and a ", P2R3N2, "so we gave you two more rolls you scored a : ", P2R3N3, "and a: ", P2R3N4, "These have been added to your original score your total is: ", totalR3p2) else: totalR3p2= (P2R3N1 + P2R3N2) print("you rolled a ", P2R3N1, "and a ",P2R3N2, "your total is ", totalR3p2) print("") time.sleep(3) if totalR3p1 > totalR3p2: print(player1, "wins round 3") else: print(player2, "wins round 3") print("") totalP1= (totalR1p1 + totalR2p1 + totalR3p1) print(player1, "your total score at the end of round 3 is ", totalP1) print("") totalP2= (totalR1p2 + totalR2p2 + totalR3p2) print(player2, "your total score at the end of round 3 is ", totalP2) print("") print("") print("Round 4") print("") print(player1) print("") time.sleep(3) print("Dice rolling...") time.sleep(3) print("") from random import * P1R4N1= randint(1,6) #this generates a random number for the first dice from 1 to 6 and stores it in playe 1 round 1 number 1 variable P1R4N2= randint(1,6) #this generates a random number for the first dice from 1 to 6 and stores it in playe 1 round 1 number 2 variable if P1R4N1 == P1R4N2: #if the dice have both the same number then both dice will role 2 new numbers P1R4N3= randint(1,6) P1R4N4= randint(1,6) totalR4p1= (P1R4N1 + P1R4N2 + P1R4N3 + P1R4N4) #these 2 new numbers will then be aded to form a total print("you rolled a double, you scored a ", P1R4N1, "and a ", P1R4N2, "so we gave you two more rolls you scored a : ", P1R4N3, "and a: ", P1R4N4, "These have been added to your original score your total is: ", totalR4p1) else: totalR4p1= (P1R4N1 + P1R4N2) #if the dice did not role two of the same numbers then the total of the dice are just added up and the total is outputed # it is then stored in the variable totalR1p1 which is the total for the players 1 round this will be later used to add up all of the players totals print("you rolled a ", P1R4N1, "and a ",P1R4N2, "your total is ", totalR4p1) print("") print("") time.sleep(5) print(player2) print("") time.sleep(3) print("Dice rolling...") print("") time.sleep(3) #this repeates the process for player 2 from random import * P2R4N1= randint(1,6) P2R4N2= randint(1,6) if P2R4N1 == P2R4N2: P2R4N3= randint(1,6) P2R4N4= randint(1,6) totalR4p2= (P2R4N1 + P2R4N2 + P2R4N3 + P2R4N4) print("you rolled a double, you scored a ", P2R4N1, "and a ", P2R4N2, "so we gave you two more rolls you scored a : ", P2R4N3, "and a: ", P2R4N4, "These have been added to your original score your total is: ", totalR4p2) else: totalR4p2= (P2R4N1 + P2R4N2) print("you rolled a ", P2R4N1, "and a ",P2R4N2, "your total is ", totalR4p2) print("") time.sleep(3) if totalR4p1 > totalR4p2: print(player1, "wins round 4") else: print(player2, "wins round 4") print("") totalP1= (totalR1p1 + totalR2p1 + totalR3p1 + totalR4p1) print(player1, "your total score at the end of round 4 is ", totalP1) print("") totalP2= (totalR1p2 + totalR2p2 + totalR3p2 + totalR4p2) print(player2, "your total score at the end of round 4 is ", totalP2) print("Round 5") print("") print(player1) time.sleep(3) print("") print("Dice rolling...") time.sleep(3) print("") from random import * P1R5N1= randint(1,6) #this generates a random number for the first dice from 1 to 6 and stores it in playe 1 round 1 number 1 variable P1R5N2= randint(1,6) #this generates a random number for the first dice from 1 to 6 and stores it in playe 1 round 1 number 2 variable if P1R5N1 == P1R5N2: #if the dice have both the same number then both dice will role 2 new numbers P1R5N3= randint(1,6) P1R5N4= randint(1,6) totalR5p1= (P1R5N1 + P1R5N2 + P1R5N3 + P1R5N4) #these 2 new numbers will then be aded to form a total print("you rolled a double, you scored a ", P1R5N1, "and a ", P1R5N2, "so we gave you two more rolls you scored a ", P1R5N3, "and a: ", P1R5N4, "These have been added to your original score your total is: ", totalR5p1) else: totalR5p1= (P1R5N1 + P1R5N2) #if the dice did not role two of the same numbers then the total of the dice are just added up and the total is outputed # it is then stored in the variable totalR1p1 which is the total for the players 1 round this will be later used to add up all of the players totals print("you rolled a ", P1R5N1, "and a ",P1R5N2, "your total is ", totalR5p1) print("") print("") time.sleep(5) print(player2) print("") time.sleep(3) print("Dice rolling...") print("") time.sleep(3) #this repeates the process for player 2 from random import * P2R5N1= randint(1,6) P2R5N2= randint(1,6) if P2R5N1 == P2R5N2: P2R5N3= randint(1,6) P2R5N4= randint(1,6) totalR5p2= (P2R5N1 + P2R5N2 + P2R5N3 + P2R5N4) print("you rolled a double, you scored a ", P2R5N1, "and a ", P2R5N2, "so we gave you two more rolls you scored a : ", P2R5N3, "and a: ", P2R5N4, "These have been added to your original score your total is ", totalR5p2) else: totalR5p2= (P2R5N1 + P2R5N2) print("you rolled a ", P2R5N1, "and a ",P2R5N2, "your total is ", totalR5p2) print("") time.sleep(3) if totalR5p1 > totalR5p2: print(player1, "wins round 5") else: print(player2, "wins round 5") print("") totalP1= (totalR1p1 + totalR2p1 + totalR3p1 + totalR4p1 + totalR5p1) print(player1, "your total score at the end of round 5 is ", totalP1) print("") totalP2= (totalR1p2 + totalR2p2 + totalR3p2 + totalR4p2 + totalR5p2) print(player2, "your total score at the end of round 5 is ", totalP2) if (totalP1 % 2) == 0: totalP1F = totalP1 + 10 print(player1, "your final score was even so you earned an extra 10 points! your final total is ", totalP1F) else: totalP1F = totalP1 - 5 print(player1, "your final score was odd so you lost 5 points! your final score is ", totalP1F) print("") if (totalP2 % 2) == 0: totalP2F = totalP2 + 10 print(player2, "your final score was even so you earned an extra 10 points! your final total is ", totalP2F) else: totalP2F = totalP2 - 5 print(player2, "your final score was odd so you lost 5 points! your final score is ", totalP2F) print("") if totalP1F > totalP2F: print(player1, "CONGRATULATIONS YOU WIN!") else: print(player2, "CONGRATULATIONS YOU WIN!")