Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """CSV is used for the login system. Random / Randint is used for the dice"""
- import csv
- from random import randint
- #########################################################################################
- # Authenticator #
- #########################################################################################
- def importCredentials():
- """Read the user's usernames & password in the csv file"""
- with open ('Credentials.csv', 'r') as myFile:
- reader = csv.reader(myFile)
- Credentials = list(reader)
- return Credentials
- def userLogin():
- """Get useranme & password"""
- print("Player 1, please enter your credentials")
- print("")
- username = input("Please enter your username: ")
- password = input ("Please enter your password: ")
- print("")
- print("Player 2, please enter your credentials")
- print("")
- username2 = input("Please enter your username: ")
- password2 = input ("Please enter your password: ")
- return username, password, username2, password2
- def searchList(uname, pword, uname2, pword2, clist):
- """ valid is set to false by default"""
- valid = False
- player1 = False
- player2 = False
- """Get uname and pword from range with in clist"""
- for x in range (0, len(clist)):
- if uname == clist[x][0]:
- if pword == clist[x][1]:
- player1 = True
- if uname2 == clist[x][0]:
- if pword2 == clist[x][1]:
- player2 = True
- if player1 == True and player2 == True:
- valid = True
- break
- else:
- valid = False
- return valid
- """Instead of having two for loops used IF statements"""
- # for i in range (0, len(clist)):
- # if uname2 == clist[i][0]:
- # if pword2 == clist[i][1]:
- # valid = True
- # break
- # else:
- # valid = False
- # return valid
- def main():
- """Outputs x onto python shell"""
- Credentials = importCredentials()
- """Get username and password"""
- username, password, username2, password2 = userLogin()
- """checks if username in searchlist is valid"""
- valid = searchList(username, password, username2, password2, Credentials)
- if valid == True:
- #Added spaces to make the UI look nicer
- print("")
- print("────────────────────────────────────────"
- "────────────────────────────────────────"
- "───────────████──███────────────────────"
- "──────────█████─████────────────────────"
- "────────███───███───████──███───────────"
- "────────███───███───██████████──────────"
- "────────███─────███───████──██──────────"
- "─────────████───████───███──██──────────"
- "──────────███─────██────██──██──────────"
- "──────██████████────██──██──██──────────"
- "─────████████████───██──██──██──────────"
- "────███────────███──██──██──██──────────"
- "────███─████───███──██──██──██──────────"
- "───████─█████───██──██──██──██──────────"
- "───██████───██──────██──────██──────────"
- "─████████───██──────██─────███──────────"
- "─██────██───██─────────────███──────────"
- "─██─────███─██─────────────███──────────"
- "─████───██████─────────────███──────────"
- "───██───█████──────────────███──────────"
- "────███──███───────────────███──────────"
- "────███────────────────────███──────────"
- "────███───────────────────███───────────"
- "─────████────────────────███────────────"
- "──────███────────────────███────────────"
- "────────███─────────────███─────────────"
- "────────████────────────██──────────────"
- "──────────███───────────██──────────────"
- "──────────████████████████──────────────"
- "──────────████████████████──────────────"
- "────────────────────────────────────────"
- "────────────────────────────────────────")
- print("")
- else:
- print("")
- print("User not valid or found")
- print("")
- main()
- #Testing to see if usernames & passwords would read and print them in py shell
- #for x in Credentials:
- #print(x)
- main()
- #########################################################################################
- # Authenticator #
- #########################################################################################
- #########################################################################################
- #########################################################################################
- # Dice #
- #########################################################################################
- def dice_even():
- """When an even number is rolled 10 will be added to the current value"""
- value = 10
- return(value)
- def dice_odd():
- """When an odd number is rolled 5 will be taken away from the current value"""
- value = -5
- return(value)
- def dice_roll():
- """count is set to 1 by deafult & score is set to 0 by default"""
- count = 1
- score = 0
- while count < 3:
- print("\n")
- print("Shaking dice\n")
- print("Rolling...")
- print("Rolling..")
- print("Rolling.")
- dice = random.randint(1,6)
- print("Dice", count, "thrown score is", dice, "\n")
- score = score + dice
- count = count + 1
- if score%2 == 0:
- print("an even number was thrown")
- score = dice_even()
- #print(score) | Testing score due to a logic error which has been fixed
- else:
- print("an even number was thrown")
- score = dice_odd()
- #print(score) | Testing score due to a logic error which has been fixed
- return(score)
- def dice_main(username, username2):
- """All states of been assigned to false or 0 by deafault"""
- play = False
- p1Score = 0
- p2Score = 0
- p1RoundScore = 0
- p2RoundScore = 0
- dice_player1 = username # dice_player1 will call
- dice_player2 = username2
- gameRound = 0
- while gameRound < 5: # 0 - 5 | Zero is registered as number '1'
- p1RoundScore = dice_roll()
- p2RoundScore = dice_roll()
- p1Score = p1Score + p1RoundScore
- if p1Score <= 0:
- p1Score = 0
- p2Score = p2Score + p2RoundScore
- if p2Score <= 0:
- p2Score = 0
- gameRound = gameRound + 1
- input("Press enter to start next round")
- print(p1Score, p2Score)
- print("a")
- print("b")
- print("c")
- print("d")
- print("#" * 25)
- #print("p1 score= ",p1Score)
- #print("p2 score= ",p2Score)
- if p1Score > p2Score:
- print(dice_player1, "Win")
- elif p2Score > p1Score:
- print(dice_player2, "Win")
- else:
- print("draw")
- print(p1Score, p2Score)
- dice_main()
- #########################################################################################
- # Dice #
- #########################################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement