diff --git a/PuzzlePlayer/Binary.cs b/PuzzlePlayer/Binary.cs index 2f10fd993593af33b70de139a5eba1c303acd595..8f76b5cb65ead5eee454197a656f7805f0648f01 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 22c6bc4d4997a0008766c5b65a9f384d4059d966..0e4778440090d4734f9ae8992bb41d7263e011a8 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 819473ccc0ddf5cbeb1ab9ba74b0c1af398f65a9..aa7f924659de002e54f93313b1dcb091a11f38fe 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 129947026ebd8f2bcfe3e5729085ebb5f3003e22..76746ba1b5db718d6611b61e7a96c91a67aabba2 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 6f91df4d488ad4d590b3647107483dee8ca40b7a..309616690bfed65c8debd91294298045c562ad38 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 5423716528556f6b9cdc9f0125d9c25c92ca04c7..447c2d723129b2d7bb78aa8f42b4e652276ad8af 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)