-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoneybagg
91 lines (79 loc) · 3.15 KB
/
moneybagg
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
import random
class User:
def __init__(self, username, password, balance=0):
self.username = username
self.password = password
self.balance = balance
class Question:
def __init__(self, text, options, correct_option):
self.text = text
self.options = options
self.correct_option = correct_option
class Game:
def __init__(self):
self.questions = [] # List of Question objects
self.users = {} # Dictionary to store users
self.current_user = None
def add_question(self, question_text, options, correct_option):
question = Question(question_text, options, correct_option)
self.questions.append(question)
def register_user(self, username, password):
if username in self.users:
print("Username already exists. Please choose another one.")
else:
self.users[username] = User(username, password)
print("Registration successful!")
def login(self, username, password):
if username in self.users and self.users[username].password == password:
self.current_user = self.users[username]
print(f"Welcome back, {username}!")
else:
print("Invalid username or password.")
def play_game(self):
if not self.current_user:
print("Please login to play.")
return
score = 0
for question in random.sample(self.questions, 10):
print(question.text)
for i, option in enumerate(question.options):
print(f"{i+1}. {option}")
choice = int(input("Your choice: ")) - 1
if choice == question.correct_option:
score += 1
print("Correct!")
else:
print("Incorrect!")
break
if score == 10:
self.current_user.balance += 10000
print("Congratulations! You've won 10,000 Francs CFA!")
else:
print("Better luck next time!")
if __name__ == "__main__":
game = Game()
game.add_question("What is the capital of France?", ["Paris", "London", "Berlin"], 0)
game.add_question("What is the largest mammal?", ["Elephant", "Blue Whale", "Giraffe"], 1)
game.add_question("What is the chemical symbol for water?", ["H2O", "CO2", "NaCl"], 0)
# Add more questions here...
while True:
print("\n1. Register")
print("2. Login")
print("3. Play Game")
print("4. Exit")
choice = input("Enter your choice: ")
if choice == "1":
username = input("Enter username: ")
password = input("Enter password: ")
game.register_user(username, password)
elif choice == "2":
username = input("Enter username: ")
password = input("Enter password: ")
game.login(username, password)
elif choice == "3":
game.play_game()
elif choice == "4":
print("Exiting...")
break
else:
print("Invalid choice. Please try again.")