Professional Documents
Culture Documents
#Sergiy Zarubin
#Danny Tran
#Lacey Sikes
#Derek Bowdle
#Final Project
import random
import os
#IMPORTING SOUND
#dir_path = os.path.dirname(os.path.realpath(__file__)) #get path of where AdventureGame is at
#print(os.path.basename(os.getcwd()))
#data_folder = os.path.join()
#Note###
#Technically this code will still work on Windows because Python has a hack where it will recognize either kind of
slash when you call open() on Windows.
#So coding the paths with / slashes
#Will need to do a windows check at the end!#
#object images
scorpion = makePicture(dirPath+'/images/radscorpion.png')
ant = makePicture(dirPath+'/images/giantAnt.png')
centaur = makePicture(dirPath+'/images/centaur.png')
chest = makePicture(dirPath+'/images/chest.png')
cameron = makePicture(dirPath+'/images/cameron.png')
print("odone")
#background images
inside = makePicture(dirPath+'/images/templeInside.jpg')
darkRoom = makePicture(dirPath+'/images/darkRoom.jpg')
entrance = makePicture(dirPath+'/images/templeEntrance.jpg')
door = makePicture(dirPath+'/images/templeDoor.jpg')
print("bdone")
#composit images
insideAnt = makePicture(dirPath+'/images/insideAnt.jpg')
insideScorpion = makePicture(dirPath+'/images/insideScorpion.jpg')
insideCameron = makePicture(dirPath+'/images/insideCameron.jpg')
insideCentaur = makePicture(dirPath+'/images/insideCentaur.jpg')
insideChest = makePicture(dirPath+'/images/insideChest.jpg')
jumpsuit = makePicture(dirPath+'/images/jumpsuit.jpg') #wasn't initialized, so i did it here
print("cdone")
deathSound = makeSound(dirPath+'/sounds/death.wav')
#play(deathSound)
earthquakeSound = makeSound(dirPath+'/sounds/earthquake.wav')
#play(earthquakeSound)
encounterSound = makeSound(dirPath+'/sounds/encounter.wav')
#play(encounterSound)
gunSound = makeSound(dirPath+'/sounds/gun.wav')
#play(slapSound)
injuredSound = makeSound(dirPath+'/sounds/injured.wav')
#play(injuredSound)
lootSound = makeSound(dirPath+'/sounds/loot.wav')
#play(lootSound)
slapSound = makeSound(dirPath+'/sounds/slap.wav')
#play(slapSound)
slashSound = makeSound(dirPath+'/sounds/slash.wav')
#play(slashSound)
smackSound = makeSound(dirPath+'/sounds/smack.wav')
#play(smackSound)
spearSound = makeSound(dirPath+'/sounds/spear.wav')
#play(spearSound)
stungSound = makeSound(dirPath+'/sounds/stung.wav')
#play(stungSound)
windSound = makeSound(dirPath+'/sounds/wind.wav')
#play(windSound)
startSound = makeSound(dirPath+'/sounds/start.wav')
play(startSound)
#
#CLASS GAME ITEMS
#
class gameItems:
class Weapon:
def __init__(self):
raise NotImplementedError("No we cannot make it in to the weapon")
def __str__(self):
return self.name+": "+self.description
class Spear(Weapon):
def __init__(self):
self.name = "Spear"
self.description = "A razor tipped pole arm. The shaft is wooden, and the tip is worked steel "
self.damage = 10
self.sound = smackSound
class pistol223(Weapon):
def __init__(self):
self.name = ".223 pistol"
self.description = "A .223 rifle modified and cut down to a pistol. This is a one-of-a-kind firearm, obviously
made with love and skill."
self.damage = 50
self.rounds = 5
self.sound = gunSound
class pistol223Empty(Weapon):
def __init__(self):
self.name = "Empty .223 pistol"
self.description = "A .223 rifle modified and cut down to a pistol. This is a one-of-a-kind firearm, obviously
made with love and skill. No rounds Left"
self.damage = 5
self.sound = smackSound
class Explosives(Weapon):
def __init__(self):
self.name = "Explosives"
self.description = "A chunk of Cordex, a military brand of plastic explosives. Highly stable, very destructive.
Includes a timer."
self.damage = 1000
self.sound = earthquakeSound
class Consumable:
def __init__(self):
raise NotImplementedError("Do not create raw Consumable objects.")
def __str__(self):
class HealingPouder(Consumable):
def __init__(self):
self.name = "Healing Powder"
self.healing_value = 25
class Misc:
def __init__(self):
raise NotImplementedError("Do not create raw Consumable objects.")
def __str__(self):
return "%s - %s" % (self.name,str(self.description))
class Book(Misc):
def __init__(self):
self.name = "Ready Player One"
self.description = "It's the year 2044, and the real world is an ugly place..."
#
#CLASS NPS's Not Implemented Fully
#
class NonPlayableCharacter(object):
def __init__(self):
raise NotImplementedError("Do not create raw NPC objects.")
def __str__(self):
return self.name
class Chest(NonPlayableCharacter):
def __init__(self):
self.name = "Chest"
self.h = 100
self.inventory = [gameItems.Explosives()]
#
#CLASS ENEMIES
#
class enemies:
class Enemy:
def __init__(self):
raise NotImplementedError("Do not create raw Enemy objects.")
def __str__(self):
return self.name
def is_alive(self):
return self.hp > 0
class GiantAnt(Enemy):
def __init__(self):
class RadScorpion(Enemy):
def __init__(self):
self.name = "Rad Scorpion"
self.hp = 20
self.damage = 5
class Cameron(Enemy):
def __init__(self):
self.name = "Cameron"
self.hp = 80
self.damage = 15
class Centaur(Enemy):
def __init__(self):
self.init = "Centaur"
self.hp = 2000
self.damage = 100
class Door(Enemy):
def __init__(self):
self.name = "Door"
self.hp = 1000
#
#CLASS WORLD
#
class world(object):
class MapTile(object):
def __init__(self, x, y):
self.x = x
self.y = y
def intro_text(self):
raise NotImplementedError("Create a subclass instead!")
class StartTile(MapTile):
def intro_text(self):
return """
You find yourself at the entrance of a temple.
You look around and find that only path you have is to go inside,
as other paths are blocked by the palisade and sharpened stakes.
"""
def view(self):
return entrance
def view(self):
return jumpsuit
def intro_text(self):
return """
You see a bright light in the distance...
... it grows as you get closer! It's sunlight!
It is pouring down on the blue and yellow jumpsuit!
You take it and turn it over, it reads:
VAULT 101
You realize that you are in the Fallout 2 Universe.
Congratulations - now go and buy the game if you want to continue
"""
class DoorTile(MapTile):
def __init__(self, x, y):
self.door_opened = False
self.enemy = enemies.Door()
super(world.DoorTile,self).__init__(x, y)
self.alive_text = """
You can see a big door with a big lock.
You can try and pick the lock or
You can try and destroy it
"""
self.dead_text = """Pass is open now
"""
super(world.DoorTile,self).__init__(x,y)
def view(self):
return door
def intro_text(self):
if self.enemy.is_alive():
text = self.alive_text
else:
text = self.dead_text
return text
class EnemyTile(MapTile):
def __init__(self, x, y):
r = random.random()
if r < 0.80:
self.enemy = enemies.GiantAnt()
self.alive_text ="A giant %s speeds toward you it's pincers snap at you! "%(self.enemy.name)
super(world.EnemyTile,self).__init__(x, y)
def view(self):
if self.enemy.is_alive():
if self.enemy.name == "Giant Ant":
return insideAnt
else:
return insideScorpion
else:
return inside
def intro_text(self):
if self.enemy.is_alive():
text = self.alive_text
else:
text = self.dead_text
return text
class EnemyLootTile(MapTile):
def __init__(self, x, y,name):
self.name=name
self.item_claimed = False
#Random Item Drop
r = random.random()
if r < 0.01:
self.item = gameItems.pistol223()
elif r < 0.80:
self.item = gameItems.HealingPouder()
else:
self.item_claimed = True
super(world.EnemyLootTile,self).__init__(x, y)
def view(self):
return inside
def intro_text(self):
if self.item_claimed:
return "%s body decomposing on the ground" % (self.name)
else:
return "%s dropped some %s" % (self.name,self.item.name)
class BossTile(MapTile):
def __init__(self, x, y):
self.enemy = enemies.Cameron()
self.alive_text = "A man yells at you:/nMy Name is %s!!!'You Shell Not Pass' and lunges at you!" %
(self.enemy.name)
self.dead_text = "The corpse of %s man dissolves on the ground." %(self.enemy.name)
super(world.BossTile,self).__init__(x,y)
def view(self):
return insideCameron
def intro_text(self):
if self.enemy.is_alive():
text = self.alive_text
else:
text = self.dead_text
return text
class SecretTile(MapTile):
def __init__(self, x, y):
self.enemy = enemies.Centaur()
self.item_claimed = False
self.item = gameItems.Book()
self.alive_text = "Statue of the Colosus Comes to life 'Only who without hate should pass'"
self.dead_text = "You stroll around the statue of Colosus. It reminds you of John Cena for some reason"
super(world.SecretTile,self).__init__(x,y)
def view(self):
return insideCentaur
def intro_text(self):
if self.enemy.is_alive():
text = self.alive_text
else:
text = self.dead_text
return text
class TrapTile(MapTile):
def __init__(self, x, y):
self.alive_text = "You notice some strange patterns on the floor, but you barge in anyway"
super(world.TrapTile,self).__init__(x, y)
def view(self):
return inside
def intro_text(self):
text = self.alive_text
return text
class LootTile(MapTile):
def __init__(self, x, y):
#Random Item Drop
r = random.random()
self.item_claimed = False
if r < 0.10:
self.item = gameItems.pistol223()
elif r < 0.80:
self.item = gameItems.HealingPouder()
else:
self.item = gameItems.pistol223()
super(world.LootTile,self).__init__(x, y)
def view(self):
def intro_text(self):
if self.item_claimed:
return "Another unremarkable part of the temple. You must forge onwards."
else:
return "Someone dropped some %s" % (self.item.name)
class PassageTile(MapTile):
def view(self):
return darkRoom
def intro_text(self):
roomDesc = ["You are in a dark, musty temple. The shadows seem to play tricks with your eyes, and you can
hear the faint sound of movement.",\
"You see a coridor draped in darkness in front of you. What does this darkness hold for you?",\
"You see scattered pieces of ceiling on the floor.Watch your steps.",\
"You can see a body lying on the floor, you get closer.Name tag reads 'Parzeval'. You find the bloody message
close to the corps.BeWare they are working for IOI, they are sixers! Don't trust them!",\
"You start seeing strang glowing symbols in the dark. Suddenly you realize what they are saying:Peace of Eden
belongs to us!",\
"On the walls you can read the big sign:'Save Cheer Leader - Save the World'",\
"A crack in the ceiling above the middle of the north wall allows a trickle of water to flow down to the floor.The
water pools near the base of the wall, and a rivulet runs along the wall an out into the hall. The water smells fresh.",\
"A large, arched niche pierces one wall of this chamber. Filled with rotting wood and rubble the niche appears to
be a dumping ground of sorts. Elsewhere in the room, several sections of floor are cracked and pitted.",\
"This irregularly-shaped room has an uneven floor. Several small puddles have gathered in the deeper
depressions. Elsewhere, small pieces of rubble litter the floor.",\
"The arched ceiling of this chamber rises to a height of 20 ft. In the center of the room, but is barely man-high
where it meets the walls. The arches holding the ceiling aloft are carved to represent writhing tentacles; a few have been
defaced but the upper portions of all remain untouched.",\
"A pile of rotting wood, rubbish and other detritus partially obscures one wall of this chamber.Clearly used as a
rubbish dump, the stench of decay and rot hangs heavily in the air",\
"This large chamber was the scene of an ancient battle. Skeletal remains of at least a dozen humanoids lie
scattered about the room where they fell. Several rusting broken spears and shattered, rotting shields lie among the
fallen.",\
"Part of one wall of this room has collapsed, revealing the natural rock behind the dressed stone wall. The rubble
has been moved to create a breastwork across one of the room's exits. Splatters of old, dried blood decorate the top of
the breastwork.",\
"The remains of a cold camp are evident here. A tattered cloak-the size meant for a gnome or halfling?-along
with two empty wineskins and the stripped bones of a chicken and crusts of mouldy bread bear testimony to an
explorer's rest.",\
"A gaping open pit in one of this chamber's doorways blocks access to the area beyond. Two skeletons, pierced
by dozens of tiny stone spikes, lie in the pit.The chamber beyond boasts a stone plinth and altar set in a semi-circular
niche. The chamber's other doorway-twice the width of the trapped one appears unprotected."]
class ChestTile(MapTile):
def __init__(self, x, y):
self.chest = Chest()
super(world.ChestTile,self).__init__(x, y)
def view(self):
return insideChest
def is_locations_valid(object,locations):
if locations.count("|ST|") != 1:
return False
if locations.count("|VT|") == 0:
return False
lines = locations.splitlines()
lines = [l for l in lines if l]
pipe_counts = [line.count("|") for line in lines]
for count in pipe_counts:
if count != pipe_counts[0]:
return False
return True
world_map = []
start_tile_location = None
def parse_world_locations(object):
if not world.is_locations_valid(object,world.worldLocations):
raise SyntaxError("This location is invalid!")
locations_lines = world.worldLocations.splitlines()
tile_type = world.tile_type_dict[locations_cell]
if tile_type == world.StartTile:
global start_tile_location
start_tile_location = x, y
if tile_type :
row.append(tile_type(x, y))
else:
row.append(None )
world.world_map.append(row)
#
#CLASS Player
#
class player:
class Player:
def __init__(self):
def is_alive(self):
return self.hp > 0
def print_inventory(self):
printNow("Inventory:")
for item in self.inventory:
printNow('* ' + str(item))
def senpokku(self):
self.hp = self.hp-self.hp
printNow("%s commit Seppuku"%self.name)
def heal(self):
consumables = [item for item in self.inventory
if isinstance(item, gameItems.Consumable)]
if not consumables:
printNow("You don't have any items to heal you!")
return
i=0
for i,item in enumerate(consumables):
i=i+1
printNow("Choose an item to use to heal:")
printNow("%d. %s"%(i,str(item.name)))
valid = False
while not valid:
choice = requestNumber("")
try:
to_eat = consumables[int(choice) - 1]
self.hp = min(100, self.hp + to_eat.healing_value)
self.inventory.remove(to_eat)
printNow("Current HP: %d" % (self.hp))
valid = True
except (ValueError, IndexError):
printNow("Invalid choice, try again.")
def most_powerful_weapon(self):
max_damage = 0
best_weapon = None
for item in self.inventory:
try:
if item.damage > max_damage:
best_weapon = item
max_damage = item.damage
except AttributeError:
pass
def move_north(self):
self.move(dx=0, dy=-1)
def move_south(self):
self.move(dx=0, dy=1)
def move_east(self):
self.move(dx=1, dy=0)
def move_west(self):
self.move(dx=-1, dy=0)
def attack(self,w):
best_weapon = self.most_powerful_weapon()
enemy = room.enemy
if isinstance(best_weapon, gameItems.Explosives):
self.inventory.remove(best_weapon)
if isinstance(best_weapon, gameItems.pistol223):
best_weapon.rounds-=1
if best_weapon.rounds<=0:
self.inventory.remove(best_weapon)
self.inventory.append(gameItems.pistol223Empty())
if not enemy.is_alive():
printNow("You killed %s!"%(enemy.name))
w.world_map[room.y][room.x]=w.EnemyLootTile(room.x,room.y,enemy.name)
else:
printNow("%s HP is %d"%(enemy.name,enemy.hp))
def loot(self,w):
room = w.tile_at(self.x, self.y)
room.modifyPlayer(self)
def check(self,w):
room = w.tile_at(self.x, self.y)
room.check_chest(self)
def quit(self):
self.hp=-1
#
#MAIN Game loop
#
#Global Variables and Arrays
WELCOME = """
===================================================================================
| Welcome %s
| Section Six Labs
| Presents
| "Escape from Temple of Terror!"
| In each room you will be told which directions you can go
| You'll be able to go north, south, east or west by typing that direction
| Follow on screen instructions to play the game
| You can go in any avaliable direction
| (I)nventory, (H)eal , (A)tack,(L)oot
| Go: (N)orth, (S)outh, (W)est or (E)ast
| Type /h for Help or you can type /q to Quit
===================================================================================
"""
#from collections import OrderedDict
def playgame(): #changed name to playgame due to conficts with sound play()
w=world()
w.parse_world_locations()
p = player.Player()
p.name = requestString("Enter your name: ")
showInformation(WELCOME %(p.name))
while p.is_alive() and not p.victory:
room = w.tile_at(p.x, p.y)
repaint(room.view())
showInformation(room.intro_text())
room.modify_player(p)
if p.is_alive() and not p.victory:
choose_action(w,room, p)
elif not p.is_alive():
showInformation("Your journey has come to an early end %s!" % p.name)
play(deathSound)
playgame()