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
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)
{
gr.DrawEllipse(Pens.White,
(int)(p.X+((double)i+0.25)*s.Width),
(int)(p.Y+((double)j+0.25)*s.Height),
s.Width/2,s.Height/2);
return;
gr.FillEllipse(Brushes.White,
(int)(p.X + ((double)i + 0.125) * s.Width / boardState.GetLength(0)),
(int)(p.Y + ((double)j + 0.125) * s.Height / boardState.GetLength(1)),
s.Width / boardState.GetLength(0) * 3 / 4,
s.Height / boardState.GetLength(1) * 3 / 4);
}
if (boardState[i, j] == 1)
{
gr.DrawEllipse(Pens.Black,
(int)(p.X + ((double)i + 0.25) * s.Width),
(int)(p.Y + ((double)j + 0.25) * s.Height),
s.Width / 2, s.Height / 2);
gr.FillEllipse(Brushes.Black,
(int)(p.X + ((double)i + 0.125) * s.Width / boardState.GetLength(0)),
(int)(p.Y + ((double)j + 0.125) * s.Height / boardState.GetLength(1)),
s.Width / boardState.GetLength(0) * 3 / 4,
s.Height / boardState.GetLength(1) * 3 / 4);
}
}
}
......@@ -105,7 +111,7 @@ namespace PuzzlePlayer_Namespace
List<int[,]> result = new List<int[,]>();
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);
if (move != null)
......
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Reflection.Metadata;
using System.Text;
......@@ -26,14 +27,11 @@ namespace PuzzlePlayer_Namespace
public string description;
// a property for getting and setting the boardsstate. The boardstate should only be setted if the imputed int[,] is valid.
public int[,] boardState
{
get { return boardState; }
set { setBoardState(value); }
}
public int[,] boardState;
// 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;
boardState = newState;
......@@ -45,7 +43,7 @@ namespace PuzzlePlayer_Namespace
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
public SOLUTIONS Solve()
{
......
......@@ -17,13 +17,15 @@ namespace PuzzlePlayer_Namespace
private Label boardlabel;
private TextBox informationbox;
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; }
set
{
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
{
if (s == default(Size)) s = new Size(800, 500);
this.Size = s;
// board = b;
graphics = this.CreateGraphics();
generatebutton = new Button();
hintbutton = new Button();
solvebutton = new Button();
informationbox = new TextBox();
Board = b;
CreateUI();
UpdateUI();
this.Resize += (object sender, EventArgs ea) =>
{
UpdateUI();
};
Board.boardState[1, 1] = 1;
Board.boardState[2, 2] = 0;
}
private void CreateUI()
{
......@@ -68,16 +73,15 @@ namespace PuzzlePlayer_Namespace
solvebutton.Text = "Solve";
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);
informationbox.Multiline = true;
informationbox.Size = new Size(160, 400);
informationbox.BackColor = Color.LightGray;
informationbox.Text = $"DEFAULT1";
//informationbox.Text = board.description;
//https://stackoverflow.com/questions/224236/adding-a-newline-into-a-string-in-c-sharp
informationbox.Text = board.description;
}
private void UpdateUI()
......
......@@ -9,7 +9,7 @@ namespace PuzzlePlayer_Namespace
{
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