I quite like this extra credit assignment I did for Zed Shaw's Learn Python The Hard Way. Its a neat little text adventure game that uses stats. I would like to eventually expand this, but let me know how the code looks so far!
# Legend Of Doobieus
import random
from sys import exit
#rolls 3d6
def roll_3d6():
a = random.randint(1, 6)
b = random.randint(1, 6)
c = random.randint(1, 6)
list = [a, b, c,]
list.sort()
add = sum(list[0:3])
return add
#stats
def display_stats():
global pow, cun, per
pow = roll_3d6()
print "Power: ", pow
cun = roll_3d6()
print "Cunning: ", cun
per = roll_3d6()
print "Personality: ", per
# Check Random Encounter
def chk_rn():
x = random.randint(1, 6)
if x == 1:
rn_ec1()
# First Encounter (main program really)
def fi_en():
global pow, cun, per
print"""
It smells of damp vegetation, and the air is particularly thick. You can
hear some small animals in the distance. This was a nice place to sleep.
1. Stay close, find some cover, and wait for food to show up.
2. Explore the nearby marsh & find the nearest river, following it downstream.
3. Walk towards the large mysterious mountain in the distance.
"""
answer = int(raw_input(prompt))
if answer == 1:
cun_one = roll_3d6()
if cun_one <= cun - 2:
print"""
Time passes as eventually you capture some varmints. You feel slightly more
roguish.
"""
cun = cun + 1
chk_rn()
fi_en()
else:
print """
Time passes and a group of slavers marches into right where you are hiding in
the woods. They locate you, capture you, and haul you away for a lifetime of
servitude in the main city.
Goodbye %s
""" % name
elif answer == 2:
power = roll_3d6()
if power <= pow - 4:
print"""
You trudge through the marshes until you eventually reach a large river.
Downstream from the river is a large temple covered in vines, you walk towards
it. You feel more powerful."""
pow = pow + 2
chk_rn()
te_en()
else:
print """
The vegetation here wraps itself around your legs making it impossible to move.
You will most likely die here in the vegetation.
Goodbye %s.
""" % name
elif answer == 3:
cun_two = roll_3d6()
if cun_two <= cun:
print """
You make your way towards the mountain and you encounter a really large group of
devil dogs guarding the entrance to the mountain.
"""
chk_rn()
dd_en()
else:
print"You have gotten lost and ended up right where you started."
fi_en()
# Devil Dog Encounter
def dd_en():
global pow, cun, per
print"""
You have encountered a massive group of Devildogs.
1. Fight off the whole group, like a true hero
2. Try to sneak very quietly around them.
3. Attempt to tame them like domestic animals.
4. Accept the Devildog curse and walk through unmolested, sort of.
"""
answer = int(raw_input(prompt))
if answer == 1:
power = roll_3d6()
if power <= pow - 6:
print """
You are a God among men and have defeated all of the surrounding Devildogs.
Beyond the entrance to the mountain is a temple covered in vines. You
feel more powerful.
"""
power = power + 3
chk_rn()
te_en()
else:
print """
You are easily overwhelmed by the devildogs and you are continuously eaten
by devildogs for all eternity.
Goodbye %s.
""" % name
elif answer == 2:
sneak = roll_3d6()
if sneak <= cun - 4:
print """
You stealthily evade the Devildogs. Beyond the entrance to the mountain is a
temple covered in vines. You feel more roguish.
"""
cun = cun + 2
chk_rn()
te_en()
else:
print """
The devildogs pick up on your scent. You are easily overwhelmed by the
devildogs and you are continuously eaten by devildogs for all eternity.
Goodbye %s.
""" % name
elif answer == 3:
charm = roll_3d6()
if charm <= per - 4:
print """
The Devildogs are thrilled and have accepted you as their leader, they allow
you to pass and will sing your praises for all eternity. Beyond the entrance
to the mountain is a temple covered in vines. You feel more charming.
"""
per = per + 2
chk_rn()
te_en()
else:
print """
The Devildogs have no idea what you are trying to do.You are easily
overwhelmed by the devildogs and you are continuously eaten by devildogs
for all eternity.
Goodbye %s.
""" % name
elif answer == 4:
print"""
The Devildogs circle around you and start howling in unison. You feel your
life forces draining away as they howl their awful song. Beyond the entrance
to the mountain is a temple covered in vines.
"""
pow = pow - 3
cun = cun - 3
per = per - 3
chk_rn()
te_en()
else:
print """
You stumble as the Devildogs take notice. You are easily overwhelmed by the
devildogs and you are continuously eaten by devildogs for all eternity.
Goodbye %s.
""" % name
# Temple Encounter
def te_en():
global pow, cun, per
print """
You are now standing right in front of a large temple with many vines
covering its cobblestone exterior. An archway precedes a small and
peaceful garden with a main road leading to the temple.
Next to the archway is a small gargoyle that is moving and staring at you
with a friendly smile. It is now sundown and the area starts to gleam a reddish
glow. In the glow you can see faint white whips in the distance beyond the
archway. It smells like fresh produce. In your head you are instantly reminded
of a heartwarming song you remembered as a kid.
1. Walk through the archway normally towards the temple.
2. Run through the archway trying to get to the door as quickly as possible.
3. Have a conversation with the gargoyle staring at you.
"""
answer = int(raw_input(prompt))
if answer == 1:
power = roll_3d6()
if power <= pow - 5:
print"""
As you walk through you immediately feel what feels like hundreds of hands
groping at you pulling you into the ground. You stand your ground and make
it to the door. You enter the temple. You feel more powerful.
"""
pow = pow + 2
in_te()
else:
print """
As you walk through, you are taken off guard as hundreds of hands grope you and
pull you straight down to hell for the rest of eternity.
Goodbye %s.
""" % name
elif answer == 2:
run = roll_3d6()
if run <= cun - 6:
print """
You sprint through and notice nothing as you quickly arrive at and enter the
temple. You feel more roguish.
"""
cun = cun + 2
in_te()
else:
print """
You trip and fall as you are running. What feels like 100 hands grabs you and
pulls you straight down to hell for the rest of eternity.
Goodbye %s.""" % name
elif answer == 3:
charm = roll_3d6()
if charm <= per - 3:
print """
You ask the gargoyle where you are, and he cheerfully
tells you that you've arrived at the halls of destiny, and that you should
walk down the driveway. The sky returns to its normal color. You walk down
the passageway and enter the temple. You feel more charming.
"""
per = per + 1
in_te()
else:
print """
You ask the gargoyle where you are, right as the
expression changes on his face and tells you, 'Hell.' Right as he
says that 100 hands come up from the ground and pull you straight to hell.
Goodbye %s.
""" % name
elif answer == "sing" or "sing song" or "Sing" or "Sing Song":
print """
The gargoyle rejoices as you sing and exclaims he was
just thinking about that song as he saw you. He says you are allowed
to enter the temple of destiny. The sky turns back to its normal color. You
walk down the passageway and enter the temple. You feel charming.
"""
cun = cun + 2
in_te()
else:
print"""
You stumble as the gargoyle scowls you and screams an awful
noise. Immediately, 100 hands appear from the ground and drag you down to
hell as the gargoyle cackles above you.
Goodbye %s.
""" % name
# Inside The Temple
def in_te():
global pow, cun, per
print"""
Inside the temple, Cobblestone lines the walls. There is one large room
leading to another. It smells of mold, and you can hear both water dripping,
and gears shifting. In the middle of a room stands a large minotaur with his
head looking down carrying a massive axe.
1. Engage the minotaur in combat.
2. Sneak along the edges of the walls to the next room.
3. Attempt to speak the the minotaur.
"""
answer = int(raw_input(prompt))
if answer == 1:
fight = roll_3d6()
if fight <= pow - 6:
print """
You destroy the foul beast without taking injury. It screams as it dissolves
into the ground. Several torches light up and signal safe entry into the next
room. You feel more powerful.
"""
pow = pow + 2
you_win()
else:
print """
You find yourself unable to best to minotaur in combat and he decapitates you.
Goodbye %s""" % name
elif answer == 2:
sneak = roll_3d6()
if sneak <= cun - 5:
print """
You successfully sneak around the minotaur and enter the next room.
You feel more roguish.
"""
cun = cun + 2
you_win()
else:
print """
You step on a pressure plate and a blade emerges from the wall
decapitating you.
Goodbye %s
""" % name
elif answer == 3:
charm = roll_3d6()
if charm <= per - 5:
print """
You ask the minotaur what his purpose is, and he exclaims to welcome you to
your destiny. And allows you to pass. You feel more charming.
"""
per = per + 2
you_win()
else:
print"""
You ask the minotaur what his purpose is, and he exclaims to prevent you from
stealing the hero's destiny. He swings his axe and decapitates you.
Goodbye %s.
""" % name
else:
print"""
You stumble and trip right in front of the minotaur, who takes this opportunity
to decapitate you with his axe.
Goodbye %s
""" % name
exit
# You Win!
def you_win():
print """
You have entered a room covered in jewels & a large crown sits on a pedestal.
Behind the crown is a plaque that reads:
~CoNgRaTuLaTiOnS HeRo~
You have found the crown of destiny
This crown lays here to be worn
By the hero of this land
Who has proved himself capable
Of surviving much hardship, &
Having both a sharp mind & Spirit
Take the crown, and henceforth
Your rightful place as the ruler
Of Calgaria.
You pick up the crown and place it on your head. You are now the king of
Calgaria. Congratulations %s you beat the legend of doobieus!
""" % name
print"Your final stats were: \n", display_stats()
print "\nThanks for playing, goodbye!"
#random encounter 1
def rn_ec1():
global pow, cun, per
print """
You have randomly encountered a colony of large ants
They are about your size but have pincers the size of your arms.
Their clicking noises now envelop you...
1. Fight off the ants to the best of your ability.
2. Run away as quickly as possible.
3. Sing 'The Song of Insect Charm.'
"""
answer = int(raw_input(prompt))
if answer == 1:
fight = roll_3d6()
if fight <= pow - 4:
print """With an amazing display of strength, you defeat all
of your foes. You feel stronger after your victory."""
pow = pow + 2
else:
print """You are eaten alive by ants and die.
Goodbye %s.""" % name
elif answer == 2:
trick = roll_3d6()
if trick <= cun - 2:
print """You outrun the giant ants and have survived.
You feel a little bit more roguish"""
cun = cun + 1
else:
print """You fail to outrun the ants and are eaten alive.
Goodbye %s""" % name
elif answer == 3:
charm = roll_3d6()
if charm <= per - 2:
print """The giant ants thank you for your lovely rendition &
allow you to pass. You feel charming."""
per = per + 1
else:
print """The giant ants are horrified by your awful rendition of
their sacred anthem. They tear you apart mercilessly."
Goodbye %s.""" % name
else:
print """You stumble as the clicking gets closer and closer until
you are painfully eaten alive by ants.
Goodbye %s""" % name
######################## MAIN PROGRAM ###################################################
prompt = "> "
print "\n\t\tWelcome to LeGeNeD oF DoObIeUs..."
print "\n\t\tProgrammed using Python 2.7 by Ray Weiss"
name = raw_input("\nWhat is your name brave rogue? > ")
print "\nOk %s, lets roll up some character stats." % name
print "\nPress enter to roll 3D6 for each stat."
raw_input()
display_stats()
print "\nThese are your stats. They can be changed by things in game."
print "\nThese stats will have an effect on the outcomes that you choose."
print "\nYou will be presented with many choices, type in a number."
print "\nOr risk typing something different."
print "\nPress enter to start the game"
raw_input()
print"""You are %s, you are but a wandering rogue in the vast,
mysterious, and deadly land of Calgaria. Your goal is to survive.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You have just woken up in the woods, its really cold, and you are hungry.
""" % name
fi_en()