Ich habe ein paar Hilfsfunktionen geschrieben, mit denen TextRPGs in reinem Python geschrieben werden können.
Die Skripte sind dabei so nah wie möglich an Skripten für Theaterstücke und trotzdem noch Python.
Im Hintergrund bindet es eine vollständige RPG Bibliothek ein, die auf einem freien (d.h. frei lizensierten) Pen-and-Paper Regelwerk aufbaut ( http://1w6.org ).
Ihr könnt es den Code bisher auf http://freehg.org/u/ArneBab/textrpg finden.
Ein Skript sieht dann zum Beispiel so aus (gerade ad-hoc geschrieben):
Code: Alles auswählen
#!/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 a 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()
Und ich hoffe, dass ich das Design sauber genug bekommen habe, dass es möglich ist, es so umzustellen, dass mit einem einfachen
from rpg_lib.graphic_rpg import *
das gleiche Skript eine GUI Umgebung nutzen kann (bzw. dass es einfach ist, ein graphic_rpg Modul zu schreiben, das das Skript ausliest).
Für einfache Nutzung habe ich die ersten zwei Kapitel eines Tutorials geschrieben (auch als TextRPG

- http://freehg.org/u/ArneBab/textrpg
(Liegt alles in einem Mercurial repository - Versionsverwaltungssystem in Python).
Ich würde mich über Rückmeldungen freuen!
