From d77b73ede68d79b5deb197b76a2f3ecab54ca7ff Mon Sep 17 00:00:00 2001
From: Floris <f.k.h.vandezande@students.uu.nl>
Date: Wed, 4 Dec 2024 12:37:18 +0100
Subject: [PATCH] input fixes deel 2

---
 PuzzlePlayer/Binary.cs     |  4 ++--
 PuzzlePlayer/Board.cs      |  2 +-
 PuzzlePlayer/PuzzleForm.cs | 13 ++++++++-----
 3 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/PuzzlePlayer/Binary.cs b/PuzzlePlayer/Binary.cs
index 18ad059..d3ec27f 100644
--- a/PuzzlePlayer/Binary.cs
+++ b/PuzzlePlayer/Binary.cs
@@ -463,7 +463,7 @@ namespace PuzzlePlayer_Namespace
         }
         public override void TileClick(Point p, int x)
         {
-            if (boardState[p.X, p.Y] == -1)
+            if (boardState[p.X, p.Y] == emptySpace)
             {
                 boardState[p.X, p.Y] = x;
                 return;
@@ -475,7 +475,7 @@ namespace PuzzlePlayer_Namespace
             }
             if (boardState[p.X, p.Y] == 1 - x)
             {
-                boardState[p.X, p.Y] = -1;
+                boardState[p.X, p.Y] = emptySpace;
             }
         } 
 
diff --git a/PuzzlePlayer/Board.cs b/PuzzlePlayer/Board.cs
index 7a393c6..341c3d3 100644
--- a/PuzzlePlayer/Board.cs
+++ b/PuzzlePlayer/Board.cs
@@ -37,7 +37,7 @@ namespace PuzzlePlayer_Namespace
      */
     public abstract class Board
     {
-        protected const int emptySpace = -1; // for every puzzle -1 represents a empty space
+        public const int emptySpace = -1; // for every puzzle -1 represents a empty space
         public string description;
         public int drawFactor; // setting this to 1 always works
 
diff --git a/PuzzlePlayer/PuzzleForm.cs b/PuzzlePlayer/PuzzleForm.cs
index 8090dc3..8bda503 100644
--- a/PuzzlePlayer/PuzzleForm.cs
+++ b/PuzzlePlayer/PuzzleForm.cs
@@ -25,7 +25,6 @@ namespace PuzzlePlayer_Namespace
         private readonly BufferedGraphics bufferedGraphics;
         private Board board;
         public Board Board //updating the Board member will immediately call board.Draw method so that the board is updated visually
-
         {
             get { return board; }
             set
@@ -64,7 +63,6 @@ namespace PuzzlePlayer_Namespace
                 Dock = DockStyle.Top,
                 Font = SettingForm.mainFont,
             };
-
             ToolStripMenuItem menuSettings = new ToolStripMenuItem
             {
                 BackColor = Color.FromArgb(54, 57, 62),
@@ -83,7 +81,6 @@ namespace PuzzlePlayer_Namespace
             this.Resize += (object o, EventArgs ea) => UpdateUI();
             this.Move += (object o, EventArgs ea) => this.Focus();
             this.KeyPress += (object o, KeyPressEventArgs kea) => Input(kea.KeyChar);
-            this.KeyUp += (object o, KeyEventArgs kea) =>
             this.MouseClick += (object o, MouseEventArgs mea) =>
             {
                 if (mea.Button == MouseButtons.Left)
@@ -152,7 +149,7 @@ namespace PuzzlePlayer_Namespace
             titlebox.Size = new Size(180, 50);
             titlebox.BackColor = this.BackColor;
             titlebox.ForeColor = Color.White;
-            titlebox.Text = "Binary";
+            titlebox.Text = puzzleType;
             titlebox.Font = new Font("Verdana", 24, FontStyle.Bold);
 
             Controls.Add(informationbox);
@@ -192,7 +189,7 @@ namespace PuzzlePlayer_Namespace
         }
         public void Input(char c) //checks if a command binded to the keyboard key and runs it, affects tile that is hovered on if applicable
         {
-            if (!"nhs[]1234567890".Contains(c)) return;
+            if (!$"nhs[]{(char)8}1234567890".Contains(c)) return;
             switch (c)
             {
                 case 'n':
@@ -209,6 +206,12 @@ namespace PuzzlePlayer_Namespace
             }
             Point tile = GetTile(new Size(Board.boardState.GetLength(0), Board.boardState.GetLength(1)), boardspace, Control.MousePosition);
             if (!(tile.X >= 0 && tile.X < Board.boardState.GetLength(0) && tile.Y >= 0 && tile.Y < Board.boardState.GetLength(1))) return;
+            if((int)c == 8)
+            {
+                Board.boardState[tile.X, tile.Y] = Board.emptySpace;
+                this.Invalidate();
+                return;
+            }
             if (c == '[' || c == ']') // '[' = 91, ']' = 93
             {
                 Board.TileClick(tile, (c - 91) / 2);
-- 
GitLab