This commit is contained in:
2024-09-22 16:11:29 +01:00
parent 8752ceeb63
commit 885a44be11

136
main.py
View File

@ -87,35 +87,119 @@ class Game():
def roll_laps(self):
self.laps = roll(-2)
def get_obstacle_index(self):
return self.round % len(self.track.obstacles)
def get_obstacle(self):
return self.track.obstacles[self.get_obstacle_index()]
def is_new_lap(self):
return True if self.get_obstacle_index() == 0 and self.round != 0 else False
def play_round(self):
print(f"Round {self.round} | Lap {self.current_lap}/{self.laps}")
if self.round == 0:
p1_roll = self.p1.roll(Stats.SPD)
p2_roll = self.p2.roll(Stats.SPD)
print("Green flag, the race has started")
if p1_roll > p2_roll:
print(f"{self.p1.name} gets a good start and takes the lead")
self.p1.SP += 1
self.leader = self.p1
self.lead += 1
elif p2_roll > p1_roll:
print(f"{self.p2.name} gets a good start and takes the lead")
self.p2.SP += 1
self.leader = self.p2
self.lead += 1
if self.is_new_lap():
self.current_lap += 1
if self.current_lap > self.laps:
print("It's over!")
print("")
print("\tSUMMARY:")
if self.leader:
print(f"\t\tWINNER: {self.leader.name} by +{self.lead}")
else:
print("Both drivers get a good start and they're neck and neck")
print(f"\t\tWINNER: A DRAW!")
print(f"--- {self.p1.name} ---")
print(f"SP: {self.p1.SP}")
print("")
print(f"--- {self.p2.name} ---")
print(f"SP: {self.p2.SP} ---")
else:
obstacle_index = self.round % len(self.track.obstacles)
if obstacle_index == 0 and self.round != 0:
self.current_lap += 1
if self.current_lap == self.laps:
print("its over")
obstacle = self.track.obstacles[obstacle_index]
print(obstacle.name)
sleep(1)
self.round += 1
self.play_round()
print("========================================================")
print(f"Round {self.round} | Lap {self.current_lap}/{self.laps}")
print("--------------------------------------------------------")
if self.round == 0:
p1_roll = self.p1.roll(Stats.SPD)
p2_roll = self.p2.roll(Stats.SPD)
print("Green flag, the race has started")
if p1_roll > p2_roll:
print(f"{self.p1.name} gets a good start and takes the lead")
self.p1.SP += 1
self.leader = self.p1
self.lead = 1
elif p2_roll > p1_roll:
print(f"{self.p2.name} gets a good start and takes the lead")
self.p2.SP += 1
self.leader = self.p2
self.lead = 1
else:
print("Both drivers get a good start and they're neck and neck")
else:
obstacle = self.get_obstacle()
print(obstacle.name)
obstacle_roll = roll(4)
p1_roll = self.p1.roll(obstacle.stat, obstacle.skill)
p2_roll = self.p2.roll(obstacle.stat, obstacle.skill)
print(f"{self.p1.name} vs {obstacle.name}")
print(f"{p1_roll} vs {obstacle_roll}")
if p1_roll > obstacle_roll:
self.p1.SP += 1
print(f"> {self.p1.name} gains 1 SP for a total of {self.p1.SP}!")
if self.leader == self.p1:
self.lead += 1
print(f"> {self.p1.name}'s lead extends to +{self.lead}")
elif self.leader == None:
self.leader = self.p1
self.lead = 1
print(f"> {self.p1.name} takes the lead")
elif self.leader == self.p2:
self.lead -= 1
if self.lead == 0:
self.leader = None
print(f"> {self.p1.name} negates {self.p2.name}'s lead. It's neck and neck.")
else:
print(f"> {self.p1.name} reduces {self.p2.name}'s lead to +{self.lead}.")
else:
if self.leader == self.p1 and p2_roll > p1_roll:
self.lead -= 1
if self.lead > 0:
print(f"> {self.p1.name}'s lead drops to +{self.lead}")
else:
self.leader = None
print(f"> {self.p1.name} loses their lead")
print(f"{self.p2.name} vs {obstacle.name}")
print(f"{p2_roll} vs {obstacle_roll}")
if p2_roll > obstacle_roll:
self.p2.SP += 1
print(f"> {self.p2.name} gain 1 SP for a total of {self.p2.SP}!")
if self.leader == self.p2:
self.lead += 1
print(f"> {self.p2.name}'s lead extends to +{self.lead}")
elif self.leader == None:
self.leader = self.p2
self.lead = 1
print(f"> {self.p2.name} takes the lead")
elif self.leader == self.p1:
self.lead -= 1
if self.lead == 0:
self.leader = None
print(f"> {self.p2.name} negates {self.p1.name}'s lead. It's neck and neck.")
else:
print(f"> {self.p2.name} reduces {self.p1.name}'s lead to +{self.lead}.")
else:
if self.leader == self.p2 and p1_roll > p2_roll:
self.lead -= 1
if self.lead > 0:
print(f"> {self.p2.name}'s lead drops to +{self.lead}")
else:
self.leader = None
print(f"> {self.p2.name} loses their lead")
sleep(5)
self.round += 1
self.play_round()
player1 = Player("Player 1", 3, 2, 1, Skills.FM)
player2 = Player("Player 2", 1, 3, 2, Skills.TM)