From f90b4dda3f550f60a6464f21a90b7ed368dd537e Mon Sep 17 00:00:00 2001
From: Floris <f.k.h.vandezande@students.uu.nl>
Date: Thu, 28 Nov 2024 11:36:40 +0100
Subject: [PATCH] update

---
 PuzzlePlayer/Binary.cs     | 10 ++++++++--
 PuzzlePlayer/PuzzleForm.cs | 32 +++++++++++++++++++-------------
 2 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/PuzzlePlayer/Binary.cs b/PuzzlePlayer/Binary.cs
index 3458fd9..12aa1f2 100644
--- a/PuzzlePlayer/Binary.cs
+++ b/PuzzlePlayer/Binary.cs
@@ -30,12 +30,13 @@ namespace PuzzlePlayer_Namespace
         public override void Draw (Graphics gr, Rectangle r) //draws board in rectangle R. warning: will stretch image unless FitBoard() is used for rectangle size
         {
             Size tilesize = new Size(r.Width / boardState.GetLength(0), r.Height / boardState.GetLength(1));
-            gr.FillRectangle(Brushes.Gainsboro, r.X, r.Y, tilesize.Width*boardState.GetLength(0), tilesize.Height*boardState.GetLength(1));
+            Pen border = new Pen(Color.Black, 2);
+            gr.FillRectangle(Brushes.Beige, r.X, r.Y, tilesize.Width*boardState.GetLength(0), tilesize.Height*boardState.GetLength(1));
             for (int i = 0; i < boardState.GetLength(0); i++)
             {
                 for(int j = 0; j < boardState.GetLength(1); j++)
                 {
-                    gr.DrawRectangle(Pens.Black,
+                    gr.DrawRectangle(Pens.LightGray,
                         r.X+i* tilesize.Width,
                         r.Y+j* tilesize.Height,
                         tilesize.Width,
@@ -47,6 +48,11 @@ namespace PuzzlePlayer_Namespace
                             (int)(r.Y + ((double)j + 0.125) * tilesize.Height),
                             tilesize.Width * 3 / 4,
                             tilesize.Height * 3 / 4);
+                        gr.DrawEllipse(border,
+                            (int)(r.X + ((double)i + 0.125) * tilesize.Width + border.Width/2),
+                            (int)(r.Y + ((double)j + 0.125) * tilesize.Height + border.Width/2),
+                            tilesize.Width * 3 / 4 - border.Width,
+                            tilesize.Height * 3 / 4 - border.Width);
                     }
                     if (boardState[i, j] == 1)
                     {
diff --git a/PuzzlePlayer/PuzzleForm.cs b/PuzzlePlayer/PuzzleForm.cs
index f9d6f7b..8b3aaf7 100644
--- a/PuzzlePlayer/PuzzleForm.cs
+++ b/PuzzlePlayer/PuzzleForm.cs
@@ -31,10 +31,11 @@ namespace PuzzlePlayer_Namespace
 
         public PuzzleForm(Board b = null, Size s = default(Size)) //Takes Board and Size parameter and sets up the PuzzleForm window.
         {
-            if (s == default(Size)) s = new Size(800, 500);
-            this.Size = s;
+            if (s == default(Size)) s = new Size(700, 420);
+            this.Size = this.MinimumSize = s;
             this.WindowState = FormWindowState.Maximized;
-            this.BackColor = Color.Beige;
+            this.BackColor = Color.DarkGreen;
+            this.Text = "top text";
             graphics = this.CreateGraphics();
             graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
             generatebutton = new Button();
@@ -44,19 +45,17 @@ namespace PuzzlePlayer_Namespace
             boardspace = new Rectangle(220, 30, 400, 400);
             this.Paint += (object o, PaintEventArgs pea) =>
             {
-                graphics.Clear(this.BackColor);
                 board.Draw(graphics, boardspace);
-                //graphics.FillRectangle(Brushes.LightCoral, 220, 30, this.Width - 400, this.Height - 100);
-                //graphics.FillRectangle(Brushes.DarkRed, 220, 30, boardspace.Width*Board.boardState.GetLength(0), boardspace.Height * Board.boardState.GetLength(1));
+                //graphics.FillRectangle(Brushes.LightCoral, 220, 30, this.Width - 380, this.Height - 100);
+                //graphics.FillRectangle(Brushes.DarkRed, boardspace);
             };
             this.Resize += (object o, EventArgs ea) => UpdateUI();
             Board = b;
             CreateUI();
-            UpdateUI();
             Board.boardState[1, 1] = 1;
             Board.boardState[2, 2] = 0;
         }
-        private void CreateUI()
+        private void CreateUI() //sets up ui elements
         {
             void CreateButton(Button b)
             {
@@ -87,26 +86,33 @@ namespace PuzzlePlayer_Namespace
 
             Controls.Add(informationbox);
             informationbox.Multiline = true;
-            informationbox.Size = new Size(160, 400);
+            informationbox.Size = new Size(160, 300);
             informationbox.BackColor = Color.LightGray;
             informationbox.Text = board.description;
+            informationbox.Font = new Font("Verdana", 10);
+            UpdateUI();
         }
-        private void UpdateUI()
+        private void UpdateUI() //resizes the boardspace rectangle and updates the rest of the ui around the new boardspace size
         {
-            boardspace.Size = FitBoard(new Size(Board.boardState.GetLength(0),Board.boardState.GetLength(1)),new Size(this.Width - 400, this.Height - 100),8);
+            graphics.Clear(this.BackColor);
+            boardspace.Size = FitBoard(new Size(Board.boardState.GetLength(0),Board.boardState.GetLength(1)),new Size(this.Width - 380, this.Height - 100),8);
             generatebutton.Location = new Point(boardspace.Right + 30, 30);
             hintbutton.Location = new Point(boardspace.Right + 30, 130);
             solvebutton.Location = new Point(boardspace.Right + 30, 230);
             informationbox.Location = new Point(40, 30);
             this.Invalidate();
         }
-        public static Size FitBoard(Size gamesize, Size maxboardsize, int drawfactor)
+        public static Size FitBoard(Size gamesize, Size maxboardsize, int drawfactor) //returns the largest rectangle smaller than MaxBoardSize that fits the given GameSize well
         {
-            int TileLength = Math.Min(maxboardsize.Width / gamesize.Width, maxboardsize.Height / gamesize.Height)/drawfactor*drawfactor;
+            int TileLength = Math.Min(maxboardsize.Width / gamesize.Width, maxboardsize.Height / gamesize.Height) / drawfactor * drawfactor;
             return new Size(gamesize.Width*TileLength, gamesize.Height*TileLength);
             //After each of the divisions in this method, the value should be rounded down,
             //as the end value cannot exceed the size given by maxboardsize.
             //however, C# rounds divisions of Int values down by default, so this does not have to be explicitly done.
         }
+        public static Point GetTile(Point p)
+        {
+            return p;
+        }
     }
 }
-- 
GitLab