Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import sys
- #making a login system
- counter = 0
- print("what is your username? ")
- user = ""
- leaderboard=[]
- file=open("leaderb.txt","r")
- for line in file:
- temp=line.split(",")
- leaderboard.append ([temp[0],int(temp[1])])
- file.close()
- while user != "kat":
- user = input()
- if user == "kat":
- print("username correct")
- else:
- print("username not recognized")
- counter = counter + 1
- if counter >=3:
- print ("you have run out of tries")
- sys.exit()
- else:
- tleft = 3 - counter
- print("you have " ,tleft, " try/tries left")
- print("what is your password?")
- password = ""
- while password != "a":
- password = input()
- if password == "a":
- print("access granted")
- else:
- print("access denied")
- counter = counter + 1
- if counter >=3:
- print ("you have run out of tries")
- sys.exit()
- else:
- tleft = 3 - counter
- print("you have " ,tleft, " try/tries left")
- print("login completed")
- #now ono the actual game
- p1=0
- p2=0
- turn=0
- while turn < 10 :
- rollq = input("player one, type 'go' to roll ")
- r1p1=random.randint(1,6)
- r2p1=random.randint(1,6)
- rollp1 = r1p1+r2p1
- if rollq == "go":
- turn = turn + 1
- p1 = p1 + rollp1
- else:
- print("player one, type 'go' to roll ")
- if rollp1 % 2 == 1:
- p1= p1 - 5
- else:
- p1= p1 + 10
- print("player 1 is at ",p1)
- rollq2 = input("player two, type 'go' to roll ")
- r1p2=random.randint(1,6)
- r2p2=random.randint(1,6)
- rollp2 = r1p2+r2p2
- if rollq2 == "go":
- turn = turn + 1
- p2 = p2 + rollp2
- else:
- print("player two, type 'go' to roll ")
- if rollp2 % 2 == 1:
- p2= p2 - 5
- else:
- p2= p2 + 10
- print("player 2 is at ",p2)
- if p1 > p2 :
- print("player one wins")
- elif p2 > p1 :
- print("player two wins")
- else:
- print("you tied,and now it's time for the tiebreaker")
- r1p1=random.randint(1,6)
- r2p1=random.randint(1,6)
- rollp1 = r1p1+r2p1
- r1p2=random.randint(1,6)
- r2p2=random.randint(1,6)
- rollp2 = r1p2+r2p2
- rollq = input("player one, type 'go' to roll ")
- if rollq == "go":
- turn = turn + 1
- p1 = p1 + rollp1
- else:
- print("player one, type 'go' to roll ")
- if rollp1 % 2 == 1:
- p1= p1 - 5
- else:
- p1= p1 + 10
- print("player 1 is at ",p1)
- rollq2 = input("player two, type 'go' to roll ")
- if rollq2 == "go":
- turn = turn + 1
- p2 = p2 + rollp2
- else:
- print("player two, type 'go' to roll ")
- if rollp2 % 2 == 1:
- p2= p2 - 5
- else:
- p2= p2 + 10
- print("player 2 is at ",p2)
- #onto the files
- if p1>p2 :
- user1 = input("player one please enter name of choice for leaderboard ")
- else:
- user2 = input("player two please enter name of choice for leaderboard ")
- if p1>p2 :
- leaderboard.append([user1,p1])
- else:
- leaderboard.append([user2,p2])
- sortedlist=sorted(leaderboard,key=lambda x:x[1], reverse=True)
- #now make a 'for line in sortedlist' to only print the top 5 from the leaderboard
- file=open("leaderb.txt","w")
- for score in leaderboard:
- file.write(score[0]+","+str(score[1])+"\n")
- file.close()
- for index in range(0,5):
- print(sortedlist[index])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement