Arne Babenhauserheide  committed 25b0e54

Fixed persistent game states.

  • Participants
  • Parent commits f822c81
  • Branches default

Comments (0)

Files changed (5)

File ews/amov/Skripte/Kernskripte/ein_und_ausgabe/

 # Kategorie/name-version-yyyy-url.yml
 """Read an input-object ('ID' supplies the tag) and translate it to a file-path"""
+from os.path import join
 import tag_zu_objekt
 import tag_zu_datei_von_tag
 class Datei: 
         """Read a tag and return a
-corresponding file-path"""
-        def __init__(self, Eingabe): 
+corresponding file-name"""
+        def __init__(self, Eingabe, speicherordner_rel_zu_home=".amov"): 
                 self.Eingabe = Eingabe
                 self.tag_string = self.Eingabe["ID"]
                 self.version = self.Eingabe["Version"]
+                self.speicherordner_rel_zu_home = speicherordner_rel_zu_home
+                self.basisordner = join(tag_zu_datei_von_tag.BASISORDNER, speicherordner_rel_zu_home)
                 # wir holen uns das Objekt das dem tag entspricht.
                 self.tag_zum_objekt = tag_zu_objekt.tag_zu_objekt(self.tag_string)
                 self.tag_objekt = self.tag_zum_objekt.tag_objekt()
+        def dateipfad(self): 
+            return join(self.basisordner, self.kategorie)
         def dateiname_ausgeben(self): 
                 # Mit dem Tag_objekt und dem Eingabe-Wörterbuch können wir nun den Datei-String erzeugen. 
-                tag_zu_dat_v_t = tag_zu_datei_von_tag.Datei(tag=self.tag_string, kategorie=self.kategorie_ausgeben(), version=self.version)
+                tag_zu_dat_v_t = tag_zu_datei_von_tag.Datei(tag=self.tag_string, kategorie=self.kategorie_ausgeben(), version=self.version, speicherordner_rel_zu_home=self.speicherordner_rel_zu_home)
                 datei = tag_zu_dat_v_t.dateiname_ausgeben()
                 return datei

File ews/amov/

 # Um die Dateien zu laden, nutzen wir die Objekt-Klasse. 
 import Skripte.Kernskripte.ein_und_ausgabe.tag_zu_datei_von_tag as tag_zu_datei
+# Außerdem müssen wir Pfade Plattformunabhängig verbinden können. 
+from os.path import join
+from Skripte.Kernskripte.ein_und_ausgabe.tag_zu_datei_von_tag import BASISORDNER
 #### Imports ####
     """Manage Versions. 
     ToDo: Rewrite, so that data about the file-path is taken from an ID object again (self.finde_neuste_datei())."""
-    def __init__(self, tag=u",2007:Menschen", kategorie=u"Armeen"): 
+    def __init__(self, tag=u",2007:Menschen", kategorie=u"Armeen", speicherordner_rel_zu_home = ".amov"): 
         #: the unique identifier for content, barring the cathegory. 
         self.tag = tag 
         #: The type of objekt we want to retrieve. 
-        self.kategorie = kategorie 
+        self.kategorie = kategorie
+        self.BASISORDNER = join(BASISORDNER, speicherordner_rel_zu_home)
         #: The ID including the most recent version of the objekt. 
         self.neuste = self.neuste_version() 
         #: The filepacth to the file with the most recent version. ToDo: Check and Remove, since this breaks the levels, which state that on this level only tag strings and ID dicts should be exchanged. 
         result_list = []
         # print "name =", name, ", pfad =", pfad
         # list all files. 
-        if not os.path.isdir(pfad): 
-            os.makedirs(pfad)
-        for i in os.listdir(pfad):
+        if not os.path.isdir(join(self.BASISORDNER, pfad)): 
+            os.makedirs(join(self.BASISORDNER, pfad))
+        for i in os.listdir(join(self.BASISORDNER, pfad)):
             # If the file begins with the name and ends with ".yml" add it to the list of matching files. 
             if i.find(name, 0, len(name)) != -1 and i[-4:] == ".yml":
-                result_list.append(pfad + TRENNER_ORDNER + i) # TODO: Use os.path.join()
+                result_list.append(join(self.BASISORDNER, pfad) + TRENNER_ORDNER + i) 
         return result_list
     def finde_neuste_datei(self, tag, pfad):
         # creation from amov template/char
         self.source = source
         self.ID = Versionsverwaltung.Versionen(self.source, _(u"Vorlagen")).neuste
+        print self.ID
         self.amov = Charakter.Charakter(self.ID)
         # rank


-from textrpg import Char, story
-char1 = Char()
+#!/usr/bin/env python
+# encoding: utf-8
-story('''Where the sun doesn't shine, 
+from textrpg import Char, story, ask
+from save import save
+name = ask("What's your name?")
+# First load the chars for better gameflow. 
+char2 = Char(source=",2008:Nasfar")
+char1 = Char(source=",2008:" + name)
+Where the sun doesn't shine, 
 and the stars flicker and wane, 
 and terror reigns over the land, 
 a hero is born to save us. 
 Or not.
-char2 = Char()
 char2.say("""I don't know about life or death or anything. I only know I want to live. 
 I don't know about heroes, they come and go, but I persist, and I follow them when they move across the lands. 
 But I live to live, so don't hope for my help, either. 
 Please don't hope for my help.
+char1.say("""You're a wimp!
+I'll show you "don't hope for my help"!
+It's time to die!
+won = char1.battle(char2)
+if won:
+    char1.say("So much for 'you survive'!")
+    story(char1.upgrade(1))
+    char2.say("Harr! You won't be the one to kill me!")
+story("""And thus ends another battle on the plains of darkness.""")
+save([char1, char2])
 #!/usr/bin/env python
 # encoding: utf-8
-# first try: Linear
+"""TextRPG - Simple TextRPG module built on top of the 1d6 RPG library.
-# TODO: Lazy loading modules, to be able to print stuff at once without having to print before the imports.
+first try: Linear
+TODO: Lazy loading modules, to be able to print stuff at once without having to print before the imports.
+    - Simple to use functions in easy to read scriptfiles in the style of the ministory file. 
 print "...Loading rpg library..."
     return str(text)
 class Char(ews_char):
-    def __init__(self, *args, **kwds): 
-        super(Char, self).__init__(*args, **kwds)
+    def __init__(self, template=False, *args, **kwds): 
+        super(Char, self).__init__(template=False, *args, **kwds)
         self.battle_diff_treshold = 4 #: The treshold of the char below which no hit is scored. 
     def battle_stats(self):
             if i.strip() != "": 
                 diag( + ': ' + i, localize=False)
             # If the string is empty, just add a blank line without the characters name. 
-            else: diag(i, localize=False)
+            else: diag("...", localize=False)
     def fight_round(self, other, *args, **kwds): 
         """Fight for one round."""
         return super(Char, self).fight_round(other, *args, **kwds)
+    def battle(self, other): 
+        """Fight a dadly battle."""
+        return battle(self, other)
+def ask(question): 
+    """Ask a question."""
+    return raw_input(_(question) + " ")
 def story(data):
 	data = _(data)
 		diag(i, localize=False)
+def save(chars=[]):
+        """Save the current state."""
+        for i in chars:
 def diag(data, localize=True):
 	if localize: 
     return won
+def battle(me, other): 
+    return fight_while_standing(me, other)
 def fight_while_standing(me, other):
     '''Fight as long as both characters are still active.