Skip to content
Snippets Groups Projects
Commit d77b73ed authored by Floris's avatar Floris
Browse files

input fixes deel 2

parent 6f317932
No related branches found
No related tags found
No related merge requests found
...@@ -463,7 +463,7 @@ namespace PuzzlePlayer_Namespace ...@@ -463,7 +463,7 @@ namespace PuzzlePlayer_Namespace
} }
public override void TileClick(Point p, int x) 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; boardState[p.X, p.Y] = x;
return; return;
...@@ -475,7 +475,7 @@ namespace PuzzlePlayer_Namespace ...@@ -475,7 +475,7 @@ namespace PuzzlePlayer_Namespace
} }
if (boardState[p.X, p.Y] == 1 - x) if (boardState[p.X, p.Y] == 1 - x)
{ {
boardState[p.X, p.Y] = -1; boardState[p.X, p.Y] = emptySpace;
} }
} }
......
...@@ -37,7 +37,7 @@ namespace PuzzlePlayer_Namespace ...@@ -37,7 +37,7 @@ namespace PuzzlePlayer_Namespace
*/ */
public abstract class Board 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 string description;
public int drawFactor; // setting this to 1 always works public int drawFactor; // setting this to 1 always works
......
...@@ -25,7 +25,6 @@ namespace PuzzlePlayer_Namespace ...@@ -25,7 +25,6 @@ namespace PuzzlePlayer_Namespace
private readonly BufferedGraphics bufferedGraphics; private readonly BufferedGraphics bufferedGraphics;
private Board board; private Board board;
public Board Board //updating the Board member will immediately call board.Draw method so that the board is updated visually public Board Board //updating the Board member will immediately call board.Draw method so that the board is updated visually
{ {
get { return board; } get { return board; }
set set
...@@ -64,7 +63,6 @@ namespace PuzzlePlayer_Namespace ...@@ -64,7 +63,6 @@ namespace PuzzlePlayer_Namespace
Dock = DockStyle.Top, Dock = DockStyle.Top,
Font = SettingForm.mainFont, Font = SettingForm.mainFont,
}; };
ToolStripMenuItem menuSettings = new ToolStripMenuItem ToolStripMenuItem menuSettings = new ToolStripMenuItem
{ {
BackColor = Color.FromArgb(54, 57, 62), BackColor = Color.FromArgb(54, 57, 62),
...@@ -83,7 +81,6 @@ namespace PuzzlePlayer_Namespace ...@@ -83,7 +81,6 @@ namespace PuzzlePlayer_Namespace
this.Resize += (object o, EventArgs ea) => UpdateUI(); this.Resize += (object o, EventArgs ea) => UpdateUI();
this.Move += (object o, EventArgs ea) => this.Focus(); this.Move += (object o, EventArgs ea) => this.Focus();
this.KeyPress += (object o, KeyPressEventArgs kea) => Input(kea.KeyChar); this.KeyPress += (object o, KeyPressEventArgs kea) => Input(kea.KeyChar);
this.KeyUp += (object o, KeyEventArgs kea) =>
this.MouseClick += (object o, MouseEventArgs mea) => this.MouseClick += (object o, MouseEventArgs mea) =>
{ {
if (mea.Button == MouseButtons.Left) if (mea.Button == MouseButtons.Left)
...@@ -152,7 +149,7 @@ namespace PuzzlePlayer_Namespace ...@@ -152,7 +149,7 @@ namespace PuzzlePlayer_Namespace
titlebox.Size = new Size(180, 50); titlebox.Size = new Size(180, 50);
titlebox.BackColor = this.BackColor; titlebox.BackColor = this.BackColor;
titlebox.ForeColor = Color.White; titlebox.ForeColor = Color.White;
titlebox.Text = "Binary"; titlebox.Text = puzzleType;
titlebox.Font = new Font("Verdana", 24, FontStyle.Bold); titlebox.Font = new Font("Verdana", 24, FontStyle.Bold);
Controls.Add(informationbox); Controls.Add(informationbox);
...@@ -192,7 +189,7 @@ namespace PuzzlePlayer_Namespace ...@@ -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 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) switch (c)
{ {
case 'n': case 'n':
...@@ -209,6 +206,12 @@ namespace PuzzlePlayer_Namespace ...@@ -209,6 +206,12 @@ namespace PuzzlePlayer_Namespace
} }
Point tile = GetTile(new Size(Board.boardState.GetLength(0), Board.boardState.GetLength(1)), boardspace, Control.MousePosition); 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 (!(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 if (c == '[' || c == ']') // '[' = 91, ']' = 93
{ {
Board.TileClick(tile, (c - 91) / 2); Board.TileClick(tile, (c - 91) / 2);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment