218 lines
5.7 KiB
Python
218 lines
5.7 KiB
Python
import random
|
|
|
|
MAX_DISTANCE = 100
|
|
SOUND_EFFECTS = ["Slap!", "Smack!"]
|
|
|
|
def fformat_percentage(val):
|
|
if val == 1.0:
|
|
return "0%"
|
|
elif val > 1.0:
|
|
return f"{int((val-1)*100)}%"
|
|
return f"{int((-val)*100)}%"
|
|
|
|
def iformat_percentage(val):
|
|
return f"{val}%"
|
|
|
|
class Defeated:
|
|
"""
|
|
Tris only cums as much as possible
|
|
"""
|
|
def __init__(self, game):
|
|
self.game = game
|
|
self.input = ""
|
|
self.is_running = True
|
|
self.chance = None
|
|
|
|
def do_action(self, inp):
|
|
if inp in ["end"]:
|
|
self.is_running = False
|
|
return
|
|
else:
|
|
self.game.arousal += 10
|
|
print(random.choice(SOUND_EFFECTS))
|
|
|
|
def run(self):
|
|
while self.is_running:
|
|
self.input = input("$")
|
|
self.do_action(self.input)
|
|
print("Defeat Ended.")
|
|
|
|
|
|
class Encounter:
|
|
"""
|
|
If stamina gets to zero during an encounter, Tris is "defeated".
|
|
"""
|
|
def __init__(self, game):
|
|
self.game = game
|
|
self.input = ""
|
|
self.is_running = True
|
|
self.chance = None
|
|
self.enemy = Enemy()
|
|
|
|
def roll(self):
|
|
self.chance = random.random()
|
|
|
|
def check_defeat(self):
|
|
if self.game.stamina <= 0:
|
|
print("Defeated!")
|
|
self.is_running = False
|
|
d = Defeated(self.game)
|
|
d.run()
|
|
|
|
def do_action(self, inp):
|
|
self.check_defeat()
|
|
if inp in ["fight", "f"]:
|
|
print("Fight!")
|
|
self.game.drain_stamina(20)
|
|
self.enemy.attack(self.game)
|
|
# self.is_running = False
|
|
else:
|
|
print("Unknown command.")
|
|
|
|
def run(self):
|
|
while self.is_running:
|
|
self.input = input("#")
|
|
self.do_action(self.input)
|
|
print("Encounter ended.")
|
|
|
|
class Enemy:
|
|
def __init__(self) -> None:
|
|
self.health = random.randint(50, 150)
|
|
|
|
def attack(self, game):
|
|
if hasattr(game, "stamina"):
|
|
print("Enemy attacks ")
|
|
game.stamina -= 1
|
|
|
|
|
|
class Game:
|
|
def __init__(self):
|
|
self.is_running = True
|
|
self.input = ""
|
|
self.chance = None
|
|
# Stats
|
|
self.distance = 0
|
|
self.stamina = 100
|
|
self.arousal = 0
|
|
self.pleasure = 0
|
|
self.sensitivity = 1.0
|
|
|
|
def save(self, name="save"):
|
|
print("Saving...")
|
|
data = [
|
|
f"distance:{self.distance}\n",
|
|
f"stamina:{self.stamina}\n",
|
|
f"arousal:{self.arousal}\n",
|
|
f"pleasure:{self.pleasure}\n",
|
|
f"sensitivity:{self.sensitivity}\n",
|
|
]
|
|
with open(f"{name}.sav", "w+") as f:
|
|
f.writelines(data);
|
|
print("Game saved!")
|
|
|
|
def load(self, name="save"):
|
|
print("Loading...")
|
|
with open(f"{name}.sav", "r") as f:
|
|
lines = f.readlines()
|
|
for line in lines:
|
|
s = line.split(":")
|
|
if s[0] == "distance":
|
|
self.distance = int(s[1])
|
|
if s[0] == "stamina":
|
|
self.stamina = int(s[1])
|
|
if s[0] == "arousal":
|
|
self.arousal = float(s[1])
|
|
if s[0] == "pleasure":
|
|
self.pleasure = int(s[1])
|
|
if s[0] == "sensitivity":
|
|
self.sensitivity = float(s[1])
|
|
print("Game loaded!")
|
|
|
|
def roll(self):
|
|
self.chance = random.random()
|
|
|
|
def drain_stamina(self, amt):
|
|
self.stamina -= amt
|
|
if self.stamina < 0:
|
|
self.stamina = 0
|
|
|
|
def gain_stamina(self, amt):
|
|
self.stamina += amt
|
|
if self.stamina > 100:
|
|
self.stamina = 100
|
|
|
|
def print_status(self):
|
|
print(f"Tris has travelled {self.distance} out of {MAX_DISTANCE} miles.")
|
|
print(f"Stamina:\t{self.stamina}")
|
|
print(f"Pleasure:\t{self.pleasure}")
|
|
print(f"Arousal:\t{iformat_percentage(self.arousal)}")
|
|
print(f"Sensitivity:\t{fformat_percentage(self.sensitivity)}")
|
|
|
|
def do_encounter(self):
|
|
print("Encounter!")
|
|
e = Encounter(self)
|
|
e.run()
|
|
|
|
def do_ambush(self):
|
|
self.gain_stamina(25)
|
|
print("Ambush!")
|
|
e = Encounter(self)
|
|
e.run()
|
|
|
|
def check_victory(self):
|
|
if self.distance >= MAX_DISTANCE:
|
|
print("Victory!")
|
|
self.is_running = False
|
|
|
|
def debug(self):
|
|
print(fformat_percentage(1))
|
|
print(fformat_percentage(1.5))
|
|
print(fformat_percentage(0.5))
|
|
print(fformat_percentage(2.5))
|
|
print(fformat_percentage(0.0))
|
|
|
|
def do_action(self, inp):
|
|
self.roll()
|
|
if inp in ["e","exit","q","quit"]:
|
|
self.is_running = False
|
|
elif inp in ["walk","w"]:
|
|
if self.chance > 0.8:
|
|
self.do_encounter()
|
|
return
|
|
if self.stamina == 0:
|
|
print("Tris has no stamina. She must rest.")
|
|
else:
|
|
print("Tris walks forward")
|
|
self.distance += 1
|
|
self.drain_stamina(5)
|
|
self.check_victory()
|
|
|
|
elif inp in ["status", "s"]:
|
|
self.print_status()
|
|
elif inp in ["save"]:
|
|
self.save()
|
|
elif inp in ["load"]:
|
|
self.load()
|
|
|
|
elif inp in ["rest","r"]:
|
|
if self.chance > 0.9:
|
|
self.do_ambush()
|
|
return
|
|
print("Tris rests")
|
|
self.gain_stamina(50)
|
|
elif inp in ["dbg"]:
|
|
self.debug()
|
|
else:
|
|
print("Unknown command.")
|
|
|
|
def run(self):
|
|
while self.is_running:
|
|
self.input = input(">")
|
|
self.do_action(self.input)
|
|
|
|
def main():
|
|
game = Game()
|
|
game.run()
|
|
|
|
if __name__ == "__main__":
|
|
main() |