import random
class ErrorWithName(Exception):
pass
class NonCompliant(Exception):
pass
class NotApplicable(Exception):
pass
class DeathError(Exception):
pass
class Person:
def __init__(self):
self.health = 5
self.name = ""
self.hunger = 5
def assignName(self, name):
self.name = name
def takeDamage(self, dmgAmnt):
self.health = dmgAmnt
def makeHungry(self, hungryAmount):
self.hunger -= hungryAmount
def heal(self):
self.health = 5
def feed(self):
self.hunger += 1
if self.hunger >= 5:
self.hunger = 5
def checkIfDead():
if party1.health == 0 and party2.health == 0 and party3.health == 0 and party4.health == 0 and party5.health == 0:
return True
def HandleDay(day, amntPeople, toGo, traveled, food):
print("-" * 8, end=" ")
print(f"Day {day}", end=" ")
print("-" * 8)
print("\nToday is a new day!")
print(f"You have traveled {traveled} of {toGo} units.")
print(f"You currently have {food} of 10 rations.")
print(f"You currently have {healPacks} of 3 Heal Packs.")
def OptionsMenu():
print("What will your party do?")
print("(1) Hunt\n(2) Heal\n(3) Feed\n(4) Craft\n(5) Check Party Stats\n(6) End Day and Continue On.")
choice = int(input())
if choice == 1:
return 1
elif choice == 2:
return 2
elif choice == 3:
return 3
elif choice == 4:
return 4
elif choice == 5:
return 5
elif choice == 6:
return 6
else:
return -1
def Hunt():
global amntFood
global hasHunted
print("Who will hunt?")
print(f"(1) {names[0]}\n(2) {names[1]}\n(3) {names[2]}\n(4) {names[3]}\n(5) {names[4]}")
hunterChosen = int(input())
if hunterChosen == 1 and party1.health > 0:
party1.makeHungry(random.randint(2,5))
elif hunterChosen == 2 and party2.health > 0:
party2.makeHungry(random.randint(2,5))
elif hunterChosen == 3 and party3.health > 0:
party3.makeHungry(random.randint(2,5))
elif hunterChosen == 4 and party4.health > 0:
party4.makeHungry(random.randint(2,5))
elif hunterChosen == 5 and party5.health > 0:
party5.makeHungry(random.randint(2,5))
elif hunterChosen < 1 or hunterChosen > 5:
raise NotApplicable("Party member does not exist, please pick 1-5.")
else:
raise DeathError("Party member has died and cannot hunt")
print(f"{names[hunterChosen - 1]} was sent out to go hunt.")
randopt = random.randint(0, 2)
if randopt == 1:
print(f"{names[hunterChosen-1]} made it back safely.")
elif randopt == 2:
print(f"{names[hunterChosen-1]} made it back safely.")
else:
print(f"{names[hunterChosen-1]} Came back feeling a little worse.")
if hunterChosen == 1:
party1.takeDamage(random.randint(1, 2))
elif hunterChosen == 2:
party2.takeDamage(random.randint(1, 2))
elif hunterChosen == 3:
party3.takeDamage(random.randint(1, 2))
elif hunterChosen == 4:
party4.takeDamage(random.randint(1, 2))
elif hunterChosen == 5:
party5.takeDamage(random.randint(1, 2))
addfoodamnt = random.randint(2, 4)
print(f"{names[hunterChosen-1]} brought back {addfoodamnt} rations.")
if amntFood + addfoodamnt >= 10:
print("But you can't hold more than 10 rations, so the excess was discarded.")
amntFood = 10
else:
amntFood = amntFood + addfoodamnt
hasHunted = True
def healPartyMember():
global healPacks
print("Who will be healed?")
print(f"(1) {names[0]} - {party1.health}/5\n(2) {names[1]} - {party2.health}/5\n(3) {names[2]} - {party3.health}/5\n(4) {names[3]} - {party4.health}/5\n(5) {names[4]} - {party5.health}/5")
healChosen = int(input())
if healChosen == 1 and party1.health > 0:
party1.heal()
elif healChosen == 2 and party2.health > 0:
party2.heal()
elif healChosen == 3 and party3.health > 0:
party3.heal()
elif healChosen == 4 and party4.health > 0:
party4.heal()
elif healChosen == 5 and party5.health > 0:
party5.heal()
elif healChosen < 1 or healChosen > 5:
raise NotApplicable("Party member does not exist, please pick 1-5.")
else:
raise DeathError("Party member has died and cannot be healed")
healPacks -= 1
print(f"{names[healChosen - 1]}'s HP was raised to 5/5!")
def feedPartyMember():
global amntFood
print("Who will be fed?")
feedChosen = 0
while feedChosen !=6:
print(f"Amount of Rations remaining: {amntFood}")
print(f"(1) {names[0]} - {party1.hunger}/5\n(2) {names[1]} - {party2.hunger}/5\n(3) {names[2]} - {party3.hunger}/5\n(4) {names[3]} - {party4.hunger}/5\n(5) {names[4]} - {party5.hunger}/5\n(6) Stop Feeding")
feedChosen = int(input())
if feedChosen == 1 and party1.health > 0:
party1.feed()
amntFood -= 1
elif feedChosen == 2 and party2.health > 0:
party2.feed()
amntFood -= 1
elif feedChosen == 3 and party3.health > 0:
party3.feed()
amntFood -= 1
elif feedChosen == 4 and party4.health > 0:
party4.feed()
amntFood -= 1
elif feedChosen == 5 and party5.health > 0:
party5.feed()
amntFood -= 1
elif feedChosen < 1 or feedChosen > 5:
raise NotApplicable("Party member does not exist, please pick 1-5.")
else:
raise DeathError("Party member has died and cannot be fed")
def craftHealthKits():
global healPacks
global amntFood
print("5 Rations are required to craft 1 Health Pack.")
print("Craft a Health Pack?\n(1) Yes\n(2) No")
healChosen = int(input())
if healChosen == 1:
amntFood -= 5
healPacks += 1
print(f"Your party crafted a Health Pack. They now have {healPacks}/3 Health Packs and {amntFood}/10 Rations.")
else:
print("Your party did not craft a Health Pack.")
def listStats():
if party1.health !=0:
print(f"{party1.name}: {party1.health}/5 HP, {party1.hunger}/5 Fullness")
else:
print(f"{party1.name}: Dead")
if party2.health !=0:
print(f"{party2.name}: {party2.health}/5 HP, {party2.hunger}/5 Fullness")
else:
print(f"{party2.name}: Dead")
if party3.health !=0:
print(f"{party3.name}: {party3.health}/5 HP, {party3.hunger}/5 Fullness")
else:
print(f"{party3.name}: Dead")
if party4.health !=0:
print(f"{party4.name}: {party4.health}/5 HP, {party4.hunger}/5 Fullness")
else:
print(f"{party4.name}: Dead")
if party5.health !=0:
print(f"{party5.name}: {party5.health}/5 HP, {party5.hunger}/5 Fullness")
else:
print(f"{party5.name}: Dead")
def randomSplashText():
randomsplashchance = random.randint(1,10)
if randomsplashchance == 1:
return "Your party stopped for ice cream. They enjoyed it."
elif randomsplashchance == 2:
return "The DMV was not too kind to your party. They don't want to go there again."
elif randomsplashchance == 3:
return "One of the party members had Justin Beiber's \"Baby\" playing for about 30 miles. Nobody was happy with this decision."
elif randomsplashchance == 4:
return "Your party members wanted to stop at Chuy\'s, but forgot that they're playing a stupid python game."
elif randomsplashchance == 5:
return "Your party members stopped at an arcade. Everyone had a great time!"
elif randomsplashchance == 6:
return "These random Splash messages, is this feature creep?"
elif randomsplashchance == 7:
return "Your party members talk about the Aristotle of our time, Dr. Michael Kolta."
elif randomsplashchance == 8:
return "Your party members think that Computer Science is cool, and they are RIGHT!"
elif randomsplashchance == 9:
return "When all else fails, spend 7 hours trying to automate it in Python. If that doesn't work, give up and cry."
elif randomsplashchance == 10:
return "Your party thinks that ChatGPT could never."
def statCheck():
# handle HP
if party1.health <= 0:
party1.health = 0
party1.hunger = 0
elif party2.health <= 0:
party2.health = 0
party2.hunger = 0
elif party3.health <= 0:
party3.health = 0
party3.hunger = 0
elif party4.health <= 0:
party4.health = 0
party4.hunger = 0
elif party5.health <= 0:
party5.health = 0
party5.hunger = 0
# handle hunger
if party1.hunger <= 0:
party1.hunger = 0
elif party2.hunger <= 0:
party2.hunger = 0
elif party3.hunger <= 0:
party3.hunger = 0
elif party4.hunger <= 0:
party4.hunger = 0
elif party5.hunger <= 0:
party5.hunger = 0
day = 1
numOfPeople = 5
distanceToTravel = 1000
gameOver = False
distanceTraveled = 0
amntFood = random.randint(5, 10)
healPacks = random.randint(0,1)
choiceMain = 0
hasHunted = False
dayComplete = False
while gameOver != True:
try:
print("Welcome to the Florida Trail.")
print("Name 5 people to go on this journey:")
names = input().split()
if len(names) < 5:
print("You need at least 5 people to go on this journey.")
raise ErrorWithName("Try again. (Input type: \"one two three four five\")")
elif len(names) > 5:
print("You cannot have more than 5 people on this journey.")
raise ErrorWithName("Try again. (Input type: \"one two three four five\")")
else:
party1 = Person()
party1.assignName(names[0])
party2 = Person()
party2.assignName(names[1])
party3 = Person()
party3.assignName(names[2])
party4 = Person()
party4.assignName(names[3])
party5 = Person()
party5.assignName(names[4])
print(f"Accepted names. Let's begin.")
print("-" * 16)
# Game Start
for i in range(4):
print(names[i], end=", ")
print("and " + names[4], end=" ")
print("embark on a journey down the Florida Trail.")
sport = random.randint(1, 5)
if sport == 1:
sport = "Dolphins"
location = "Miami"
elif sport == 2:
sport = "Tampa Bay Lightning"
location = "Tampa"
elif sport == 3:
sport = "Miami Heat"
location = "Miami"
elif sport == 4:
sport = "Marlins"
location = "Miami"
elif sport == 5:
sport = "Sailfish"
location = "West Palm Beach"
print(f"Their journey takes them from The Panhandle to {location} for the {sport} game.")
print("Make sure to get them there safely!")
while day <= 7 and gameOver != True:
statCheck()
isdeadcheck = checkIfDead()
if isdeadcheck == True:
gameOver = True
break
HandleDay(day, numOfPeople, distanceToTravel, distanceTraveled, amntFood)
print("\n", randomSplashText(), "\n")
try:
while choiceMain != 6:
choiceMain = OptionsMenu()
if choiceMain == 1:
choiceMain = 0
if not hasHunted:
Hunt()
else:
print("You've already hunted today, give your party members a break.")
elif choiceMain == 2:
choiceMain = 0
if healPacks == 0:
print("You don't have any healing packs. You can get more with the Craft option.")
else:
healPartyMember()
elif choiceMain == 3:
choiceMain = 0
if amntFood > 0:
feedPartyMember()
else:
print("There are no rations in storage. Hunt to get more.")
elif choiceMain == 4:
choiceMain = 0
if amntFood >= 5:
craftHealthKits()
else:
print(f"Your party does not have enough Rations to craft a Health Pack. (5 needed, {amntFood} Rations)")
elif choiceMain == 5:
choiceMain = 0
listStats()
elif choiceMain == -1:
choiceMain = 0
raise NonCompliant("Please pick a valid option. ")
choiceMain = 0
print(f" Ended Day {day}")
movementAmnt = random.randint(125, 200)
print(f"Your party managed to travel {movementAmnt} units.")
distanceTraveled = distanceTraveled + movementAmnt
day += 1
hasHunted = False
if party1.hunger == 0:
party1.health -= 1
if party1.health == 0:
print(f"{party1.name} has starved to death. Shoulda got them those good Mickey pancakes from Chef Mickey's Cafe.")
else:
print(f"{party1.name} is starving! Feed ASAP, or they will lose more HP.")
if party2.hunger == 0:
party2.health -= 1
if party2.health == 0:
print(f"{party2.name} has starved to death. Google told me Beer is the most popular food in Florida, why didn't you just have that?")
else:
print(f"{party2.name} is starving! Feed ASAP, or they will lose more HP.")
if party3.hunger == 0:
party3.health -= 1
if party3.health == 0:
print(f"{party3.name} has starved to death. When was the last time you saw a McDonald's?")
else:
print(f"{party3.name} is starving! Feed ASAP, or they will lose more HP.")
if party4.hunger == 0:
party4.health -= 1
if party4.health == 0:
print(f"{party4.name} has starved to death. You guys passed like 7 Texmex places. what happened?")
else:
print(f"{party4.name} is starving! Feed ASAP, or they will lose more HP.")
if party5.hunger == 0:
party5.health -= 1
if party5.health == 0:
print(f"{party5.name} has starved to death. Where was the Waffle House?.")
else:
print(f"{party5.name} is starving! Feed ASAP, or they will lose more HP.")
print("Overnight, your party", end=" ")
randomnumber = random.randint(1, 5)
if randomnumber == 1:
randomchance = random.randint(1, 4)
print("got into a crazy accident", end="")
if randomchance == 1:
randomparty = random.randint(1, 5)
if randomparty == 1:
party1.health = 0
elif randomparty == 2:
party2.health = 0
elif randomparty == 3:
party3.health = 0
elif randomparty == 4:
party4.health = 0
elif randomparty == 5:
party5.health = 0
print("and completely wiped out. They all died.")
gameOver = True
checkIfDead()
else:
print(", but everything was okay.")
elif randomnumber == 2:
# finds either food or health
randomchance = random.randint(1, 4)
if randomchance == 1:
amntFood += random.randint(1, 3)
if amntFood >= 10:
amntFood = 10
print(f"got super lucky and found a some Rations! Ration storage is now {amntFood}!")
elif randomchance == 2:
healPacks += 1
if healPacks >= 3:
healPacks = 3
print(f"got super lucky and found a Health Pack! Health Pack storage is now {healPacks}!")
elif randomchance == 3:
healPacks = 0
print(f"got unlucky and lost all their Health Packs. Health Pack storage is now {healPacks}")
else:
amntFood = 0
print(f"got unlucky and lost all their Rations. Ration storage is now {amntFood}")
elif randomnumber == 3:
randomchance = random.randint(1, 4)
if randomchance == 1:
party1.health = 5
party2.health = 5
party3.health = 5
party4.health = 5
party5.health = 5
print("had a GREAT night's sleep. All party member's Health MAXED OUT!")
else:
print("had a nice night. Nothing happened.")
elif randomnumber == 4:
print("had a rough night. ", end="")
randomparty = random.randint(1, 5)
if randomparty == 1:
party1.health -= random.randint(1, 3)
print(party1.name, end=" ")
elif randomparty == 2:
party2.health -= random.randint(1, 3)
print(party2.name, end=" ")
elif randomparty == 3:
party3.health -= random.randint(1, 3)
print(party3.name, end=" ")
elif randomparty == 4:
party4.health -= random.randint(1, 3)
print(party4.name, end=" ")
elif randomparty == 5:
party5.health -= random.randint(1, 3)
print(party5.name, end=" ")
print("got hit by a stray golf ball and took some damage.")
elif randomnumber == 5:
print("Had a very rough night.", end=" ")
randomparty = random.randint(1, 5)
if randomparty == 1:
party1.health = 0
print(party1.name, end=" ")
elif randomparty == 2:
party2.health = 0
print(party2.name, end=" ")
elif randomparty == 3:
party3.health = 0
print(party3.name, end=" ")
elif randomparty == 4:
party4.health = 0
print(party4.name, end=" ")
elif randomparty == 5:
party5.health = 0
print(party5.name, end=" ")
print("got got by a swamp puppy and died.")
except NonCompliant as e:
print(e, end="")
print("Try again.")
except ValueError:
print("Strings are not allowed here, please try again.")
except NotApplicable as e:
print(e)
except DeathError as e:
print(e, end="")
print(", please pick another option.")
if gameOver:
print("All of your party members have fallen...\n G A M E O V E R .")
print(f"You only had {distanceTraveled}/1000 to go! Try again!!")
if day > 7:
print("7 days have passed!", end=" ")
if distanceTraveled < 1000:
print("Unfortunately, your party did not make it to their destination, and died.")
print("Try again.")
else:
print("Your party has made it to their destination! Congratulations! YOU WIN!!")
# gameOver = True
except ErrorWithName as e:
print(e)
finally:
print("-" * 16 + "\nThank you for playing!\n Florida Trail: a Python Game by Calvin Hyrkas")
gameOver = True