Created
August 5, 2016 17:54
-
-
Save Ekultek/1a68bfe736a25d1a7541448f72cac620 to your computer and use it in GitHub Desktop.
Here's all the files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# battle.py | |
from settings import formatter, BACKPACK, SURVIVAL_TOOLS, \ | |
return_to_camp, die | |
from choices import try_to_start_fire, build_shelter | |
from random import randint, random | |
def battle(animal, weapon, health): | |
print formatter() | |
print "To try to kill the {};" \ | |
" you must press the correct key" \ | |
" when it appears on the screen." \ | |
" Press enter when ready".format(animal) | |
raw_input() | |
keys = 'abcdefghijklmnopqrstuvwxyz' | |
animal_health = 100 | |
while health > 0: | |
while True: | |
if weapon == 'knife': | |
weapon_damage = randint(5, 30) | |
weapon_output = "You strike with your knife doing {} damage!".format(weapon_damage) | |
elif weapon == 'machete': | |
weapon_damage = randint(13, 37) | |
weapon_output = "You strike with your machete doing {} damage!".format(weapon_damage) | |
elif weapon == 'colt .45': | |
weapon_damage = 100 | |
weapon_output = "You shoot that bastard in the face and he drops dead." | |
else: | |
weapon_damage = randint(1, 10) | |
weapon_output = "You try to smash them {} with your {} doing {} damage!".format(animal, weapon, | |
weapon_damage) | |
if animal == 'mountain lion': | |
animal_damage = randint(35, 67) | |
animal_output = "The mountain lion slashes at you doing {} damage!".format(animal_damage) | |
else: | |
animal_damage = randint(10, 25) | |
animal_output = "The {} slashes at you doing {} damage!".format(animal, animal_damage) | |
correct_key = random.choice(keys) | |
print correct_key | |
to_eval = raw_input('> ') | |
if to_eval == correct_key: | |
print weapon_output | |
animal_health -= weapon_damage | |
print "The {} has {} health remaining".format(animal, animal_health) | |
if animal_health <= 0: | |
win_battle(animal, weapon) | |
else: | |
print animal_output | |
health -= animal_damage | |
print "You have {} health remaining".format(health) | |
if health <= 0: | |
lose_battle(animal) | |
def win_battle(animal, weapon): | |
print "You pick up the dead {} and start walking back to camp.".format(animal) | |
food = SURVIVAL_TOOLS['meat'] = 1 | |
BACKPACK['raw meat'] = food | |
if weapon == 'colt .45': | |
BACKPACK['bullets'] -= 1 | |
print formatter() | |
if 'camp' in SURVIVAL_TOOLS: | |
return_to_camp() | |
else: | |
options = ['create a fire', 'create a camp'] | |
for opt in options: | |
print "{}".format(opt) | |
print "\n" | |
while True: | |
choice = raw_input('What would you like to do: ') | |
if 'fire' in choice: | |
try_to_start_fire(SURVIVAL_TOOLS['fire wood']) | |
elif 'camp' in choice: | |
build_shelter() | |
else: | |
print "{} isn't an option right now, your meat is spoiling." | |
def lose_battle(animal): | |
print "You fall down and the {} jumps on you.".format(animal) | |
die("The {} slowly starts eating you.".format(animal)) | |
###################################################################################### | |
# game.py | |
from choices import gather_fire_wood, go_hunting, build_shelter, \ | |
create_signal_fire, look_for_escape | |
from prepare import gather_gear | |
from settings import formatter, die, create_player | |
def start_adventure(player): | |
"""Start your adventure, you start out hiking and then someone dies | |
you freak out because your a wuss and run away like a little girl. | |
:type player: String | |
""" | |
print formatter() # Pretty formatting | |
print "You head out to your location." \ | |
" On your way there you and Jack" \ | |
" talk about your lives until you" \ | |
" finally pull in to the trail." \ | |
" You look at the map and notice there's" \ | |
" an emergency number. " \ | |
' "Jack" you say "Should we take down this number?"' \ | |
' "Don\'t be such a baby {}" says Jack laughing' \ | |
" You start walking the trail and come to a clearing." \ | |
" When suddenly there's a loud growl, you turn around" \ | |
" and see a mountain lion jump on Jack," \ | |
" Jack starts screaming as the lion rips his throat out." \ | |
" You begin to run, you hear Jack's screams fading away" \ | |
" in the distance. You run for what seems like an hour" \ | |
" and realize you have no idea where you are." \ | |
" You lean against a trunk and think about what just" \ | |
" happened. You have limited options.\n".format(player) # Well that escalated quickly O.O | |
options = ['Find fire wood', 'Cry', 'Find food', 'Build a shelter', 'Build a signal fire', | |
'Try to find your way back'] | |
print "Options are:" | |
for i, opt in enumerate(options): | |
print "[{}] {}".format(i+1, opt) # Print out your possible options at this point | |
option = False | |
print "\n" | |
while option is not True: | |
choice = raw_input('What would you like to do, enter a number: ') | |
if choice == '1': | |
option = True | |
gather_fire_wood() | |
elif choice == '2': | |
option = True | |
print die('You start crying loudly. It starts to snow, you have no shelter and freeze.') | |
elif choice == '3': | |
option = True | |
go_hunting() | |
elif choice == '4': | |
option = True | |
build_shelter() | |
elif choice == '5': | |
option = True | |
create_signal_fire() | |
elif choice == '6': | |
option = True | |
look_for_escape() | |
else: | |
option = False | |
print "Expected 1-{} got {}".format(len(options), choice) | |
def welcome_screen(): | |
""" | |
Main program method, where all the magic happens | |
""" | |
player_name = create_player() | |
print "\n** Welcome to the survival game {}. **\n".format(player_name) | |
message = """The object of this game is fairly simple. Survive.\n | |
You will be given a set number of items to survive | |
with. These items will be put into your 'backpack' | |
and can be used from there. Everything you do effects | |
how this will turn out for you.\nRemember, small mistakes in the wilderness | |
can be the difference between life and death. | |
""" | |
print formatter() | |
print message | |
while True: | |
begin = raw_input('Are you ready to begin, {} [Y/N]? '.format(player_name)).lower() | |
if 'y' in begin: | |
gather_gear(player_name) | |
break | |
elif 'n' in begin: | |
print "Exiting program.." | |
break | |
else: | |
print "Expected 'Y' or 'N' got {}. Try again..".format(begin) | |
if __name__ == '__main__': | |
welcome_screen() | |
#################################################################################### | |
# prepare.py | |
from settings import formatter, BACKPACK | |
from game import start_adventure | |
from random import randint | |
def gather_gear(player): | |
""" | |
Gather your gear from a set list of items you have available | |
:type player: String | |
""" | |
print formatter() | |
print "{}! Shouts Jack as he runs towards you." \ | |
" Do you wanna go Hiking this weekend?" \ | |
" You ponder this for a second." \ | |
" What the hell, you think." \ | |
" Can't be any worse then last time." \ | |
" Sure, Jack! You say enthusiastically." \ | |
" Just let me get some things prepared.\n".format(player) | |
options = { # All the items that are available to you before you leave | |
'fire starter': 1, | |
'matches': randint(1, 5), # Uses random integers as the value | |
'flash light': 1, | |
'sleeping bag': 1, | |
'canteen cup': 1, | |
'dried foods': randint(2, 6), | |
'shovel': 1, | |
'knife': 1, | |
'pair of socks': randint(2, 10), | |
'granola bars': randint(2, 5), | |
'machete': 1, | |
'bottle of whiskey': 1, | |
'heavy jacket': 1, | |
'tinder pieces': randint(3, 5), | |
'bullets': randint(4, 7), | |
'colt .45': 1 | |
} | |
for key in options: | |
print "You have {} {}".format(options[key], key) # Print out all your items and make it look pretty | |
count = 3 | |
num_in_pack = 0 | |
print '\n' | |
while count != 0: | |
item = raw_input("What would you like to take with you? Choose {} items one at a time: ".format(str(count))).lower() | |
if item in options and item not in BACKPACK: # As long as the item is available you can use it | |
BACKPACK[item] = options[item] # Add the item value to your backpack constant | |
count -= 1 | |
print "You throw a {} in your backpack".format(item) | |
num_in_pack += 1 | |
if num_in_pack == 3: # If you have three items, lets begin! | |
print "Your backpack is now full." | |
start_adventure(player) | |
else: | |
print "Can't bring that item." | |
return BACKPACK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment