spooky house

MiraMira made a small graphical adventure-game using Easygui and python. In the game adventure2.py , the player has the task to survive 60 minutes whithout dying by hunger, fear or loss of health.

Screenshot

Screenshot of Mira's adventure2 game prerequisites: Miras's game needs Python and the python modul easygui. Easygui is included in the zip-file of the download.

License

Creative-commons Logo pictures in the game are from Wikipedia or created by Mira and Teresa (faces). For pictures not from Wikipedia this creative-commons license apply: http://creativecommons.org/licenses/by-nc-sa/2.0/at/

Videos

video series at www.showmedo.com
part 1 of 2: adventure1 part 2 of 2: adventure2
Mira explain in a screencast her adventure1 game Mira & Teresa showing the improved adventure2 game

notice

Mira's sister Teresa made the German versions of this games and German screencasts.

Download

Source Code

adventure2

using a big directory for each room, containing directorys and lists for the possible actions the player can undertake in each room, adventure2 has an easy to maintain and easy to expand data structure.

part of the source code of adventure2.py

adventure2.py
# -*- coding: utf-8 -*-
from __future__ import division
# adventure game
 
import easygui as e
import random as r
 
# define random stats of player
fear_max = r.randint(80,120)
health_max = r.randint(80,120)
hunger_max = r.randint(80,120)
time_max = 60     # player must survive 60 minutes
fear = 0         # fearless
health = health_max # 0 health means dead
hunger = 0        # not hungry
time = 0          # 0 minutes passed
def status():
    """calculate title for msgbox/buttonbox"""
    fearp = fear/fear_max * 100
    healthp = health/health_max * 100
    hungerp = hunger/hunger_max * 100
    return "health: %i%%  fear: %i%% Hunger: %i%% time: %i Minutes" % (healthp, fearp, hungerp, time)
 
