home · contact · privacy
Add FLATTEN_SURROUNDINGS task.
authorChristian Heller <c.heller@plomlompom.de>
Sun, 25 Oct 2020 04:29:11 +0000 (05:29 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Sun, 25 Oct 2020 04:29:11 +0000 (05:29 +0100)
new2/plomrogue/game.py
new2/plomrogue/mapping.py
new2/plomrogue/tasks.py
new2/rogue_chat.html

index 4a4f2972756832a647582cdc5503a60e7d329b42..55f7c726a9020f07850e6dcb80c094c4481d8841 100755 (executable)
@@ -1,4 +1,5 @@
-from plomrogue.tasks import Task_WAIT, Task_MOVE, Task_WRITE
+from plomrogue.tasks import (Task_WAIT, Task_MOVE, Task_WRITE,
+                             Task_FLATTEN_SURROUNDINGS)
 from plomrogue.errors import GameError
 from plomrogue.commands import (cmd_ALL, cmd_LOGIN, cmd_QUERY, cmd_PING,
                                 cmd_TURN, cmd_MAP_LINE)
@@ -39,7 +40,8 @@ class Game(GameBase):
         self.io = GameIO(self, save_file)
         self.tasks = {'WAIT': Task_WAIT,
                       'MOVE': Task_MOVE,
-                      'WRITE': Task_WRITE}
+                      'WRITE': Task_WRITE,
+                      'FLATTEN_SURROUNDINGS': Task_FLATTEN_SURROUNDINGS}
         self.map_geometry = MapGeometrySquare(YX(24, 40))
         self.commands = {'QUERY': cmd_QUERY,
                          'ALL': cmd_ALL,
index 39aff658bee8682fa738244879166fe6f0c250fe..2edbea84809acbfc759aed7993e603ffdb9c74e6 100644 (file)
@@ -27,6 +27,12 @@ class MapGeometry():
                 directions += [name[5:]]
         return directions
 
+    def get_neighbors(self, pos):
+        neighbors = {}
+        for direction in self.get_directions():
+            neighbors[direction] = self.move(pos, direction)
+        return neighbors
+
     def move(self, start_pos, direction):
         mover = getattr(self, 'move_' + direction)
         target = mover(start_pos)
index e60012250baed701d8c99f61e6508d90a5980dcd..0fe68791d9ee779df2f6160a8f85bc0f2ade9dcf 100644 (file)
@@ -53,3 +53,17 @@ class Task_WRITE(Task):
 
     def do(self):
         self.thing.game.map[self.thing.position] = self.args[0]
+
+
+
+class Task_FLATTEN_SURROUNDINGS(Task):
+    todo = 10
+
+    def check(self):
+        pass
+
+    def do(self):
+        self.thing.game.map[self.thing.position] = '.'
+        for yx in self.thing.game.map_geometry.get_neighbors(self.thing.position).values():
+            if yx is not None:
+                self.thing.game.map[yx] = '.'
index 6b37d6cdea41cf266afe3b0d9f5c5f5ecfb026fd..a61269385ab41c6ae1cb00f27fe20c8ad068fe5c 100644 (file)
@@ -164,7 +164,7 @@ tui.draw_turn_line();
 tui.draw_history();
 tui.draw_input_line();
 
-tui.log_msg("commands:", 1);
+tui.log_msg("basic commands:", 1);
 tui.log_msg("LOGIN USER - register as USER", 3);
 tui.log_msg("ALL TEXT - send TEXT to all users", 3);
 tui.log_msg("QUERY USER TEXT - send TEXT to USER", 3);
@@ -175,6 +175,9 @@ tui.log_msg("Use double quotes for strings that contain whitespace, escape them
 tui.log_msg("");
 tui.log_msg("To change the map cell you are standing on, type the desired ASCII character into the prompt and hit Return.", 1);
 tui.log_msg("");
+tui.log_msg("more commands:", 1);
+tui.log_msg("FLATTEN - transform surrounding map cells to \".\" ones", 3);
+tui.log_msg("");
 
 document.addEventListener('keydown', (event) => {
   if (chat.input_line === '') {
@@ -189,6 +192,8 @@ document.addEventListener('keydown', (event) => {
   } else if (event.key === 'Enter') {
     if (chat.input_line.length === 1) {
       websocket.send("TASK:WRITE " + chat.input_line);
+    } else if (chat.input_line.trimEnd() === 'FLATTEN') {
+      websocket.send("TASK:FLATTEN_SURROUNDINGS");
     } else {
       websocket.send(chat.input_line);
     }