#!/usr/bin/python """ Quest by Kris Schnee. Very basic doodle of a game idea. """ ##___________________________________ ## ~Header~ ##___________________________________ __author__ = "Kris Schnee" __version__ = "2008.?.?" __license__ = "Public domain." ##___________________________________ ## ~Imported Modules~ ##___________________________________ ## Standard import random ## Third-party ## Mine ##___________________________________ ## ~Constants~ ##___________________________________ ENCOUNTER_ACTIONS = ["bribe","charm","flee","kill","pummel","taunt"] ##___________________________________ ## ~Classes~ ##___________________________________ class Hero: def __init__(self,**options): self.name = options.get("name","Grignr") self.status = [] ##class Encounter( dict ): ## def __init__(self,**options): ## dict.__init__(self) ## self["nature"] = "Encounter" ## self["name"] = options.get ## for action in options.get("actions",[]): ## self[action] = options[action] class EncounterDeck: def __init__(self): self.encounters = [] def Add(self,card): card.setdefault("used",False) self.encounters.append(card) def Deal(self): available = [e for e in self.encounters if not e.get("used")] if not available: raise "All encounters are used up!" return available[ random.randint(0,len(available)-1) ] class Game: def __init__(self): self.encounter_deck = EncounterDeck() self.hero = Hero() def Play(self): print "Game begins. You have an encounter." card = self.encounter_deck.Deal() print "*** "+card["name"]+" ***" print card["text"] print "Your choices:" choices = {} for action in card["actions"]: choices[action[0]] = action print "("+action[0].upper()+")"+action[1:] choice = raw_input("> ") if choice == "q": pass elif choice.lower() in choices: result = card[choices[choice.lower()]] print result["text"] print "Effects: "+str(result.get("effects","None")) ##___________________________________ ## ~Functions~ ##___________________________________ ##__________________________________ ## ~Autorun~ ##__________________________________ if __name__ == "__main__": g = Game() e1 = {"name":"The Hideous Painting", "text":"You come across a crude painting of a creepy grey demon clutching a torch.", "actions":["examine","flee","kill"], "examine":{"text":"The painting calls to you in a gravelly voice: 'Come on in here...'\nYou are so terrified that you begin to convulse!", "effects":[("inflict","jibblies")], }, "flee":{"text":"You run away from the hideous painting as it mutters curses at you, unable to stop your flight! Close call!", }, "kill":{"text":"You slash the painting to ribbons!", }, } g.encounter_deck.Add(e1) g.Play()