Commits

Anonymous committed 89d0319

Added a simple RPG story written for the german python forum (python-forum.de).

Comments (0)

Files changed (2)

rpg_lib/anyrpg.py

         for i in data.split("\n"): 
             self.diag(self.name + ': ' + i, localize=False)
     
+    def ask(self, data, localize=False, *args, **kwds): 
+        """Say something -> Show that the char says it."""
+        data = _(data)
+        for i in data.split("\n")[:-1]: 
+            self.diag(self.name + ': ' + i, localize=localize, *args, **kwds)
+        return super(Char, self).ask(self.name + ': ' + data.split("\n")[-1], *args, **kwds)
+    
     def act(self, data): 
         """Do something -> Show that the char does it in the style "<name> walks away.".
         
+#!/usr/bin/env python
+# encoding: utf-8
+
+from rpg_lib.textrpg import *
+
+hero = Char() # a generic human :)
+peasant = Char(template=True) # A random human with random name. 
+enemy = Char() # another generic human :)
+
+
+story("""Welcome to the world of easy RPG scripting. 
+
+I hope you enjoy your stay!
+""")
+
+hero.say("""And welcome from me, too!
+
+I hope we'll be able to go adventuring, soon!
+
+besides: I'm Darjad Merejn.""")
+
+hero.name = "Darjad Merejn"
+
+hero.say("""So now you know my name. Would you tell me yours?""")
+
+name = ask("Your name:")
+
+player = Char(source="tag:1w6.org,2008:" + name)
+
+hero.say("So this time in style: Welcome " + player.name + "!")
+
+enemy.say("""How nice to see you. I hope you enjoy your glee. 
+
+It won't last too long.
+""")
+
+hero.say("""How dare you come here! 
+
+I'll splatter your guts, Granash Barn!""")
+
+enemy.name = "Granash Barn"
+
+enemy.say("""Well well, try it!""")
+
+hero.attack = 18 # A quite formidable fighter. 
+enemy.attack = 18 # Same goes for him
+
+peasant.attack = 6 # Knows not to grab a dagger from the wrong side. 
+
+peasant.act("tries to get out of the way of " + enemy.name)
+
+story(enemy.name + " attacks " + peasant.name)
+
+won = enemy.fight_round(peasant)[0]
+if won: 
+   peasant.say("""Aaargh!""")
+else: enemy.say("""Damn peasant.""")
+
+
+hero.say("""How dare you! I'll taste your blood!""")
+
+hero.act("attacks " + enemy.name)
+
+while hero.active and enemy.active: 
+   hero.fight_round(enemy)
+
+if hero.active:
+   hero.act("won.")
+   hero.say("""That's what they call villain these days. 
+
+So now to you. You look kinda sorry for him. 
+
+Seems I'll have to kill you, too.""")
+   won = player.battle(hero)
+   if not won: 
+       story("""And so the adventure of """ + player.name + """ended quite early.""")
+else:
+   enemy.act("won.")
+   enemy.say("""So much for heroes. 
+
+I hope you didn't stand with that bastard. I'm leaving. 
+
+Want to come with me?""")
+
+   join_the_enemy = ask("""Come with him? (Yes, no)""")
+
+   if join_the_enemy.lower() in ["yes", "y", ""]: 
+      enemy.say("""A wise decision. Now carry my bag.""")
+   else: 
+      enemy.say("""That's too bad. Good luck for your future. 
+
+And don't trust the heroes.
+
+Do you want to fight me, then?""")
+
+if player.active: 
+   fight = ask("Fight him? (Yes, no)")
+else:
+   fight = "No"
+if fight.lower() in ["yes", "y", ""]:
+   won = player.battle(enemy)
+   if not won:
+      story("Sorry, you lost.")
+else:
+   enemy.say("""A good fight.""")
+
+exit()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.