From 6c1a2688e13280e3a253673574784f6f5581895e Mon Sep 17 00:00:00 2001
From: Floris <f.k.h.vandezande@students.uu.nl>
Date: Tue, 10 Dec 2024 12:55:23 +0100
Subject: [PATCH] maze.draw update

---
 PuzzlePlayer/Binary.cs       |  2 +-
 PuzzlePlayer/Board.cs        |  1 +
 PuzzlePlayer/Maze.cs         | 35 ++++++++++++++++++++++-------------
 PuzzlePlayer/PuzzleForm.cs   | 20 ++++++++++----------
 PuzzlePlayer/PuzzlePlayer.cs |  1 +
 PuzzlePlayer/Sudoku.cs       |  4 ++--
 6 files changed, 37 insertions(+), 26 deletions(-)

diff --git a/PuzzlePlayer/Binary.cs b/PuzzlePlayer/Binary.cs
index 2f10fd9..8f76b5c 100644
--- a/PuzzlePlayer/Binary.cs
+++ b/PuzzlePlayer/Binary.cs
@@ -94,7 +94,7 @@ namespace PuzzlePlayer_Namespace
                 counter++;
                 Debug.WriteLine($"board is null....trying for  the {counter} time");
             }
-            MessageBox.Show($"Found board in {counter} tries");
+            //MessageBox.Show($"Found board in {counter} tries");
 
             boardState = (int[,])generatedBoard.Clone();
             
diff --git a/PuzzlePlayer/Board.cs b/PuzzlePlayer/Board.cs
index 22c6bc4..0e47784 100644
--- a/PuzzlePlayer/Board.cs
+++ b/PuzzlePlayer/Board.cs
@@ -75,6 +75,7 @@ namespace PuzzlePlayer_Namespace
         }
 
         public abstract void Draw(Graphics gr, Rectangle r);
+
         // a methode for solving the whole board. It uses the private SolveStep methode untill the whole board is solved
         // it has one parameter. setting this to true will only give a return value without changing the current boardState
         public virtual SOLUTIONS Solve(bool CheckOnly)
diff --git a/PuzzlePlayer/Maze.cs b/PuzzlePlayer/Maze.cs
index 819473c..aa7f924 100644
--- a/PuzzlePlayer/Maze.cs
+++ b/PuzzlePlayer/Maze.cs
@@ -47,7 +47,7 @@ namespace PuzzlePlayer_Namespace
             Reset(sizeX, sizeY);
             lastGeneratedBoard = GetClearBoard(sizeX, sizeY);
 
-            description = "The maze is played on a square grid where each cells has walls. You need to navigate through the maze until you reach the end. Use the arrow keys or WASD to move the blue square to the end goal";
+            description = "Maze is played on a grid containing walls. You need to navigate through the maze until you reach the end. Use the arrow keys or WASD to move the blue square to the end goal";
         }
 
         private void Reset(int sizeX, int sizeY)
@@ -101,12 +101,18 @@ namespace PuzzlePlayer_Namespace
             Size tilesize = new Size(r.Width / boardState.GetLength(0), r.Height / boardState.GetLength(1));
             Pen wall = new Pen(Color.Black, tilesize.Width / 5);
 
+            // draw an indication of where the end of the maze is
+            gr.FillRectangle(Brushes.Red, r.X + tilesize.Width * (boardState.GetLength(0) - 1), r.Y + tilesize.Height * (boardState.GetLength(1) - 1), tilesize.Width, tilesize.Height);
+
             //debug colors
             //Pen wall1 = new Pen(Color.Black, tilesize.Width / 5);
             //Pen wall2 = new Pen(Color.Blue, tilesize.Width / 5);
             //Pen wall3 = new Pen(Color.Green, tilesize.Width / 5);
             //Pen wall4 = new Pen(Color.Purple, tilesize.Width / 5);
 
+            //MessageBox.Show(Convert.ToString(tilesize));
+            int extralength = tilesize.Width/10;
+
             for (int i = 0; i < boardState.GetLength(0); i++)
                 for(int j = 0; j < boardState.GetLength(1); j++)
                 {
@@ -116,25 +122,28 @@ namespace PuzzlePlayer_Namespace
                     // draw the space blue if the player has visited it
                     if (boardState[i, j] == 1)
                         gr.FillRectangle(Brushes.Blue, currentRect);
-                    if(i == playerPos.X &&  j == playerPos.Y)
-                        gr.FillRectangle(Brushes.DarkBlue, currentRect);
+                    if(i == playerPos.X && j == playerPos.Y)
+                        gr.FillRectangle(Brushes.DarkBlue, currentRect); 
+                }
+            for (int i = 0; i < boardState.GetLength(0); i++)
+            {
+                for (int j = 0; j < boardState.GetLength(1); j++)
+                {
+                    Rectangle currentRect =
+                        new Rectangle(r.X + i * tilesize.Width, r.Y + j * tilesize.Height, tilesize.Width, tilesize.Height);
 
                     // drawing walls
-                    (bool top,bool right,bool bottom,bool left) = getWallsFromNumber(mazeState[i,j]);
-
+                    (bool top, bool right, bool bottom, bool left) = getWallsFromNumber(mazeState[i, j]);
                     if (top)
-                        gr.DrawLine(wall, currentRect.Left, currentRect.Top, currentRect.Right, currentRect.Top);
+                        gr.DrawLine(wall, currentRect.Left - extralength, currentRect.Top, currentRect.Right + extralength, currentRect.Top);
                     if (right)
-                        gr.DrawLine(wall, currentRect.Right, currentRect.Top, currentRect.Right, currentRect.Bottom);
+                        gr.DrawLine(wall, currentRect.Right, currentRect.Top - extralength, currentRect.Right, currentRect.Bottom + extralength);
                     if (bottom)
-                        gr.DrawLine(wall, currentRect.Left, currentRect.Bottom, currentRect.Right, currentRect.Bottom);
+                        gr.DrawLine(wall, currentRect.Left - extralength, currentRect.Bottom, currentRect.Right + extralength, currentRect.Bottom);
                     if (left)
-                        gr.DrawLine(wall, currentRect.Left, currentRect.Bottom, currentRect.Left, currentRect.Top);
-                    
+                        gr.DrawLine(wall, currentRect.Left, currentRect.Bottom + extralength, currentRect.Left, currentRect.Top - extralength);
                 }
-
-            // draw an indication of where the end of the maze is
-            gr.FillRectangle(Brushes.Red, r.X + tilesize.Width*(boardState.GetLength(0)-1), r.Y + tilesize.Height * (boardState.GetLength(1)-1), tilesize.Width, tilesize.Height);
+            }
         }
 
         // this methode generates a Maze starting with an empty board
