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

input fixes

parent 4c71273a
No related branches found
No related tags found
No related merge requests found
......@@ -18,13 +18,13 @@ namespace PuzzlePlayer_Namespace
internal class Binary : Board
{
// constructor with boardSize parameter (default is set to 8 but can be changed)
public Binary(int boardSize = 8) // should be even
public Binary(int boardSize = 6) // should be even
{
boardState = GetClearBoard(boardSize);
description = "Binary puzzle is played on any even-numbered square grid, with some cells initially containing black or white circles. The goal of the puzzle is to fill all cells such that:\r\n● More than two circles of the same color cannot be adjacent\r\n● Each row and column must contain an equal number of black and white circles\r\n● Each row and column cannot appear multiple times on the board";
description = "Binary puzzle is played on any even-numbered square grid, with some cells initially containing black or white circles. The goal of the puzzle is to fill all cells such that:\r\n● More than two circles of the same color cannot be adjacent\r\n● Each row and column must contain an equal number of black and white circles";
drawFactor = 8;
// clear the board (fill it in with -1)
//Clear(false);
}
......@@ -452,8 +452,25 @@ namespace PuzzlePlayer_Namespace
}
public override void TileInput(Point p, int x)
{
if (x==0 || x==1) boardState[p.X, p.Y] = x;
if (x==0 || x==1 || x==2) boardState[p.X, p.Y] = x%2;
}
public override void TileClick(Point p, int x)
{
if (boardState[p.X, p.Y] == -1)
{
boardState[p.X, p.Y] = x;
return;
}
if (boardState[p.X, p.Y] == x)
{
boardState[p.X, p.Y] = 1 - boardState[p.X, p.Y];
return;
}
if (boardState[p.X, p.Y] == 1 - x)
{
boardState[p.X, p.Y] = -1;
}
}
}
}
\ No newline at end of file
......@@ -39,6 +39,7 @@ namespace PuzzlePlayer_Namespace
{
protected const int emptySpace = -1; // for every puzzle -1 represents a empty space
public string description;
public int drawFactor; // setting this to 1 always works
// variables to keep track of the board state and the last generated board
public int[,] boardState;
......
......@@ -19,6 +19,9 @@ namespace PuzzlePlayer_Namespace
private readonly Label titlebox;
private readonly Label informationbox;
private Rectangle boardspace;
private readonly MenuStrip menuStrip;
private readonly ToolStripMenuItem menuSettings;
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
......@@ -52,7 +55,24 @@ namespace PuzzlePlayer_Namespace
titlebox = new Label();
informationbox = new Label();
boardspace = new Rectangle(220, 30, 400, 400);
MenuStrip menuStrip = new MenuStrip
{
BackColor = SettingForm.secondaryColor,
ForeColor = SettingForm.secondaryColor,
Name = "Main menu",
Text = "Main Menu",
Dock = DockStyle.Top,
Font = SettingForm.mainFont,
};
ToolStripMenuItem menuSettings = new ToolStripMenuItem
{
BackColor = Color.FromArgb(54, 57, 62),
ForeColor = Color.Black,
Text = "Settings",
TextAlign = ContentAlignment.BottomRight,
Font = SettingForm.mainFont,
};
this.Paint += (object o, PaintEventArgs pea) =>
{
board.Draw(bufferedGraphics.Graphics, boardspace);
......@@ -63,6 +83,7 @@ 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)
......@@ -100,21 +121,21 @@ namespace PuzzlePlayer_Namespace
generatebutton.MouseClick += (object sender, MouseEventArgs mea) =>
{
Board.Generate();
Board = Board;
this.Invalidate();
};
CreateButton(hintbutton);
hintbutton.Text = "Hint";
hintbutton.MouseClick += (object sender, MouseEventArgs mea) =>
{
MessageBox.Show("Hint: geef op");
Board = Board;
this.Invalidate();
};
CreateButton(solvebutton);
solvebutton.Text = "Solve";
solvebutton.MouseClick += (object sender, MouseEventArgs mea) =>
{
Board.Solve(false);
Board = Board;
this.Invalidate();
};
CreateButton(UPDATEBUTTON);
......@@ -141,12 +162,13 @@ namespace PuzzlePlayer_Namespace
informationbox.ForeColor = Color.White;
informationbox.Text = board.description;
informationbox.Font = new Font("Verdana", 10);
UpdateUI();
}
private void UpdateUI() //resizes the boardspace rectangle and updates the rest of the ui around the new boardspace size
{
bufferedGraphics.Graphics.Clear(this.BackColor);
boardspace.Size = FitBoard(new Size(Board.boardState.GetLength(0),Board.boardState.GetLength(1)),new Size(this.Width - 350, this.Height - 100),8);
boardspace.Size = FitBoard(new Size(Board.boardState.GetLength(0), Board.boardState.GetLength(1)), new Size(this.Width - 350, this.Height - 100), Board.drawFactor);
generatebutton.Location = new Point(boardspace.Right + 30, 30);
hintbutton.Location = new Point(boardspace.Right + 30, 110);
solvebutton.Location = new Point(boardspace.Right + 30, 190);
......@@ -174,11 +196,14 @@ namespace PuzzlePlayer_Namespace
switch (c)
{
case 'n':
this.Invalidate();
return;
case 'h':
MessageBox.Show("Hint: geef op");
this.Invalidate();
return;
case 's':
this.Invalidate();
return;
}
......@@ -186,12 +211,14 @@ namespace PuzzlePlayer_Namespace
if (!(tile.X >= 0 && tile.X < Board.boardState.GetLength(0) && tile.Y >= 0 && tile.Y < Board.boardState.GetLength(1))) return;
if (c == '[' || c == ']') // '[' = 91, ']' = 93
{
//Board.TileClick(tile, (c - 91) / 2);
Board.TileClick(tile, (c - 91) / 2);
this.Invalidate();
return;
}
if (char.GetNumericValue(c) != -1)
{
Board.TileInput(tile, (int)char.GetNumericValue(c));
this.Invalidate();
return;
}
MessageBox.Show("uhoh");
......
......@@ -124,7 +124,7 @@ namespace PuzzlePlayer_Namespace
button.MouseClick += (object o, MouseEventArgs e) =>
{
this.Hide();
PuzzleForm puzzleForm = new PuzzleForm(new Binary(6));
PuzzleForm puzzleForm = new PuzzleForm(new Binary());
puzzleForm.FormClosed += (object o, FormClosedEventArgs fcea) =>
{
this.BackColor = SettingForm.primaryColor;
......
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