-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
128 lines (117 loc) · 4.96 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import time
import random
import os
print("Developed by Yash Mittal. \nVisit https://yashmittalz.github.io for more projects. \n")
print("Version 1.0")
loose = ("The computer wins")
win = ("You win")
lives = 5
score = 0
drew = 0
computer_lives = 7
password_list = []
def display_rules():
print("*******************************")
print(" RULES ")
print("*******************************")
print("-Rock looses against Paper")
print("-Rock beats Scissors")
print("-Paper beats Rock")
print("-Paper looses against Scissors")
print("-Scissors beats Paper")
print("-Scissors looses against Rock")
print("*******************************")
def end_game():
# Clear the terminal
os.system('cls' if os.name == 'nt' else 'clear')
print("Game Over!")
def get_user_choice():
while True:
rps = input("Rock, Paper, Scissors? ").lower()
if rps in ["rock", "paper", "scissors", "!help", "!lives", "!score", "!drew", "exit"]:
return rps
else:
print("Invalid choice. Please choose Rock, Paper, Scissors, or a command.")
def determine_winner(rps, computer):
if rps == computer:
return "draw"
elif (rps == "rock" and computer == "scissors") or \
(rps == "paper" and computer == "rock") or \
(rps == "scissors" and computer == "paper"):
return "win"
elif (rps == "rock" and computer == "paper") or \
(rps == "paper" and computer == "scissors") or \
(rps == "scissors" and computer == "rock"):
return "lose"
while True:
print("----------------------------------------")
print("To begin fill in the below information.")
print("----------------------------------------\n")
username = input("Please enter your username: ")
password = input("Please enter your password: ")
with open("accounts.txt", "r") as searchfile:
# Read accounts and check for valid username and password
password_list = [line.strip().split(":") for line in searchfile] # Split lines into username and password
# Check if the entered username and password match any entry
if any(user == username and pwd == password for user, pwd in password_list):
print("----------------------------------------")
print("Access Granted")
time.sleep(0.5)
print("Loading.")
time.sleep(0.5)
print("Loading..")
time.sleep(0.5)
print("Loading...\n")
time.sleep(0.5)
print("Rules")
print("----------------------------------------")
print("You start with",lives,"lives")
print("If you win you get an extra life.")
print("If you loose you loose a life.")
print("If you draw, the lives stay the same")
print("The computer has lives as well.")
print("----------------------------------------")
print("How to win? Type '!help'")
print("Stop playing? Type 'exit'")
print("Lives check? Type '!lives'")
print("Draw check? Type '!drew'")
print("Score check? Type '!score'")
print("----------------------------------------")
time.sleep(1)
print("Good Luck!!")
# Start of the game
while True:
rps = get_user_choice()
computer = random.choice(["rock", "paper", "scissors"])
if rps == "!help":
display_rules()
elif rps == "!lives":
print("remaining lives: ",lives)
elif rps == "!score":
print("Your score: ", score)
elif rps == "!drew":
print("You have drawn: ",drew, "times")
else:
result = determine_winner(rps, computer)
if result == "win":
print(f"The computer chose {computer}. You win!")
score += 1
elif result == "lose":
print(f"The computer chose {computer}. You lose!")
lives -= 1
else:
print(f"The computer chose {computer}. It's a draw!")
drew +=1
# Display current score and lives
print(f"Score: {score}, Lives: {lives}")
if lives == 0 or computer_lives == 0:
end_game()
print(f"You got {score} correct and drew {drew} times.")
input("Press enter to exit.")
exit()
#exit
if rps == "exit":
break
else:
print("\nYour username or password is incorrect.")
break