diff --git a/PuzzlePlayer/PuzzleForm.cs b/PuzzlePlayer/PuzzleForm.cs
index 1299470..76746ba 100644
--- a/PuzzlePlayer/PuzzleForm.cs
+++ b/PuzzlePlayer/PuzzleForm.cs
@@ -55,11 +55,11 @@ namespace PuzzlePlayer_Namespace
             UPDATEBUTTON = new Button();
             titlebox = new Label();
             informationbox = new Label();
-            boardspace = new Rectangle(220, 30, 400, 400);
+            boardspace = new Rectangle(220, 55, 400, 400);
             this.Paint += (object o, PaintEventArgs pea) =>
             {
                 board.Draw(bufferedGraphics.Graphics, boardspace);
-                //bufferedGraphics.Graphics.FillRectangle(Brushes.LightCoral, 220, 30, this.Width - 350, this.Height - 100);
+                //bufferedGraphics.Graphics.FillRectangle(Brushes.LightCoral, boardspace.X, boardspace.Y, this.Width - 350, this.Height - 125);
                 //bufferedGraphics.Graphics.FillRectangle(Brushes.DarkRed, boardspace);
                 bufferedGraphics.Render();
             };
@@ -176,7 +176,7 @@ namespace PuzzlePlayer_Namespace
             };
 
             Controls.Add(titlebox);
-            titlebox.Location = new Point(20, 15);
+            titlebox.Location = new Point(20, 40);
             titlebox.Size = new Size(180, 50);
             titlebox.BackColor = this.BackColor;
             titlebox.ForeColor = Color.White;
@@ -184,7 +184,7 @@ namespace PuzzlePlayer_Namespace
             titlebox.Font = new Font("Verdana", 24, FontStyle.Bold);
 
             Controls.Add(informationbox);
-            informationbox.Location = new Point(20, 65);
+            informationbox.Location = new Point(20, 90);
             informationbox.Size = new Size(180, 300);
             informationbox.BackColor = this.BackColor;
             informationbox.ForeColor = Color.White;
@@ -199,12 +199,12 @@ namespace PuzzlePlayer_Namespace
         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), 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);
-            restartbutton.Location = new Point(boardspace.Right + 30, 270);
-            UPDATEBUTTON.Location = new Point(boardspace.Right + 30, 350);
+            boardspace.Size = FitBoard(new Size(Board.boardState.GetLength(0), Board.boardState.GetLength(1)), new Size(this.Width - 350, this.Height - 125), Board.drawFactor);
+            generatebutton.Location = new Point(boardspace.Right + 30, 55);
+            hintbutton.Location = new Point(boardspace.Right + 30, 135);
+            solvebutton.Location = new Point(boardspace.Right + 30, 215);
+            restartbutton.Location = new Point(boardspace.Right + 30, 295);
+            UPDATEBUTTON.Location = new Point(boardspace.Right + 30, 375);
             this.Invalidate();
         }
         public static Size FitBoard(Size gamesize, Size maxboardsize, int drawfactor) //returns the largest rectangle smaller than MaxBoardSize that fits the given GameSize well
diff --git a/PuzzlePlayer/PuzzlePlayer.cs b/PuzzlePlayer/PuzzlePlayer.cs
index 6f91df4..3096166 100644
--- a/PuzzlePlayer/PuzzlePlayer.cs
+++ b/PuzzlePlayer/PuzzlePlayer.cs
@@ -143,6 +143,7 @@ namespace PuzzlePlayer_Namespace
                         this.Show();
                     };
                     puzzleForm.Show();
+                    puzzleForm.Board.Generate();
                     SetUpPuzzleForms(); //cheeky dwdw
                 };
                 buttonsPanel.Controls.Add(button);
diff --git a/PuzzlePlayer/Sudoku.cs b/PuzzlePlayer/Sudoku.cs
index 5423716..447c2d7 100644
--- a/PuzzlePlayer/Sudoku.cs
+++ b/PuzzlePlayer/Sudoku.cs
@@ -21,8 +21,8 @@ namespace PuzzlePlayer_Namespace
             boardLength = boardSize;
             rootBoardLength = (int)Math.Sqrt(boardLength);
 
-            description = "SUDOKU !!!!! !!!!";
-            drawFactor = 8;
+            description = "Sudoku is played on any perfect square-numbered grid, with some cells initially containing numbers. The goal of the puzzle is to fill all cells such that:\r\n● Each row and column must contain all of the numbers exactly once\r\n● Each box indicated by thicker lines must also contain all of the numbers exactly once\r\n● Every sudoku must have an unique solution";
+            drawFactor = 1;
         }
 
         public override void Draw(Graphics gr, Rectangle r)
-- 
GitLab