def real_delta(delta):
    """return a random number between delta and half of delta"""
    if delta != 0:
        if delta == 1 or delta == -1:
            return delta
        else:
            return r.randint(min(delta, delta//2), max(delta, delta//2))
    else:
        return 0
 
message = {}
choosing = {}
effekt = {}
pic = {}
 
 
 
#----- Korridor --------
message["Corridor"]="""You're in the corridor from a spooky house. You have to survive %i minutes. Where do you go first?""" % (time_max)
pic["Corridor"]="terese1.gif"
choosing["Corridor"]={}                      #  where,          fear, health, hunger, time
choosing["Corridor"]["into the computer room"]=["Computer room", 0,     0,    1,      2]
choosing["Corridor"]["into the kitchen"]      =["Kitchen"    ,   0,     0,    2,      1]
choosing["Corridor"]["into the lab"]          =["Lab" ,          0,     0,    1,      1]
choosing["Corridor"]["into the bedroom"]      =["Bedroom",      10,     0,    1,      5]
# ----- Computerzimmer -------
message["Computer room"]="""Just computer freaks in that room. Somehow they're really weird and don't know what "outside" means. They stare at you as if you were an Alien, what do you say to them?"""
pic["Computer room"]= "terese2.gif"
choosing["Computer room"]={}                                    #  where,          fear, health, hunger, time
choosing["Computer room"]["010101000111001!"]                    =["freaks funny",   -5,    0,    5,      1]
choosing["Computer room"]["I need some fresh air and sunshine"]  =["freaks panic",    20,  -10,    1,      4]
#------ freaks lustig -------
message["freaks funny"]="""The Computerfreaks think you can talk in binary code and made a joke.Everyone is happy and relaxed and you think about eating. Where will you go now?"""
pic["freaks funny"]="tereselacht.gif"
choosing["freaks funny"]={}                             #  where,          fear, health, hunger, time
choosing["freaks funny"]["back to the corridor"]     =["Corridor",        0,      0,    1,      2]
choosing["freaks funny"]["Stay in the computer room"]=["Computer room",   0,      0,    1,      2]
#-------- freaks panik -------------
message["freaks panic"]=""" The computer freaks wince already just by the thought about fresh air and sunshine and hide under their chairs. You stumble over a mouse cable and hurt yourself as you run back to the corridor"""
pic["freaks panic"]="mirafear.gif"
choosing["freaks panic"]={}                               #  where,          fear, health, hunger, time
choosing["freaks panic"]["back to the corridor"]          =["Corridor",        0,      0,    1,      2]
# -------- Speisekammer
message["Kitchen"]="""You see different fruits. What do you want to eat or do?"""
pic["Kitchen"]="tereselacht.gif"
choosing["Kitchen"]={}                           #  where,              fear, health, hunger, time
choosing["Kitchen"]["Back to the corridor"]       = ["Corridor",          0,     0,     2,    1]
choosing["Kitchen"]["Belladonna-Cherry-Marmelade"]= ["belladonna",       30,   -30,    -4,    1]
choosing["Kitchen"]["Pear"]                       = ["mampf",             0,     0,   -10,    1]
choosing["Kitchen"]["Apple"]                      = ["mampf",             0,     0,   - 7,    1]
# ---------- tollkirsche --------
message["belladonna"]="""Belladonna is poisonous! You don't know how much poison you bear and are frightened. """
pic["belladonna"]="teresestaunt.gif"
choosing["belladonna"]={}                           #  where,          fear, health, hunger, time
choosing["belladonna"]["stay in the kitchen"] =  ["Kitchen",     0,      0,    0,     1]
choosing["belladonna"]["back to the corridor"]    =  ["Corridor"    ,     0,      0,    1,     1]
# ---------- mampf ---------------
message["mampf"]="""mampf. mampf. mampf.
Hmmm...that was good! What now?"""
pic["mampf"]="tereselacht.gif"
choosing["mampf"] = {}                            #  where,          fear, health, hunger, time
choosing["mampf"]["Stay in the kitchen"] =  ["Kitchen",     0,      0,    0,     1]
choosing["mampf"]["back to the corridor"]=  ["Corridor",     0,      0,    1,     1]
# --------- Labor -------------
message["Lab"]="""The lab is empty, what now?"""
pic["Lab"] = "horstmonster.gif"
choosing["Lab"] = {}                               #  where,          fear, health, hunger, time
choosing["Lab"]["back to the corridor"]    =  ["Corridor"    ,     0,      0,    1,     1]
#Schlafzimmer
message["Bedroom"]="""You see some ghosts sleeping in the bed. What do you do now? Will you go back to the corridor or hide?"""
pic["Bedroom"] = "mirageist.gif"
choosing["Bedroom"] = {}
choosing["Bedroom"]["back to the corridor"] = ["Corridor" ,     15,      2,    4,    10]                
choosing["Bedroom"]["hide"]            = ["Hiding Place" ,     15,      5,    7,     8]           
#Versteck
message["Hiding Place"]="""You hide in the bedroom and suddenly you see a secret passage. Do you go in there or do you want to go back to the corridor?"""
pic["Hiding Place"] = "miralacht.gif"
choosing["Hiding Place"] = {}
choosing["Hiding Place"]["back to the corridor"]     = ["Corridor" ,      0,      0,    1,     1]
choosing["Hiding Place"]["Secret Passage"]              = ["Secret Passage",     0,      0,    8,     6]
#Geheimgang
message["Secret Passage"]="""That's all very exciting. Now you can decide, if you want to go on or go back to your hiding place."""
pic["Secret Passage"] = "Geheimgang.gif"
choosing["Secret Passage"] = {}
choosing["Secret Passage"]["Back to the hiding place"]   = ["Hiding Place",       0,      2,    3,     5]
choosing["Secret Passage"]["go on"]          = ["Treasure"  ,       3,      5,    4,     3]
#Schatz
message["Treasure"]="""OH MY GOSH, A TREASURE BOX, YOU TAKE IT BACK TO THE HIDING PLACE AND ARE HAPPY"""
pic["Treasure"] = "diamant.gif"
choosing["Treasure"] = {}
choosing["Treasure"] ["back to the hiding place"]      = ["Hiding Place",       0,      0,    0,    10]
 
 
#---------Hauptschleife Anfang ---------
room = "Corridor" # da bin ich jetzt
while (fear<fear_max) and (health>0) and (hunger<hunger_max) and (time < time_max):
    # button-liste erstellen: choosing[room].keys() und Notausgang dazu
    buttonliste = choosing[room].keys()    # buttonliste wird neu berechnet
    buttonliste.append("Quit the game") # wird jedes mal an die buttonliste drangehängt  
    answer = e.buttonbox(message[room], status(), buttonliste, image=pic[room] )
    if answer == "Quit the game":
        e.msgbox("Sad, that you don't want to play anymore....you coward!!!",
                  status(), image = "miradunkel1.gif")
        break # das verlässt die Hauptschleife
    # Spieler Variablen ändern sich
    fear += real_delta(choosing[room][answer][1])
    if fear < 0:
        fear = 0
    health += real_delta(choosing[room][answer][2])
    if health > health_max:
        health = health_max
    hunger+= real_delta(choosing[room][answer][3])
    if hunger < 0:
        hunger = 0
    time  += real_delta(choosing[room][answer][4])
    if time < 0:
        time = 0 # only important if a time machine is in game
    room = choosing[room][answer][0] # what next
 
if (time >= time_max) and (hunger < hunger_max) and (fear < fear_max) and (health > 0):
    e.msgbox("Super! After surviving ojne hour in the spooky house, you've won!", status(), image="mirafreundlich.gif")
message = "Game Over \n" # das \n macht einen Zeilenumbruch
if hunger > hunger_max:
    message += "You died, because you didn't eat anything. \n"
if fear > fear_max:
    message += "You scared yourself to death. \n"
if health <= 0:
    message += "You died on your injuries"
e.msgbox(message, status(), image="mirawuetend.gif")

adventure1

the predecessor of adventure2 was written in German and made out of if-elif-else blocks for each room in the game. While the game is not visible different for the player, the adventure1 source code is harder to read and much harder to extend/maintain than the adventure2 source code

part of the source code of adventure1.py:

adventure1.py
# -*- coding: utf-8 -*-
from __future__ import division
# adventure game
 
import easygui as e
import random as r
 
# define variables (min, max)
fear_max = r.randint(80,120)
live_max = r.randint(80,120)
hunger_max = r.randint(80,120)
time_max = 40
#  (player character)
fear = 0         # habe keine fear
live = live_max # viel live ist gut, 0 live bedeutet tot
hunger = 0        # bin satt
time = 0
def status():
    fearp = fear/fear_max * 100
    livep = live/live_max * 100
    hungerp = hunger/hunger_max * 100
    return "health: %i%%  fear: %i%% Hunger: %i%% time: %i Minuten" % (livep, fearp, hungerp, time)
 
while (fear<fear_max) and (live>0) and (hunger<hunger_max):
    #---- Hautschleife Korridor Anfang ---------
    time+= 1 
    if time > time_max:
        e.msgbox("Nach (über) einer Stunde im Spukhaus findest du den Ausgang. Spiel gewonnen", status(), image="mirafreundlich.gif")
        break # Korridorschleife verlassen
    hunger += r.randint(1,5) # spielen macht hungrig
    antwort_haus = e.buttonbox("You are in the corridor of a spooky house. Where do you want to go ?",
                status(),
                ["in the computer room", "in the kitchen", "into the lab", "into the bedroom", "exit game"])
    if antwort_haus =="exit game":
        e.msgbox("scared of a girl's game, you coward ?",
                 status(),
                 image = "miradunkel1.gif")
        break # das verlässt die Korridor-Schleife
    elif antwort_haus =="in das Computerzimmer":
        #-------freaks Anfang ------------
        time +=1
        hunger += 1
        antwort_freaks = e.buttonbox(
"""lauter Computerfreaks schauen Dich verwundert an. 
Wahrscheinlich kommen Sie nicht viel an die 
frische Luft und sind sozial verklemmt. 
Was sagst Du ?""",
                             status(),
                             ["010101000111001!", "ich brauche Frischluft und Sonnenschein"],
                              image = "terese2.gif")
        if antwort_freaks == "010101000111001!":
            fear -=  r.randint(5,10) # verliert etwas fear (zwischen 5 und 10 fear weniger
            if fear < 0:
                fear = 0 # fear darf nicht negativ werden
            e.msgbox(
"""Die Computerfreaks glauben du kannst in Binärcode reden und hast einen Witz gemacht.
alle sind fröhlich und du entspannst dich ein wenig. 
du gehtst zurück in den Korridor""",
                     status() )
        elif antwort_freaks ==  "ich brauche Frischluft und Sonnenschein":
            fear += r.randint(10,20) # noch mehr fear ! (zwichen 10 und 20 fear dazu)
            live -= r.randint(5,10) # etwas weniger live
            e.msgbox(
"""Die Computerfreaks zucken alleine beim Gedanken an Frischluft und Sonnenschein
total aus, geraten in Panik und verstecken sich unter den Tischen.
Einige Computer stürzen ab und fangen wild an zu piepsen.
Die Panik erfasst auch Dich und du rennst zurück in den Korridor,
wobei Du über ein Mauskabel stoperst und Dich verletzt.""",
                     status(),
                     image = "mirafear.gif")
        #-------freaks Ende--------
    elif antwort_haus == "ins Schlafzimmer" :
        while True:
            time+= 2
            antwort_schlafzimmer = e.buttonbox("Du siehst Geister im Bett schlafen und glaubst, dass du verrückt geworden bist, du fürchtest dich und das ist nicht gut für deine health",status(),["Zurück in den Korridor","Du versteckst dich"],image="bed.gif")
            if antwort_schlafzimmer =="Zurück in den Korridor":
                fear+= r.randint(20,30)
                live-=r.randint(10,30)
                break #raus aus der Schleife
            elif antwort_schlafzimmer=="Du versteckst dich":
                fear+=r.randint(20,30)
                live-=r.randint(10,30)
 
                e.msgbox("""Du versteckst dich und beobachtest die Geister""",
                       status(),
                       image = "gespenst.gif")
                if live<0 or fear> fear_max:
                    break
    elif antwort_haus == "in die Speisekammer":
        #------ Seisekammer Anfang -------
        while True:   # Endlosschleife, bis zum break
            time += 1 
            antwort_speisekammer = e.buttonbox("Du siehst verschiedene Nahrungsmittel. Was willst Du tun essen bzw tun ?",
                                               status(),
                                               ["Belladonna-Kirschmarmelade", "Birne", "Apfel", "zurück in den Korridor gehen"],
                                               image="tereselacht.gif")
            if antwort_speisekammer == "zurück in den Korridor gehen":
                break #raus aus der while-Schleife, in den Korridor
            elif antwort_speisekammer == "Belladonna-Kirschmarmelade":
                hunger -= r.randint(1,5) # etwas weniger Hunger                  
                if hunger < 0:
                    hunger = 0 # Hunger darf nicht negativ werden
                live -= r.randint(20,30) # vergiftung !
                fear += r.randint(10,30) # mehr fear 
                e.msgbox(
"""Belladonna ist der Name für Tollkirsche ! 
Du bekommst gr0ße Pupillen und hast Dich vergiftet ! 
Da Du nicht weisst wieviel Gift Du verträgst fürchtest Du Dich.
Wenigstens hast Du etwas weniger Hunger.""",
                         status(),
                         image="teresestaunt.gif")
            else:  
                e.msgbox("Mampf.Mampf.Mampf.", status(), image="tereselacht.gif")
                hunger -= r.randint(1,5)
                if hunger < 0:
                    hunger = 0
        #------- Speisekammer Ende ------------                                    
    elif antwort_haus == "ins Labor":
        time += 1
        hunger +=1
        e.msgbox("Nein!!! Geh sofort raus von hier! Hochgefährlich!", status(), image="horstmonster.gif")
        fear += r.randint(5,40)
        #pass # da muss ich weiterprogrammieren!
    #---- Hauptschleife Korridor Ende ---------
 
# was ist passiert ?                 
if hunger > hunger_max:
    e.msgbox("Du bist verhungert")
if fear > fear_max:
    e.msgbox("Du hast Dich zu Tode gefürchtet")
if live <= 0:
    e.msgbox("Du bist an Deinen Verletzungen gestorben")

~~LINKBACK~~


en/games/spukhaus.txt · Last modified: 2010/04/03 12:32 (external edit)