diff --git a/PuzzlePlayer/Binary.cs b/PuzzlePlayer/Binary.cs index 833053ea16951dbac0f07230e83f54de2cc7dc44..049e30979f636fb1d1add99b6ee2569111ce3f78 100644 --- a/PuzzlePlayer/Binary.cs +++ b/PuzzlePlayer/Binary.cs @@ -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); + for (int j = 0; j < boardToSolve.GetLength(1); j++) { int[,] move = CheckMove(i, j, boardToSolve); if (move != null) @@ -141,7 +147,7 @@ namespace PuzzlePlayer_Namespace } - + return null; } // check if the space is surrounded on both sides by the same number. If it is, the checked space should be the opposite number diff --git a/PuzzlePlayer/Board.cs b/PuzzlePlayer/Board.cs index 52484ce853e54b737b4836d591dc7b6fd1f1443a..836b5bf24d149ff4fdc2d570f9af0c1fc6fe6237 100644 --- a/PuzzlePlayer/Board.cs +++ b/PuzzlePlayer/Board.cs @@ -1,5 +1,6 @@ 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() { diff --git a/PuzzlePlayer/PuzzleForm.cs b/PuzzlePlayer/PuzzleForm.cs index 7b315dc2a9d6c1a1449b2f1b1f0b4bf50dc62bbb..7c70587197b641bc6870def576c7c04a6025d72c 100644 --- a/PuzzlePlayer/PuzzleForm.cs +++ b/PuzzlePlayer/PuzzleForm.cs @@ -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() diff --git a/PuzzlePlayer/PuzzlePlayer.cs b/PuzzlePlayer/PuzzlePlayer.cs index 634cbef5a7e23136d8429d5935092e2402cffbbf..7d9431192676e5568e4dcbe2aa99a8cba1b3acfd 100644 --- a/PuzzlePlayer/PuzzlePlayer.cs +++ b/PuzzlePlayer/PuzzlePlayer.cs @@ -9,7 +9,7 @@ namespace PuzzlePlayer_Namespace { internal static void Main(string[] args) { - Application.Run(new PuzzleForm()); + Application.Run(new PuzzleForm(new Binary())); } }