From 68d4f3adf02deeeefb0bff0580574fc7a7de08b0 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Tue, 12 Nov 2024 23:13:08 +0100 Subject: [PATCH] add sweeping to drawing game --- src/app/DrawingGame.h | 56 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/src/app/DrawingGame.h b/src/app/DrawingGame.h index b162822..da88be3 100644 --- a/src/app/DrawingGame.h +++ b/src/app/DrawingGame.h @@ -122,21 +122,29 @@ public: AddDigit(c - '0'); break; case 'w': case 'W': - case 'i': case 'I': MoveUp(); break; case 's': case 'S': - case 'k': case 'K': MoveDown(); break; case 'a': case 'A': - case 'j': case 'J': MoveLeft(); break; case 'd': case 'D': - case 'l': case 'L': MoveRight(); break; + case 'i': case 'I': + SweepUp(); + break; + case 'k': case 'K': + SweepDown(); + break; + case 'j': case 'J': + SweepLeft(); + break; + case 'l': case 'L': + SweepRight(); + break; case 'r': case 'R': SetRed(); break; @@ -235,6 +243,46 @@ public: ConsumeNumber(); } + void SweepUp() { + int distance = GetAbsoluteNumber(1, h) % h; + for (int i = 0; i < distance; ++i) { + y = (y + h - 1) % h; + Paste(); + } + text_dirty = true; + ConsumeNumber(); + } + + void SweepDown() { + int distance = GetAbsoluteNumber(1, h) % h; + for (int i = 0; i < distance; ++i) { + y = (y + 1) % h; + Paste(); + } + text_dirty = true; + ConsumeNumber(); + } + + void SweepLeft() { + int distance = GetAbsoluteNumber(1, w) % w; + for (int i = 0; i < distance; ++i) { + x = (x + w - 1) % w; + Paste(); + } + text_dirty = true; + ConsumeNumber(); + } + + void SweepRight() { + int distance = GetAbsoluteNumber(1, w) % w; + for (int i = 0; i < distance; ++i) { + x = (x + 1) % w; + Paste(); + } + text_dirty = true; + ConsumeNumber(); + } + void SetColor(const gfx::ColorRGB &c) { cells[y * w + x] = c; } -- 2.39.2