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

Merge branch 'BinaryControls'

parents d4b2ad59 3c963424
No related branches found
No related tags found
No related merge requests found
...@@ -27,27 +27,33 @@ namespace PuzzlePlayer_Namespace ...@@ -27,27 +27,33 @@ namespace PuzzlePlayer_Namespace
Clear(); Clear();
} }
public void Draw (Graphics gr, Point p, Size s) public override void Draw (Graphics gr, Point p, Size s)
{ {
for (int i = 0; i<boardState.GetLength(0); i++) gr.FillRectangle(Brushes.Beige, p.X, p.Y, s.Width, s.Height);
for (int i = 0; i < boardState.GetLength(0); i++)
{ {
for(int j = 0; j<boardState.GetLength(1); j++) for(int j = 0; j < boardState.GetLength(1); j++)
{ {
gr.DrawRectangle(Pens.Beige, p.X+i*s.Width, p.Y+j*s.Height, s.Width, s.Height); gr.DrawRectangle(Pens.Black,
p.X+i*s.Width/boardState.GetLength(0),
p.Y+j*s.Height/boardState.GetLength(1),
s.Width / boardState.GetLength(0),
s.Height / boardState.GetLength(1));
if (boardState[i,j] == 0) if (boardState[i,j] == 0)
{ {
gr.DrawEllipse(Pens.White, gr.FillEllipse(Brushes.White,
(int)(p.X+((double)i+0.25)*s.Width), (int)(p.X + ((double)i + 0.125) * s.Width / boardState.GetLength(0)),
(int)(p.Y+((double)j+0.25)*s.Height), (int)(p.Y + ((double)j + 0.125) * s.Height / boardState.GetLength(1)),
s.Width/2,s.Height/2); s.Width / boardState.GetLength(0) * 3 / 4,
return; s.Height / boardState.GetLength(1) * 3 / 4);
} }
if (boardState[i, j] == 1) if (boardState[i, j] == 1)
{ {
gr.DrawEllipse(Pens.Black, gr.FillEllipse(Brushes.Black,
(int)(p.X + ((double)i + 0.25) * s.Width), (int)(p.X + ((double)i + 0.125) * s.Width / boardState.GetLength(0)),
(int)(p.Y + ((double)j + 0.25) * s.Height), (int)(p.Y + ((double)j + 0.125) * s.Height / boardState.GetLength(1)),
s.Width / 2, s.Height / 2); s.Width / boardState.GetLength(0) * 3 / 4,
s.Height / boardState.GetLength(1) * 3 / 4);
} }
} }
} }
...@@ -105,7 +111,7 @@ namespace PuzzlePlayer_Namespace ...@@ -105,7 +111,7 @@ namespace PuzzlePlayer_Namespace
List<int[,]> result = new List<int[,]>(); List<int[,]> result = new List<int[,]>();
for (int i = 0; i < boardToSolve.GetLength(0); i++) for (int i = 0; i < boardToSolve.GetLength(0); i++)
for (int j = 0; j < boardToSolve.GetLength(1);j++) for (int j = 0; j < boardToSolve.GetLength(1); j++)
{ {
int[,] move = CheckMove(i, j, boardToSolve); int[,] move = CheckMove(i, j, boardToSolve);
if (move != null) if (move != null)
......
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing;
using System.Linq; using System.Linq;
using System.Reflection.Metadata; using System.Reflection.Metadata;
using System.Text; using System.Text;
...@@ -26,14 +27,11 @@ namespace PuzzlePlayer_Namespace ...@@ -26,14 +27,11 @@ namespace PuzzlePlayer_Namespace
public string description; public string description;
// a property for getting and setting the boardsstate. The boardstate should only be setted if the imputed int[,] is valid. // a property for getting and setting the boardsstate. The boardstate should only be setted if the imputed int[,] is valid.
public int[,] boardState public int[,] boardState;
{
get { return boardState; }
set { setBoardState(value); }
}
// checks if the board is valid and solvable before setting the variable. // checks if the board is valid and solvable before setting the variable.
private bool setBoardState(int[,] newState) public bool setBoardState(int[,] newState)
{ {
int[,] copy = boardState; int[,] copy = boardState;
boardState = newState; boardState = newState;
...@@ -45,7 +43,7 @@ namespace PuzzlePlayer_Namespace ...@@ -45,7 +43,7 @@ namespace PuzzlePlayer_Namespace
return false; return false;
} }
} }
public abstract void Draw(Graphics gr, Point p, Size s);
// a methode for solving the whole board. It uses the private SolveStep methode untill the whole board is solved // a methode for solving the whole board. It uses the private SolveStep methode untill the whole board is solved
public SOLUTIONS Solve() public SOLUTIONS Solve()
{ {
......
...@@ -17,13 +17,15 @@ namespace PuzzlePlayer_Namespace ...@@ -17,13 +17,15 @@ namespace PuzzlePlayer_Namespace
private Label boardlabel; private Label boardlabel;
private TextBox informationbox; private TextBox informationbox;
public Graphics graphics; public Graphics graphics;
public Board board //Updating the Board member will immediately call board.Draw method so that the board is updated visually
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; } get { return board; }
set set
{ {
board = value; board = value;
//board.Draw(graphics, point, size); board.Draw(graphics, new Point(220, 30), new Size(400, 400));
} }
} }
...@@ -31,17 +33,20 @@ namespace PuzzlePlayer_Namespace ...@@ -31,17 +33,20 @@ namespace PuzzlePlayer_Namespace
{ {
if (s == default(Size)) s = new Size(800, 500); if (s == default(Size)) s = new Size(800, 500);
this.Size = s; this.Size = s;
// board = b; graphics = this.CreateGraphics();
generatebutton = new Button(); generatebutton = new Button();
hintbutton = new Button(); hintbutton = new Button();
solvebutton = new Button(); solvebutton = new Button();
informationbox = new TextBox(); informationbox = new TextBox();
Board = b;
CreateUI(); CreateUI();
UpdateUI(); UpdateUI();
this.Resize += (object sender, EventArgs ea) => this.Resize += (object sender, EventArgs ea) =>
{ {
UpdateUI(); UpdateUI();
}; };
Board.boardState[1, 1] = 1;
Board.boardState[2, 2] = 0;
} }
private void CreateUI() private void CreateUI()
{ {
...@@ -68,16 +73,15 @@ namespace PuzzlePlayer_Namespace ...@@ -68,16 +73,15 @@ namespace PuzzlePlayer_Namespace
solvebutton.Text = "Solve"; solvebutton.Text = "Solve";
solvebutton.MouseClick += (object sender, MouseEventArgs mea) => solvebutton.MouseClick += (object sender, MouseEventArgs mea) =>
{ {
//board = Board.Solve(board); //board = board.Solve();
board.Draw(graphics, new Point(220, 30), new Size(400, 400));
}; };
Controls.Add(informationbox); Controls.Add(informationbox);
informationbox.Multiline = true; informationbox.Multiline = true;
informationbox.Size = new Size(160, 400); informationbox.Size = new Size(160, 400);
informationbox.BackColor = Color.LightGray; informationbox.BackColor = Color.LightGray;
informationbox.Text = $"DEFAULT1"; informationbox.Text = board.description;
//informationbox.Text = board.description;
//https://stackoverflow.com/questions/224236/adding-a-newline-into-a-string-in-c-sharp
} }
private void UpdateUI() private void UpdateUI()
......
...@@ -9,7 +9,7 @@ namespace PuzzlePlayer_Namespace ...@@ -9,7 +9,7 @@ namespace PuzzlePlayer_Namespace
{ {
internal static void Main(string[] args) internal static void Main(string[] args)
{ {
Application.Run(new PuzzleForm()); Application.Run(new PuzzleForm(new Binary()));
} }
} }
......
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