PKKG1Fk~~texture/game_master.py# -*- coding: utf-8 -*- # # texture game engine # https://github.com/rmed/texture # # The MIT License (MIT) # # Copyright (c) 2015 Rafael Medina García # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. from . import util import pkgutil import readline import sys if sys.version[0] == '3': raw_input=input class GameMaster(object): def __init__(self, scenarios='scenarios'): """ Object that implements the main game loop and the command input. scenarios - module that contains the scenarios. These scenarios are imported at startup recursively. """ self.current = None self.game_commands = {} self.state = {} # Import scenarios self.scenarios = {} pkg = sys.modules[scenarios] for _, modname, _ in pkgutil.iter_modules(pkg.__path__): try: mod = __import__('%s.%s' % (scenarios, modname), fromlist=['Scenario']) self.scenarios[modname] = mod.Scenario except ImportError: util.tprint('Failed to import' + modname) continue except AttributeError: util.tprint('Module "%s" is not a scenario' % modname) continue def start_game(self): """ Call the main loop. """ self._main_loop() def register_command(self, cmd, func): """ Register a game command. These commands are parsed before the scenario actions and may be used to perform special action such as restarting the game or loading a special scenario. These commands may return special strings to perform actions in the game loop: continue - next "game tick" load X - load another scenario cmd - command to match func - function to execute """ self.game_commands[cmd] = func def _change_scenario(self, name): """ Change scenario and call the scenario `load()` method. Substitutes the `self.current` reference to point to the new scenario. name - name of the scenario in the scenarios map """ # Update state if self.current: self.state = self.current.state scenario = self.scenarios.get(name, None) if not scenario: util.tprint('[ERROR] Scenario "%s" not found' % name) return self.current = scenario(self.state) self.current.load() def _exec_game_command(self, cmd): """ Try to match user input to a game command and execute its function if found. """ func = self.game_commands.get(cmd, None) if not func: return None return func(self.state) def _main_loop(self): """ Main game loop. """ # First scenario is 'start' sc_name = 'start' self._change_scenario(sc_name) while True: # Ask for input util.tnewline() cmd = raw_input('> ') util.tnewline() # Preset game commands response = self._exec_game_command(cmd) if not response: # Perform scenario action response = self.current.do_action(cmd) # Parse response if type(response) is str: # Game loop commands if response.startswith('load'): sc_name = response.split('load')[1].strip() self._change_scenario(sc_name) elif response == 'continue': continue PK KGAJPtexture/scenario.py# -*- coding: utf-8 -*- # # texture game engine # https://github.com/rmed/texture # # The MIT License (MIT) # # Copyright (c) 2015 Rafael Medina García # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. class BaseScenario(object): """ Base scenario class. Simplifies writing of the scenarios and provides the game state to every scenario. """ def __init__(self, state): self.state = state def load(self): """ Method executed when changing to this scenario. """ raise NotImplementedError def do_action(self, cmd): """ Parse the command and execute an action accordingly. """ raise NotImplementedError PKKGDha texture/util.py# -*- coding: utf-8 -*- # # texture game engine # https://github.com/rmed/texture # # The MIT License (MIT) # # Copyright (c) 2015 Rafael Medina García # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. from __future__ import print_function import sys import textwrap if sys.version[0] == '3': xrange=range def tclear(): """ Clear the screen. """ print(chr(27) + '[2J') def tnewline(times=1): """ Print the newline character. times - number of times to print the character """ for _ in xrange(0, times): print('\n') def tprint(text, dedent=True): """ Print text on screen. text - text to print dedent - whether or not to dedent the text """ if dedent: print(textwrap.dedent(text)) else: print(text) def printer(func=None, **options): """ Decorator used to print whatever text is returned in the caller function. When a list or a tuple are returned, then the contents are iterated and printed. Options: dedent - whether or not to dedent the text (default: True) """ if func: def decorator(*args, **kwargs): ret = func(*args, **kwargs) do_dedent = options.get('dedent', True) if not ret: # Nothing to print return if type(ret) is tuple or type(ret) is list: # Iterate and print all for text in ret: tprint(text, do_dedent) else: # Print single text/var tprint(ret, do_dedent) return decorator # Function was not received def partial(func): return printer(func, **options) return partial PKLaKGG{xMMtexture/__init__.py# -*- coding: utf-8 -*- # # Texture game engine # https://github.com/rmed/texture # # The MIT License (MIT) # # Copyright (c) 2015 Rafael Medina García # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. from .game_master import GameMaster from .scenario import BaseScenario from .util import tclear, tnewline, tprint, printer PK4KGG\'texture-0.1.0.dist-info/DESCRIPTION.rsttexture ======= (...) I rejected those answers. Instead, I chose something different. I chose the (im)possible. I chose... texture texture is a micro-engine for creating text-based adventures. Features -------- - Scenario based architecture - Global game state - Some utilities - Main game loop (including command input) That's it. This is only a (pretty simple) tool, and you are the artist. Want your game to calculate x digits of *pi*? Well, go for it! Documentation coming soon ------------------------- PK4KGw^%texture-0.1.0.dist-info/metadata.json{"classifiers": ["Development Status :: 4 - Beta", "Environment :: Console", "Intended Audience :: Developers", "Topic :: Games/Entertainment", "Topic :: Software Development", "Topic :: Utilities", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4"], "extensions": {"python.details": {"contacts": [{"email": "rafamedgar@gmail.com", "name": "Rafael Medina Garc\u00eda", "role": "author"}], "document_names": {"description": "DESCRIPTION.rst"}, "project_urls": {"Home": "https://github.com/rmed/texture"}}}, "generator": "bdist_wheel (0.26.0)", "keywords": ["texture", "adventure", "game", "text", "based", "old"], "license": "MIT", "metadata_version": "2.0", "name": "texture", "summary": "Micro-engine for creating text-based adventures", "version": "0.1.0"}PK3KGF// texture-0.1.0.dist-info/pbr.json{"git_version": "80a7272", "is_release": false}PK3KGp^%texture-0.1.0.dist-info/top_level.txttexture PK4KGndnntexture-0.1.0.dist-info/WHEELWheel-Version: 1.0 Generator: bdist_wheel (0.26.0) Root-Is-Purelib: true Tag: py2-none-any Tag: py3-none-any PK4KGGR texture-0.1.0.dist-info/METADATAMetadata-Version: 2.0 Name: texture Version: 0.1.0 Summary: Micro-engine for creating text-based adventures Home-page: https://github.com/rmed/texture Author: Rafael Medina García Author-email: rafamedgar@gmail.com License: MIT Keywords: texture adventure game text based old Platform: UNKNOWN Classifier: Development Status :: 4 - Beta Classifier: Environment :: Console Classifier: Intended Audience :: Developers Classifier: Topic :: Games/Entertainment Classifier: Topic :: Software Development Classifier: Topic :: Utilities Classifier: License :: OSI Approved :: MIT License Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.4 texture ======= (...) I rejected those answers. Instead, I chose something different. I chose the (im)possible. I chose... texture texture is a micro-engine for creating text-based adventures. Features -------- - Scenario based architecture - Global game state - Some utilities - Main game loop (including command input) That's it. This is only a (pretty simple) tool, and you are the artist. Want your game to calculate x digits of *pi*? Well, go for it! Documentation coming soon ------------------------- PK4KG$wwtexture-0.1.0.dist-info/RECORDtexture/__init__.py,sha256=sgXfERyzRiEvFfgCyEvZJv_S4wQ57A3hR93d1cCBoAc,1357 texture/game_master.py,sha256=u_-XSzeEh_VMFoAeIEVxCHqXdUmW1HmlH8rvegPUMNk,4734 texture/scenario.py,sha256=8495cQVsSPdBThsR2AHOzVvAirsd3e40OgtIWja3mEY,1703 texture/util.py,sha256=3qOIetA12i5pNRhDFq2spAMPHwo6rgecpF9U-N5A3wY,2782 texture-0.1.0.dist-info/DESCRIPTION.rst,sha256=pIw8x65zYXT1rtAzJdk8XtRC_Ti_XRFFsf9yjGRr9cc,528 texture-0.1.0.dist-info/METADATA,sha256=OWD7czpLnhwLrFPXSzRmd6ezK-4zJ_z3v-c_2JI0Xow,1307 texture-0.1.0.dist-info/RECORD,, texture-0.1.0.dist-info/WHEEL,sha256=GrqQvamwgBV4nLoJe0vhYRSWzWsx7xjlt74FT0SWYfE,110 texture-0.1.0.dist-info/metadata.json,sha256=h1sobM5ZPfKDVgobW3TJ-ZU-Pevq3KHXlwzdjYCp3XM,909 texture-0.1.0.dist-info/pbr.json,sha256=1WaToPD4p9xNPZ2WXL4GpjCTCTSZGAdzDrXVqcILQY8,47 texture-0.1.0.dist-info/top_level.txt,sha256=odWZztv-JzJnXVs5Tg9XkD6yutmxywCZ1BfKeMfJH14,8 PKKG1Fk~~texture/game_master.pyPK KGAJPtexture/scenario.pyPKKGDha texture/util.pyPKLaKGG{xMM$texture/__init__.pyPK4KGG\'*texture-0.1.0.dist-info/DESCRIPTION.rstPK4KGw^%h,texture-0.1.0.dist-info/metadata.jsonPK3KGF// 80texture-0.1.0.dist-info/pbr.jsonPK3KGp^%0texture-0.1.0.dist-info/top_level.txtPK4KGndnn0texture-0.1.0.dist-info/WHEELPK4KGGR 1texture-0.1.0.dist-info/METADATAPK4KG$ww6texture-0.1.0.dist-info/RECORDPK 1: