-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
67 lines (56 loc) · 2.14 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
from games import RockPaperScissors
from login import LoginController
from games import HangMan
def main():
controller = LoginController()
logged_in_user = None
while True:
print("\n1. Register")
print("2. Login")
print("3. Quit")
choice = input("Enter your choice: ")
if choice == "1":
username = input("Enter username: ")
password = input("Enter password: ")
if controller.register_user(username, password):
print("User registered successfully.")
elif choice == "2":
username = input("Enter username: ")
password = input("Enter password: ")
if controller.login(username, password):
print("Login successful!")
logged_in_user = username
# Start game loop after successful login
play_game(controller, logged_in_user)
elif choice == "3":
print("Exiting program.")
return
else:
print("Invalid choice. Please enter 1, 2, or 3.")
def play_game(controller, username):
allGames = [
{"id": "1", "title": "Rock Paper Scissors",
"game": RockPaperScissors.main, "score": 5},
{"id": "2", "title": "HangMan", "game": HangMan.hangman, "score": 5}
]
while True:
print(f"\nWelcome, {username}!")
print(f"Your score: {controller.get_user_score(username)}")
print('\nOur All Games! Select the number of it to select.')
for game in allGames:
print(game["id"], ":", game["title"])
input_no = input("\nYour Choice: ")
if not input_no:
return False
try:
input_no = int(input_no)
if 1 <= input_no <= len(allGames):
selected_game = allGames[input_no - 1]["game"]
selected_game(username, allGames[input_no - 1])
else:
print(
"Invalid choice. Please select a number between 1 and", len(allGames))
except ValueError:
print("Invalid input. Please enter a number.")
if __name__ == "__main__":
main()