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

Merge branch 'generalfixes'

parents 55b0a16b 665a94aa
No related branches found
No related tags found
No related merge requests found
...@@ -18,13 +18,13 @@ namespace PuzzlePlayer_Namespace ...@@ -18,13 +18,13 @@ namespace PuzzlePlayer_Namespace
internal class Binary : Board internal class Binary : Board
{ {
// constructor with boardSize parameter (default is set to 8 but can be changed) // 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); 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 the board (fill it in with -1)
//Clear(false); //Clear(false);
} }
...@@ -459,8 +459,25 @@ namespace PuzzlePlayer_Namespace ...@@ -459,8 +459,25 @@ namespace PuzzlePlayer_Namespace
} }
public override void TileInput(Point p, int x) 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 ...@@ -39,6 +39,7 @@ namespace PuzzlePlayer_Namespace
{ {
protected const int emptySpace = -1; // for every puzzle -1 represents a empty space protected 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
// variables to keep track of the board state and the last generated board // variables to keep track of the board state and the last generated board
public int[,] boardState; public int[,] boardState;
......
...@@ -19,6 +19,9 @@ namespace PuzzlePlayer_Namespace ...@@ -19,6 +19,9 @@ namespace PuzzlePlayer_Namespace
private readonly Label titlebox; private readonly Label titlebox;
private readonly Label informationbox; private readonly Label informationbox;
private Rectangle boardspace; private Rectangle boardspace;
private readonly MenuStrip menuStrip;
private readonly ToolStripMenuItem menuSettings;
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
...@@ -52,7 +55,24 @@ namespace PuzzlePlayer_Namespace ...@@ -52,7 +55,24 @@ namespace PuzzlePlayer_Namespace
titlebox = new Label(); titlebox = new Label();
informationbox = new Label(); informationbox = new Label();
boardspace = new Rectangle(220, 30, 400, 400); 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) => this.Paint += (object o, PaintEventArgs pea) =>
{ {
board.Draw(bufferedGraphics.Graphics, boardspace); board.Draw(bufferedGraphics.Graphics, boardspace);
...@@ -63,6 +83,7 @@ namespace PuzzlePlayer_Namespace ...@@ -63,6 +83,7 @@ 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)
...@@ -100,21 +121,21 @@ namespace PuzzlePlayer_Namespace ...@@ -100,21 +121,21 @@ namespace PuzzlePlayer_Namespace
generatebutton.MouseClick += (object sender, MouseEventArgs mea) => generatebutton.MouseClick += (object sender, MouseEventArgs mea) =>
{ {
Board.Generate(); Board.Generate();
Board = Board; this.Invalidate();
}; };
CreateButton(hintbutton); CreateButton(hintbutton);
hintbutton.Text = "Hint"; hintbutton.Text = "Hint";
hintbutton.MouseClick += (object sender, MouseEventArgs mea) => hintbutton.MouseClick += (object sender, MouseEventArgs mea) =>
{ {
MessageBox.Show("Hint: geef op"); MessageBox.Show("Hint: geef op");
Board = Board; this.Invalidate();
}; };
CreateButton(solvebutton); CreateButton(solvebutton);
solvebutton.Text = "Solve"; solvebutton.Text = "Solve";
solvebutton.MouseClick += (object sender, MouseEventArgs mea) => solvebutton.MouseClick += (object sender, MouseEventArgs mea) =>
{ {
Board.Solve(false); Board.Solve(false);
Board = Board; this.Invalidate();
}; };
CreateButton(UPDATEBUTTON); CreateButton(UPDATEBUTTON);
...@@ -141,12 +162,13 @@ namespace PuzzlePlayer_Namespace ...@@ -141,12 +162,13 @@ namespace PuzzlePlayer_Namespace
informationbox.ForeColor = Color.White; informationbox.ForeColor = Color.White;
informationbox.Text = board.description; informationbox.Text = board.description;
informationbox.Font = new Font("Verdana", 10); informationbox.Font = new Font("Verdana", 10);
UpdateUI(); UpdateUI();
} }
private void UpdateUI() //resizes the boardspace rectangle and updates the rest of the ui around the new boardspace size private void UpdateUI() //resizes the boardspace rectangle and updates the rest of the ui around the new boardspace size
{ {
bufferedGraphics.Graphics.Clear(this.BackColor); 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); generatebutton.Location = new Point(boardspace.Right + 30, 30);
hintbutton.Location = new Point(boardspace.Right + 30, 110); hintbutton.Location = new Point(boardspace.Right + 30, 110);
solvebutton.Location = new Point(boardspace.Right + 30, 190); solvebutton.Location = new Point(boardspace.Right + 30, 190);
...@@ -174,11 +196,14 @@ namespace PuzzlePlayer_Namespace ...@@ -174,11 +196,14 @@ namespace PuzzlePlayer_Namespace
switch (c) switch (c)
{ {
case 'n': case 'n':
this.Invalidate();
return; return;
case 'h': case 'h':
MessageBox.Show("Hint: geef op"); MessageBox.Show("Hint: geef op");
this.Invalidate();
return; return;
case 's': case 's':
this.Invalidate();
return; return;
} }
...@@ -186,12 +211,14 @@ namespace PuzzlePlayer_Namespace ...@@ -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 (!(tile.X >= 0 && tile.X < Board.boardState.GetLength(0) && tile.Y >= 0 && tile.Y < Board.boardState.GetLength(1))) return;
if (c == '[' || c == ']') // '[' = 91, ']' = 93 if (c == '[' || c == ']') // '[' = 91, ']' = 93
{ {
//Board.TileClick(tile, (c - 91) / 2); Board.TileClick(tile, (c - 91) / 2);
this.Invalidate();
return; return;
} }
if (char.GetNumericValue(c) != -1) if (char.GetNumericValue(c) != -1)
{ {
Board.TileInput(tile, (int)char.GetNumericValue(c)); Board.TileInput(tile, (int)char.GetNumericValue(c));
this.Invalidate();
return; return;
} }
MessageBox.Show("uhoh"); MessageBox.Show("uhoh");
......
...@@ -124,7 +124,7 @@ namespace PuzzlePlayer_Namespace ...@@ -124,7 +124,7 @@ namespace PuzzlePlayer_Namespace
button.MouseClick += (object o, MouseEventArgs e) => button.MouseClick += (object o, MouseEventArgs e) =>
{ {
this.Hide(); this.Hide();
PuzzleForm puzzleForm = new PuzzleForm(new Binary(6)); PuzzleForm puzzleForm = new PuzzleForm(new Binary());
puzzleForm.FormClosed += (object o, FormClosedEventArgs fcea) => puzzleForm.FormClosed += (object o, FormClosedEventArgs fcea) =>
{ {
this.BackColor = SettingForm.primaryColor; 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