Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import csv
- import time
- def username1():
- while True:
- username1 = input("What username would you like to have? ")
- if len(username1) < 8:
- print("Your username must have more than 8 characters")
- continue
- else:
- print("Your username has the correct amount of characters")
- if username1.upper == username1 or username1.lower() == username1:
- print("Your username must contain both upper and lowercase letters")
- continue
- else:
- print("Your username has upper and lowercase letters")
- file = open("accountinfo.txt","a")
- file.write("Player 1 Username: ")
- file.write(username1)
- file.write("\n")
- file.close()
- break
- def password1():
- while True:
- password1 = input("What password would you like? ")
- if len(password1) < 8:
- print("Your password must have more than 8 characters")
- continue
- else:
- print("Your password has the correct amount of characters")
- if password1.upper == password1 or password1.lower() == password1:
- print("Your password must contain both upper and lowercase letters")
- continue
- else:
- print("Your password has upper and lowercase letters")
- file = open("accountinfo.txt","a")
- file.write("Player 1 Password: ")
- file.write(password1)
- file.write("\n")
- file.close()
- break
- def username2():
- while True:
- username2 = input("What username would you like to have? ")
- if len(username2) < 8:
- print("Your username must have more than 8 characters")
- continue
- else:
- print("Your username has the correct amount of characters")
- if username2.upper == username2 or username2.lower() == username2:
- print("Your username must contain both upper and lowercase letters")
- continue
- else:
- print("Your username has upper and lowercase letters")
- file = open("accountinfo.txt","a")
- file.write("Player 2 Username: ")
- file.write(username2)
- file.write("\n")
- file.close()
- break
- def password2():
- while True:
- password2 = input("What password would you like? ")
- if len(password2) < 8:
- print("Your password must have more than 8 characters")
- continue
- else:
- print("Your password has the correct amount of characters")
- if password2.upper == password2 or password2.lower() == password2:
- print("Your password must contain both upper and lowercase letters")
- continue
- else:
- print("Your password has upper and lowercase letters")
- file = open("accountinfo.txt","a")
- file.write("Player 2 Password: ")
- file.write(password2)
- file.write("\n")
- file.close()
- break
- def game():
- while True:
- player1 = input("Player 1 Username = ") # Asks player 1 to input a variable
- player1pass = input("Player 1 Password = ") # Asks Player 1 to input a variable
- print("You've successfully logged in.")
- player2 = input("Player 2 Username = ") # Asks player 2 to input a variable
- player2pass = input("Player 2 Password = ") # Asks player 2 to input another variable
- print("You've successfully logged in.")
- player1=0
- player2=0
- print("Player 1 Ready?")
- print("Player 2 Ready?")
- print("-----------------------------------------------------")
- totalscore1=0
- totalscore2=0
- dice1 = random.randint(1,6)
- dice2 = random.randint(1,6)
- roundno = 1
- while roundno < 2:
- totalscore1=totalscore1+player1
- totalscore2=totalscore2+player2
- player1=dice1+dice2
- roundno=roundno+1
- print("Round",roundno)
- time.sleep(1)
- roll = input("Player 1, please press enter to roll")
- print("Player 1 is rolling")
- print("Player 1's first roll is",dice1)
- time.sleep(1)
- print("Player 1's second roll is",dice2)
- time.sleep(1)
- if player1 %2==0:
- print("This is an even number. so +10 points")
- time.sleep(1)
- player1=player1+10
- time.sleep(1)
- print("Score is",player1)
- if player1<= 0:
- print("You have lost the game")
- sys.exit()
- else:
- print("This is an odd number.")
- time.sleep(2)
- player1=player1-5
- print("Score is",player1)
- time.sleep(3)
- print("Player 1 score",player1)
- print("-----------------------------------------------------")
- time.sleep(1)
- #player 2
- dice1 = random.randint(1,6)
- dice2 = random.randint(1,6)
- totalscore1=totalscore1+player1
- totalscore2=totalscore2+player2
- player2=dice1+dice2
- print("-----------------------------------------------------")
- roll = input("Player 2 press enter to roll")
- print("Player 2 is rolling")
- time.sleep(1)
- print("Player 2's first roll is",dice1)
- time.sleep(1)
- roll = input("Player 2 press enter to roll again")
- time.sleep(1)
- print("Player 2's second roll is",dice2)
- time.sleep(1)
- if player2 %2==0:
- print("This is an even number. so +10 points")
- time.sleep(1)
- player2=player2+10
- print("Score is",player2)
- time.sleep(1)
- if player2<= 0:
- print("You have lost the game")
- sys.exit()
- else:
- print("This is an odd number.")
- time.sleep(1)
- player2=player2-5
- print("Score is",player2)
- time.sleep(3)
- print("Player 2 score",player2)
- print("-----------------------------------------------------")
- print("The total score for player 1 is ",totalscore1)
- print("The total score for player 2 is ",totalscore2)
- if totalscore1 > totalscore2:
- print("Player 1 Wins!")
- file = open("scores.txt","a")
- file.write(int(player1))
- file.write(" has ")
- file.write(str(totalscore1))
- file.write(" points")
- file.write("\n")
- file.close()
- if totalscore2 > totalscore1:
- print("Player 2 Wins!")
- file = open("scores.txt","a")
- file.write(int(player2))
- file.write(" has ")
- file.write(str(totalscore2))
- file.write(" points")
- file.write("\n")
- file.close()
- #username1()
- #password1()
- #username2()
- #password2()
- game()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement