home · contact · privacy
Add basic multiplayer roguelike chat example.
[plomrogue2-experiments] / new2 / plomrogue / tasks.py
diff --git a/new2/plomrogue/tasks.py b/new2/plomrogue/tasks.py
new file mode 100644 (file)
index 0000000..402dfcb
--- /dev/null
@@ -0,0 +1,46 @@
+from plomrogue.errors import GameError
+#from plomrogue.misc import quote
+from plomrogue.mapping import YX
+
+
+
+class Task:
+    argtypes = ''
+    todo = 3
+
+    def __init__(self, thing, args=()):
+        self.thing = thing
+        self.args = args
+
+    def check(self):
+        pass
+
+
+
+class Task_WAIT(Task):
+    todo = 1
+
+    def do(self):
+        return 'success'
+
+
+
+class Task_MOVE(Task):
+    argtypes = 'string:direction'
+
+    def get_move_target(self):
+        moves = {
+            'UP': YX(-1, 0),
+            'DOWN': YX(1, 0),
+            'LEFT': YX(0, -1),
+            'RIGHT': YX(0, 1),
+        }
+        return self.thing.position + moves[self.args[0]]
+
+    def check(self):
+        test_pos = self.get_move_target()
+        if test_pos.y < 0 or test_pos.x < 0 or test_pos.y >= 24 or test_pos.x >= 40: 
+            raise GameError('would move out of map')
+
+    def do(self):
+        self.thing.position = self.get_move_target()