-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore.py
More file actions
36 lines (31 loc) · 1022 Bytes
/
Copy pathcore.py
File metadata and controls
36 lines (31 loc) · 1022 Bytes
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
import time
import random
class Game:
def __init__(self):
self.score = 0
self.high_score = 0
self.running = True
def play_round(self):
start_time = time.time()
outcome = random.choice([True, False])
if outcome:
self.score += 10
print('Round won!')
else:
print('Round lost!')
elapsed_time = time.time() - start_time
print(f'Time taken for round: {elapsed_time:.2f} seconds')
self.update_high_score()
def update_high_score(self):
if self.score > self.high_score:
self.high_score = self.score
print('New high score!')
def reset_game(self):
print('Resetting game...')
self.score = 0
def start(self):
while self.running:
self.play_round()
if input('Play another round? (y/n): ').lower() != 'y':
self.running = False
print(f'Final score: {self.score}, High score: {self.high_score}')