From: Christian Heller Date: Sun, 25 Oct 2020 04:29:11 +0000 (+0100) Subject: Add FLATTEN_SURROUNDINGS task. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/do_day?a=commitdiff_plain;h=a213ed788c8f305ea9c2192eabfb0d3562c8b2fa;p=plomrogue2-experiments Add FLATTEN_SURROUNDINGS task. --- diff --git a/new2/plomrogue/game.py b/new2/plomrogue/game.py index 4a4f297..55f7c72 100755 --- a/new2/plomrogue/game.py +++ b/new2/plomrogue/game.py @@ -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, diff --git a/new2/plomrogue/mapping.py b/new2/plomrogue/mapping.py index 39aff65..2edbea8 100644 --- a/new2/plomrogue/mapping.py +++ b/new2/plomrogue/mapping.py @@ -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) diff --git a/new2/plomrogue/tasks.py b/new2/plomrogue/tasks.py index e600122..0fe6879 100644 --- a/new2/plomrogue/tasks.py +++ b/new2/plomrogue/tasks.py @@ -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] = '.' diff --git a/new2/rogue_chat.html b/new2/rogue_chat.html index 6b37d6c..a612693 100644 --- a/new2/rogue_chat.html +++ b/new2/rogue_chat.html @@ -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); }