Skip to content

Instantly share code, notes, and snippets.

@tyronewantedsmok
Created June 24, 2019 04:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tyronewantedsmok/3f4156dd5f4673fecbdf8417cdd57f12 to your computer and use it in GitHub Desktop.
Save tyronewantedsmok/3f4156dd5f4673fecbdf8417cdd57f12 to your computer and use it in GitHub Desktop.
import sys
import time
MSG_SYNOPSIS = '''13 December 2027. A year into the zombie apocalypse, you are the young leader of a small, demoralized group in the middle of nowhere, fighting for a chance to see
light at the end of the tunnel. By September of next year, your group has grown greatly but that does not mean that your community on the brink of collapse. You must the make
tough political decisions to determine how your community fares.\n'''
MSG_WINTER = '''\n29 January 2029. It is five weeks into winter and the season shows no mercy. A drought happened for a majority of the last fall and it devastated
the food supply. As your community dives deeper into the winter, you realize that your supply will run out if consumption is not altered. You could do one of two options: reduce
consumption among civilians, or ignore the risk and take a chance ([ALTER SUPPLY]X} {B[IGNORE RISK]).'''
MSG_WINTER_ALTER_SUPPLY = '''\nYour government is now seen as selfish. You took the risk to protect the important people and "do your best with the rest". You have suffered heavy
civilian losses but your army and government losses have been few. As a result, there is division and danger in the streets. Riots breaking out, murders, arson, all happening in
your community.'''
MSG_WINTER_IGNORE_RISK = '''\nYour community did better than expected during the period. That is until you ran out of food in early March. Now you rely solely on scavenging,
risking getting devoured by zombies in order to go another day. Half your community is either dead or lost with great amount of casualties from civilians and
non-civilians.'''
MSG_SPRING = '\n' + '''27 March 2029. One way or another, you have made through the harsh winter and now must face a totally obstacle that could jeopardize your
survival. A group of violent, hostiles target your community and threaten to overtake it if not their demands are met([DEFEND]X} [MERGE]B} [NEGOTIATE]A})'''
MSG_DEFEND_ALTER = '\n' + '''It was a tough battle but it was victory in the end. You sucessfully fended off the hostiles. Your army took a heavy blow but it is still intact.
Tensions are even worse though as hostile sympathizers were suppresed all around the community.'''
MSG_MERGE_ALTER = '\n' + '''You have sucessfully merged with hostiles giving most of what is owned to them. Civilians have actually commended this call in hopes of being
treated better. Nobody was harmed.'''
MSG_NEGOTIATE_ALTER = '\n' + '''You have sucessfully made a deal with the hostiles giving a large amount of resources in order to keep some peace. Your strugling-to-survive
civilians are irate with having to deal with even worse conditions. The government and army is also starting to starve. There are few to work with and things are not
looking up soon.'''
MSG_DEFEND_IGNORE= '\n' + '''Your whole community got destroyed. Everyone is dead, nice one chief.'''
MSG_MERGE_IGNORE = '\n' + '''You have sucessfully merged with hostiles giving most of what is owned to them. Everybody sees this as the best possible option to end the
famine.'''
MSG_NEGOTIATE_IGNORE= '\n' + '''The last portions of supplies have been all been swallowed by the hostiles. You are left with nothing, nice one chief.'''
MSG_OUTBREAK = '\n' + '''22 May 2029. There was no problem in sight until one happened on this date. Civil-government relations even improved. West Nile virus has shaken your
community to the core. All healthy folks are in quarantine including you do treat the sick, which could heavily strain resources, or exile them, which could skyrocket tensions
between civilians and the government([TREAT]X} {B[EXILE])'''
MSG_OUTBREAK_TREAT = '\n' + '''You have treated everyone with the sickness at a cost for low meds. Another epedemic happened a few weeks later, and you lost a lot of
people.'''
MSG_OUTBREAK_EXILE = '\n' + '''You exiled the least useful to keep the most useful surviving. Though, resouces and supplies are stable and death is
rare.'''
MSG_POPULATION = '\n' + '''2 June 2029. Everyone is starving in a famine worse than what you imagined. Once again people are dying of starvaton and once again it is your job
to decide what happens ([POPULATION REDUCTION]X} {B[DESPERATION])'''
MSG_POPULATION_REDUCE = '\n' + '''Remaining civilians resent this decision grealty calling it worse than cruel. However, resource control is the best way to avoid dying
out.'''
MSG_POPULATION_DESPERATION = '\n' + '''Your community's desperate attempts at sustaining itself failed horribly. Scavenging outside the safe zone, hunting, mining, even crimes
like robbery and cannibalism, all failed. Eventually you all died out. Nice one chief.'''
MSG_INDEPENDENCE = '\n' + '''12 July 2029. Either everyone or the civilians came to a new home to hopefully recover from their famine. However how you all were treated is a
different story. You all were treated with inferiority, and rebuttal. You all were embarassed, mistreated and underfed. Now, you all are fed up and now want to devise a plan.
Folks however, are divided on whether an ([ESCAPE]X} [CRUSADE]B} [TALK]Y}) should happen.'''
MSG_INDEPENDENCE_ESCAPE = '\n' + '''It took a few weeks to thoroughly plan out the escape. You gathered as much people as you could to take part. The execution was
mostly sucessful, stripping as much supplies from the hostiles as you could. There were few deaths. The enraged, devastated hostiles kill all of your remaining folk, whether
they were in for the plan or out. You return to home and have some heavy clean up to do'''
MSG_INDEPENDENCE_CONQUER = '\n' + '''A lot of intelligence and thought was put into infiltrating and arming your people in a fight for their freedom. In the end the
mission was accomplished. If you altered the food supply, you did not lose much. If you took the risk, you lost a great deal of people. You took over their place and made it your
own after finding out it has closer proximity to vital resources.'''
MSG_NEW_INDEPENDENCE = '\n' + '''You gather up your most persuasive minds to convince the hostiles away from their inhumane ways. This surprisingly, goes better
than expected and with some initiative taken, your people and theirs now work together in unity.'''
MSG_ELECTION = '\n' + '''25 October 2029. For the rest of the summer and the early autumn, you bounced back and for once resources are not a priority if you have made it this far.
But, the problems never stop. A new polotician named Mr. Powell looks to takeover and "lead this community in the right direction" but you know, deep down, he is tyrannical. He
picking up steam rapidly. A lot of people want him as the leader. The election is next week and you must decide whether to sabatoge the eleciton for the safety of your
impressionable community or think of every possible compelling argument to sway your people into safety. ([SABOTAGE]X} {B[PERSUADE])'''
MSG_ELECTION_SABATOGE = '\n' + '''You have sucessfully sabatoged and won the election and there is already suspicion in the results as most people picked the new person. Everyone is
irate with arson and riots breaking out all across the town. Everyone claims that the election was sabatoged but you hide the evidence that proves them
right.'''
MSG_ELECTION_PERSUADE = '\n' + '''You try your best to convince the crowd but fail as the crowd hangs on every word Mr. Powell says. He has taken over the town. In weeks his tyrannical
overtakes the town. Cruel actions like murdering innocent outsiders, killing the children and elderly, and decapitating those who sympathize, all take effect. Your community has
become the opposite of what you envisioned.'''
MSG_UPGRADE = '\n' + '''14 November 2029. New Independence is now your new home, where the community thrives together on working to make the town a better place to live in. Different
types of people are divided on what should be big priority. ([ARMY]X} [RESILIENCY]B} [RESOURCES]Y} [SERVICES]A})'''
MSG_ARMY = '\n' + '''An EF-5 tornado directly hit your way and killed everything in its path. Nice one chief.'''
MSG_RESOURCES = '\n' + '''An EF-5 tornado directly hit your way and killed everything in its path. Nice one chief.'''
MSG_SERVICES = '\n' + '''An EF-5 tornado directly hit your way and killed everything in its path. Nice one chief.'''
MSG_RESILIENCY = '\n' + '''You have focused you attention at making your community hard to destroy. Additions like much tougher boundaries and an underground helped prepare your
community to sucessfully survive an EF-5 tornado directly hitting the town. But now you lost everything and will have to rebuild.'''
MSG_END_OPPORTUNITY = '\n' + '''1 December 2029. After a few weeks of trying to rebuild you realize that reconstruction. You can't go back your old community beacuse there is
nothing there. So now your stuck. You went scavenging earlier before the tornado and found a living space that could keep a person going for months. However, it keeps ONE person
going for months. You are left to decide if survival is really that important. ([ABANDON]X} {B[PERSERVERE])'''
MSG_END_ABANDON = '\n' + '''You left your community, with no leader, to die in exchange for your comfort. The community is irate and you will be killed on first sight if found.
Luckily, just before your food and supplies ran out, you found another community and you had few problems. You lived there for the rest of your life.'''
MSG_END_PERSERVERE = '\n' + '''One by one, everyone fell out. With no necessities, your community died out. You where seen as loyal for sticking with your community until the end.
Nice one chief.'''
MSG_END_WAR = '\n' + '''6 February 2029. Mr. Powell is back and he is out for revenge from losing the election. He and his militia are destroying everything and everyone in
sight until he gets what wants. With only a few minutes before he arrives at your city hall, you and your army must decide to ([ATTACK]X} {B[RETREAT])'''
MSG_END_ATTACK = '\n' + '''You and your remaining army fought ferociousy against the bigger opposition. In the end, you won, but at a cost, destroyed the whole city. Few survived
being admist the exchange of explosives and gunfire. Your city is decimated but you stopped a major threat from taking over. It took two years before conditions returned to
normal'''
MSG_END_RETREAT = '\n' + '''You most peaceful decision and left with your most trusted peers. You wandered off into unknown and eventually fit in with another community. A few
months later, you gathered up enough men to take back your old city. When you arrived, you discovered the city collapsed with decayed skeletons everywhere walked. It was a ghost
city.'''
MSG_END_EXECUTION = '\n' + '''11 April 2030. You are about to be hanged for sympathizing against their standards. Everyone watches outside cheering and patiently awaiting your
death. When you asked for last words, you tried to ([CONVINCE THE CROWD]X} {B[KILL MR. POWELL]).'''
MSG_END_DEATH = '\n' + '''You have died. The people heard your short speech and were compelled and related to it deeply. They were so emotional that no little time wasted to
overthrow Mr. Powell's government after you were executed. Soon a new leader was chosen to lead the community and ever since, they have advanced to be one of the most expansive
good guys in the apocolypse. They even found a cure.'''
MSG_END_KILL = '\n' + '''Just before somebody could do something, you grabbed a soldier's AK-47 and AKed both him and Mr.Powell. You barely managed to escape the scene. You gathered
any remaining supporters to basically go on a warpath and kill as much army members as you could until they surrendered. You somehow succeedeed in this and basically took over by
force. This makes the people very unhappy but over time they realize how much you care.'''
def long_load():
print('Loading', end='', flush=True)
for _ in range(10):
time.sleep(1)
print('.', end='', flush=True)
print()
def short_load():
print('\nLoading', end='', flush=True)
for _ in range(3):
time.sleep(1)
print('.', end='', flush=True)
class SocialStatus:
"""Enum to represent the societal positions found in the game"""
ARMY = "ARMY & GOVERNMENT"
CIVILIANS = "CIVILIANS"
EVERYBODY = "EVERYBODY"
ULTIMATE_SCORE_CHANGE = 15
MAJOR_SCORE_CHANGE = 2
NORMAL_SCORE_CHANGE = 1
SLIGHT_SCORE_CHANGE = 0.5
class RelationshipChanges:
"""Holds templates and modifiers to decribe changes in the relationships"""
HEROISM = {
'message': ' {} looks at you as a hero.',
'modifier': ULTIMATE_SCORE_CHANGE
}
GREAT_INCREASE = {
'message': ' This greatly improves your relationship with {}.',
'modifier': MAJOR_SCORE_CHANGE
}
INCREASE = {
'message': ' This improves your relationship with {}.',
'modifier': NORMAL_SCORE_CHANGE
}
SLIGHT_INCREASE = {
'message': ' This slightly improves your relationship with {}.',
'modifier': SLIGHT_SCORE_CHANGE
}
SLIGHT_DECREASE = {
'message': ' This slightly decreases your relationship with {}.',
'modifier': -SLIGHT_SCORE_CHANGE
}
DECREASE = {
'message': ' This worsens your relationship with {}.',
'modifier': -NORMAL_SCORE_CHANGE
}
GREAT_DECREASE = {
'message': ' This greatly worsens your relationship with {}.',
'modifier': -MAJOR_SCORE_CHANGE
}
TREASON = {
'message': ' {} wants you dead.',
'modifier': -ULTIMATE_SCORE_CHANGE
}
def change_relation(relationships, type_of_person, type_of_change):
"""Change the standing of the player with a given faction
faction and type_of_change are case insensitive and have to correspond to
class variables of SocialStatus and RelationshipChanges. type_of_change
describes by how much the relationship score is altered.
This function returns a message that describes the change.
"""
type_translation = {
"----": "treason", "---": "great_decrease", "--": "decrease", "-": "slight_decrease",
"++++": "heroism", "+++": "great_increase", "++": "increase", "+": "slight_increase"
}
if type_of_change in type_translation:
# only apply the translation if it's own of ---/--/.../+++
type_of_change = type_translation[type_of_change]
change_descr = getattr(RelationshipChanges, type_of_change.upper())
type_person_name = getattr(SocialStatus, type_of_person.upper())
relationships[type_person_name] += change_descr['modifier']
return change_descr['message'].format(type_person_name)
class RelationshipLevels:
"""Class to represent the player's relationship to other societal positions"""
VENGEFUL = "VENGEFUL"
HATEFUL = "HATEFUL"
DISAPPOINTED = "DISAPPOINTED"
NEUTRAL = "CONFLICTED/NEUTRAL"
SATISFIED = "SATISFIED"
HAPPY = "HAPPY"
PROSPEROUS = "PROSPEROUS"
ALL = [VENGEFUL, HATEFUL, DISAPPOINTED, NEUTRAL, SATISFIED, HAPPY, PROSPEROUS]
def get_final_standing(relation_score, thresholds):
"""Determine how the societal position thinks about the player at the end"""
for threshold, feeling in zip(thresholds, RelationshipLevels.ALL):
if relation_score <= threshold:
return feeling
return RelationshipLevels.ALL[-1]
def roadblock():
roadblock = 'Please enter a valid input'
print(roadblock)
def prompt_for_input(prompt, valid_inputs, max_tries=6):
print(prompt)
while max_tries > 0:
user_input = input('> ').upper()
if user_input in valid_inputs:
return user_input
else:
roadblock()
max_tries -= 1
# the input was not valid, show the roadblock
if max_tries == 0:
print('Seems like you are not willing to play. Goodbye!')
sys.exit(0)
def story(relationships, choices):
situation_winter = prompt_for_input(MSG_WINTER, ('X', 'B'))
if situation_winter == 'X':
short_load()
print('\n' + MSG_WINTER_ALTER_SUPPLY + change_relation(relationships, "civilians", "---") + change_relation(relationships, "army", "++") + '\n')
choices.append('chose safety over risk')
# spring_alter_supply(relationships, choices)
# We take a shortcut to the end here
spring_alter(relationships, choices)
elif situation_winter == 'B':
short_load()
print('\n' + MSG_WINTER_IGNORE_RISK + change_relation(relationships, "army", "---") + '\n')
choices.append('chose risk over safety')
# spring_ignore_risk(relationships, choices)
# We take a shortcut to the end here
spring_ignore(relationships, choices)
def spring_alter(relationships, choices):
situation_spring = prompt_for_input(MSG_SPRING, ('X', 'B', 'A'))
if situation_spring == 'X':
short_load()
print('\n' + MSG_DEFEND_ALTER + change_relation(relationships, "civilians", "--") + '\n')
choices.append('chose defence over all')
sit_outbreak(relationships, choices)
elif situation_spring == 'B':
short_load()
print('\n' + MSG_MERGE_ALTER + change_relation(relationships, "civilians", "++") + change_relation(relationships, "army", "-") + '\n')
choices.append('chose merging over all')
independence_mo(relationships, choices)
elif situation_spring == 'A':
short_load()
print('\n' + MSG_NEGOTIATE_ALTER + change_relation(relationships, "civilians", "---") + change_relation(relationships, "army", "---") + '\n')
choices.append('chose a deal over all')
populated(relationships, choices)
def spring_ignore(relationships, choices):
situation_spring = prompt_for_input(MSG_SPRING, ('X', 'B', 'A'))
if situation_spring == 'X':
short_load()
print('\n' + MSG_DEFEND_IGNORE + '\n')
choices.append('stupidly tried to fight a much bigger army')
elif situation_spring == 'B':
short_load()
print('\n' + MSG_MERGE_IGNORE + change_relation(relationships, "civilians", "+++") + change_relation(relationships, "army", "+++") + '\n')
choices.append('chose merging over all')
independence_mo(relationships, choices)
elif situation_spring == 'A':
short_load()
print('\n' + MSG_NEGOTIATE_IGNORE + '\n')
choices.append('stupidly gave away everything')
def sit_outbreak(relationships, choices):
situation_outbreak = prompt_for_input(MSG_OUTBREAK, ('X', 'B'))
if situation_outbreak == 'X':
short_load()
print('\n' + MSG_OUTBREAK_TREAT + change_relation(relationships, "civilians", "++") + change_relation(relationships, "army", "---") + '\n')
choices.append('chose aid over resources')
elect(relationships, choices)
elif(situation_outbreak) == 'B':
short_load()
print('\n' + MSG_OUTBREAK_TREAT + change_relation(relationships, "civilians", "---") + change_relation(relationships, "army", "++") + '\n')
choices.append('chose resources over aid')
elect(relationships, choices)
def independence_mo(relationships, choices):
situation_independence = prompt_for_input(MSG_INDEPENDENCE, ('X', 'B', 'Y'))
if situation_independence == 'X':
short_load()
print('\n' + MSG_INDEPENDENCE_ESCAPE + change_relation(relationships, "civilians", "+++") + change_relation(relationships, "army", "+") + '\n')
choices.append('chose to escape')
elect(relationships, choices)
elif situation_independence == 'B':
short_load()
print('\n' + MSG_INDEPENDENCE_CONQUER + change_relation(relationships, "civilians", "+") + change_relation(relationships, "army", "+++") + '\n')
choices.append('believed violence was the answer')
buff(relationships, choices)
elif situation_independence == 'Y':
short_load()
print('\n' + MSG_NEW_INDEPENDENCE + change_relation(relationships, "civilians", "++") + change_relation(relationships, "army", "++") + '\n')
choices.append('believed violence was not the answer')
buff(relationships, choices)
def populated(relationships, choices):
situation_population = prompt_for_input(MSG_POPULATION, ('X', 'B'))
if situation_population == 'X':
short_load()
print('\n' + MSG_POPULATION_REDUCE + change_relation(relationships, "civilians", "---") + change_relation(relationships, "army", "+") + '\n')
choices.append('chose survival over morals')
elect(relationships, choices)
elif situation_population == 'B':
short_load()
print('\n' + MSG_POPULATION_DESPERATION + '\n')
choices.append('tried to perservere but died')
def elect(relationships, choices):
situation_election = prompt_for_input(MSG_ELECTION, ('X', 'B'))
if situation_election == 'X':
short_load()
print('\n' + MSG_ELECTION_SABATOGE + change_relation(relationships, "civilians", "---") + change_relation(relationships, "army", "+") + '\n')
choices.append('chose dirty play over clean')
terrorism(relationships, choices)
elif situation_election == 'B':
short_load()
print('\n' + MSG_ELECTION_PERSUADE + change_relation(relationships, "army", "-") + '\n')
choices.append('chose clean play over dirty')
execute(relationships, choices)
def buff(relationships, choices):
situation_upgrade = prompt_for_input(MSG_UPGRADE, ('X', 'B', 'Y', 'A'))
if situation_upgrade == 'X':
short_load()
print('\n' + MSG_ARMY + '\n')
choices.append('chose army over all and died')
elif situation_upgrade == 'B':
short_load()
print('\n' + MSG_RESILIENCY + change_relation(relationships, "civilians", "++") + change_relation(relationships, "army", "++") + '\n')
choices.append('chose resiliency and survived')
opportunity(relationships, choices)
elif situation_upgrade == 'Y':
short_load()
print('\n' + MSG_RESOURCES + '\n')
choices.append('chose resources over all and died')
elif situation_upgrade == 'A':
short_load()
print('\n' + MSG_UPGRADE + '\n')
choices.append('chose services over all and died')
def opportunity(relationships, choices):
situation_end_opportunity = prompt_for_input(MSG_END_OPPORTUNITY, ('X', 'B'))
if situation_end_opportunity == 'X':
short_load()
print('\n' + MSG_END_ABANDON + change_relation(relationships, "civilians", "----") + change_relation(relationships, "army", "----") + '\n')
choices.append('chose your self over all')
long_load()
the_end(relationships, choices)
print('\n')
elif situation_end_opportunity == 'B':
short_load()
print('\n' + MSG_END_PERSERVERE + change_relation(relationships, "civilians", "++") + change_relation(relationships, "army", "++") + '\n')
choices.append('chose everyone over selfishness')
long_load
the_end(relationships, choices)
print('\n')
def terrorism(relationships, choices):
situation_end_terrorism = prompt_for_input(MSG_END_WAR, ('X', 'B'))
if situation_end_terrorism == 'X':
short_load()
print('\n' + MSG_END_ATTACK + change_relation(relationships, "civilians", "---") + '\n')
choices.append('chose war over peace')
long_load()
the_end(relationships, choices)
print('\n')
elif situation_end_terrorism == 'B':
short_load()
print('\n' + MSG_END_RETREAT + change_relation(relationships, "army", "++") + '\n')
choices.append('chose peace over war')
long_load()
the_end(relationships, choices)
print('\n')
def execute(relationships, choices):
situation_end_execute = prompt_for_input(MSG_END_EXECUTION, ('X', 'B'))
if situation_end_execute== 'X':
short_load()
print('\n' + MSG_END_DEATH + change_relation(relationships, "civilians", "++++") + change_relation(relationships, "army", "++++") + '\n')
choices.append('chose words over weapons')
long_load()
the_end(relationships, choices)
print('\n')
elif situation_end_execute== 'B':
short_load()
print('\n' + MSG_END_KILL + '\n')
choices.append('chose weapons over words')
long_load()
the_end(relationships, choices)
print('\n')
def the_end(relationships, choices):
print('\nTHE END')
short_load()
print('\n')
print('*'*80)
final_standing_civ = get_final_standing(
relationships[SocialStatus.CIVILIANS], (-11, -6, -3, 3, 5, 11)
)
print('You left the {} feeling {}.'.format(SocialStatus.CIVILIANS, final_standing_civ))
final_standing_army = get_final_standing(
relationships[SocialStatus.ARMY], (-11, -6, -3, 3, 5, 11)
)
print('You left the {} feeling {}.'.format(SocialStatus.ARMY, final_standing_army))
print('*'*80)
def choice(choices):
print("\nDecisions:\nYou ...")
for choice in choices:
print("... {}".format(choice))
def main():
relationships = {SocialStatus.ARMY: 0, SocialStatus.CIVILIANS: 0}
choices = []
print(MSG_SYNOPSIS)
long_load()
story(relationships, choices)
short_load()
print('\n')
choice(choices)
if __name__ == "__main__":
main()
@alexvorndran
Copy link

The gist still has some issues of the original version. Especially the cluttered look caused by the lack of some well-placed blank lines still remains. You should maybe also include some of the suggestions presented in the other answers and then ask a follow-up question on Code Review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment