diff --git a/PuzzlePlayer/PuzzleForm.cs b/PuzzlePlayer/PuzzleForm.cs index 1be92ff143aadddc00ab2d1f2e905e4804aff4c6..129947026ebd8f2bcfe3e5729085ebb5f3003e22 100644 --- a/PuzzlePlayer/PuzzleForm.cs +++ b/PuzzlePlayer/PuzzleForm.cs @@ -44,7 +44,7 @@ namespace PuzzlePlayer_Namespace if (s == default) s = new Size(700, 420); this.Size = this.MinimumSize = s; this.WindowState = FormWindowState.Maximized; - this.BackColor = Color.DarkGreen; + this.BackColor = SettingForm.primaryColor; this.Text = "PuzzlePlayer"; bufferedGraphics = BufferedGraphicsManager.Current.Allocate(this.CreateGraphics(), this.DisplayRectangle); bufferedGraphics.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; @@ -103,6 +103,30 @@ namespace PuzzlePlayer_Namespace menuStrip.Items.Add(menuSettings); this.Controls.Add(menuStrip); + + menuSettings.Click += (object o, EventArgs e) => + { + this.Hide(); + SettingForm settingForm = new SettingForm(); + + settingForm.FormClosed += (object s, FormClosedEventArgs args) => + { + this.BackColor = SettingForm.primaryColor; + this.ForeColor = SettingForm.tertiaryColor; + + foreach (Control control in this.Controls) + { + SettingForm.UpdateSettings(control); + } + + bufferedGraphics.Graphics.Clear(this.BackColor); + + this.Show(); + }; + + settingForm.Show(); + }; + void CreateButton(Button b) { Controls.Add(b); @@ -167,6 +191,9 @@ namespace PuzzlePlayer_Namespace informationbox.Text = board.description; informationbox.Font = new Font("Verdana", 10); + this.BackColor = SettingForm.primaryColor; + this.ForeColor = SettingForm.tertiaryColor; + UpdateUI(); } private void UpdateUI() //resizes the boardspace rectangle and updates the rest of the ui around the new boardspace size diff --git a/PuzzlePlayer/PuzzlePlayer.cs b/PuzzlePlayer/PuzzlePlayer.cs index a1a65a32a06468b4ea962acb63c6085901597781..6f91df4d488ad4d590b3647107483dee8ca40b7a 100644 --- a/PuzzlePlayer/PuzzlePlayer.cs +++ b/PuzzlePlayer/PuzzlePlayer.cs @@ -29,6 +29,7 @@ namespace PuzzlePlayer_Namespace puzzleForms.Clear(); puzzleForms.Add(new PuzzleForm(new Binary())); puzzleForms.Add(new PuzzleForm(new Maze())); + puzzleForms.Add(new PuzzleForm(new Sudoku())); } private void SetUpUI() @@ -97,6 +98,9 @@ namespace PuzzlePlayer_Namespace { string image = "../../..//Resources/" + $"{puzzleForms[i].puzzleType}"; + Image normalImage = Image.FromFile(image + ".jpg"); + Image grayImage = Image.FromFile(image + "Gray.jpg"); + // Set the name of the button RoundedButton button = new RoundedButton { @@ -104,7 +108,7 @@ namespace PuzzlePlayer_Namespace Margin = new Padding(10), Height = 345, Width = 345, - Image = Image.FromFile(image + ".jpg"), + Image = normalImage, FlatStyle = FlatStyle.Flat, Font = SettingForm.mainFont, Name = i.ToString() @@ -112,12 +116,12 @@ namespace PuzzlePlayer_Namespace button.MouseEnter += (object o, EventArgs e) => { - button.Image = Image.FromFile(image + "Gray.jpg"); + button.Image = grayImage; }; button.MouseLeave += (object o, EventArgs e) => { - button.Image = Image.FromFile(image + ".jpg"); + button.Image = normalImage; }; button.MouseClick += (object o, MouseEventArgs e) => diff --git a/PuzzlePlayer/Resources/Sudoku.jpg b/PuzzlePlayer/Resources/Sudoku.jpg new file mode 100644 index 0000000000000000000000000000000000000000..dd2d9fb8b0ab4855462dc6ba69a5f3406cf4ed86 Binary files /dev/null and b/PuzzlePlayer/Resources/Sudoku.jpg differ diff --git a/PuzzlePlayer/Resources/SudokuGray.jpg b/PuzzlePlayer/Resources/SudokuGray.jpg new file mode 100644 index 0000000000000000000000000000000000000000..38db407507fc57a46fc47b1e266c11fd154113e7 Binary files /dev/null and b/PuzzlePlayer/Resources/SudokuGray.jpg differ diff --git a/PuzzlePlayer/SettingForm.cs b/PuzzlePlayer/SettingForm.cs index d1f391b080185db38b180a8a003a7a047be7039c..3f499c4c95040ebcdffc6b2f7f63daf492505b3c 100644 --- a/PuzzlePlayer/SettingForm.cs +++ b/PuzzlePlayer/SettingForm.cs @@ -11,9 +11,10 @@ namespace PuzzlePlayer_Namespace // Public variables for all settings public static Color primaryColor = Color.FromArgb(66, 69, 73); public static Color secondaryColor = Color.FromArgb(54, 57, 62); - public static Color tertiaryColor = Color.FromArgb(66, 69, 73); + public static Color tertiaryColor = Color.FromArgb(0, 0, 0); public static int fontSize = 16; public static Font mainFont = new Font("Gotham", fontSize); + public static FlowLayoutPanel settingsPanel; public SettingForm() { @@ -69,6 +70,7 @@ namespace PuzzlePlayer_Namespace }; themeSelector.Items.Add("Dark"); themeSelector.Items.Add("Light"); + themeSelector.Items.Add("Pink"); themeSelector.SelectedIndexChanged += (object o, EventArgs e) => { @@ -84,6 +86,11 @@ namespace PuzzlePlayer_Namespace SettingForm.secondaryColor = Color.FromArgb(210, 211, 219); SettingForm.tertiaryColor = Color.FromArgb(72, 75, 106); break; + case "Pink": + SettingForm.primaryColor = Color.FromArgb(255, 209, 220); + SettingForm.secondaryColor = Color.FromArgb(252, 178, 197); + SettingForm.tertiaryColor = Color.FromArgb(251, 199, 255); + break; } }; @@ -95,7 +102,7 @@ namespace PuzzlePlayer_Namespace Width = 250, BackColor = SettingForm.secondaryColor, ForeColor = Color.Black, - Margin = new Padding(20) + Margin = new Padding(20), }; sizeSelector.Items.Add("Small"); sizeSelector.Items.Add("Medium"); @@ -116,9 +123,10 @@ namespace PuzzlePlayer_Namespace break; } mainFont = new Font("Gotham", fontSize); + settingsPanel.PerformLayout(); }; - FlowLayoutPanel settingsPanel = new FlowLayoutPanel + settingsPanel = new FlowLayoutPanel { Location = new Point(0, menuStrip.Height), Size = new Size(ClientSize.Width, ClientSize.Height - menuStrip.Height - 100), @@ -126,6 +134,7 @@ namespace PuzzlePlayer_Namespace FlowDirection = FlowDirection.TopDown, WrapContents = true, AutoScroll = true, + Padding = new Padding(20), }; // @@ -189,6 +198,29 @@ namespace PuzzlePlayer_Namespace { UpdateSettings(childControl); } + + if (control is MenuStrip menuStrip) + { + foreach (ToolStripItem item in menuStrip.Items) + { + UpdateToolStripSettings(item); + } + } + } + + public static void UpdateToolStripSettings(ToolStripItem item) + { + item.BackColor = secondaryColor; + item.ForeColor = tertiaryColor; + item.Font = mainFont; + + if (item is ToolStripMenuItem menuItem) + { + foreach (ToolStripItem subItem in menuItem.DropDownItems) + { + UpdateToolStripSettings(subItem); + } + } } } } diff --git a/PuzzlePlayer/Sudoku.cs b/PuzzlePlayer/Sudoku.cs new file mode 100644 index 0000000000000000000000000000000000000000..ecdda24fb3cff8d1d1cc98e146495d2f872980ed --- /dev/null +++ b/PuzzlePlayer/Sudoku.cs @@ -0,0 +1,284 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.DirectoryServices; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using static System.Windows.Forms.VisualStyles.VisualStyleElement.Rebar; + +namespace PuzzlePlayer_Namespace +{ + internal class Sudoku : Binary + { + private static int boardLength; + private static int rootBoardLength; + public Sudoku(int boardSize = 9) + { + boardState = GetClearBoard(boardSize, boardSize); + lastGeneratedBoard = GetClearBoard(boardSize, boardSize); + boardLength = boardSize; + rootBoardLength = (int)Math.Sqrt(boardLength); + + description = "SUDOKU !!!!! !!!!"; + drawFactor = 8; + } + + public override void Draw(Graphics gr, Rectangle r) + { + Size tilesize = new Size(r.Width / boardState.GetLength(0), r.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.LightGray, + r.X + i * tilesize.Width, + r.Y + j * tilesize.Height, + tilesize.Width, + tilesize.Height); + + if (boardState[i,j] != -1) + { + gr.DrawString( + (boardState[i, j]).ToString(), + new Font("Arial", 42), + Brushes.Black, + (float)(r.X + i * tilesize.Width + tilesize.Width / 4), + (float)(r.Y + j * tilesize.Height + tilesize.Height / 4) + ); + } + + if (lastGeneratedBoard[i, j] != Board.emptySpace) + { + gr.FillRectangle(Brushes.LightGray, + (int)(r.X + ((double)i + 0.4375) * tilesize.Width), + (int)(r.Y + ((double)j + 0.4375) * tilesize.Height), + tilesize.Width / 8, + tilesize.Height / 8); + } + } + } + } + + public override void Generate() + { + + boardState = GetClearBoard(boardLength, boardLength); + + for (int i = 0; i < boardLength; i += rootBoardLength) + { + FillBox(i, i); + } + + FillSudoku(0, rootBoardLength); + } + + private int RandomNumber(int number) + { + Random random = new Random(); + return (int)Math.Floor((double)(random.NextDouble() * number + 1)); + } + + private void FillBox(int row, int col) + { + int num; + + for (int i = 0; i < rootBoardLength; i++) + { + for (int j = 0; j < rootBoardLength; j++) + { + do + { + num = RandomNumber(boardLength); + } + while (BoxFlag(row, col, num)); + + boardState[row + i, col + j] = num; + } + } + } + + private bool DoAllChecks(int i, int j, int num) + { + return (BoxFlag(i - i % rootBoardLength, j - j % rootBoardLength, num) || RowFlag(i, num) || ColFlag(j, num)); + } + + private bool BoxFlag(int row, int col, int num) + { + for (int i = 0; i < rootBoardLength; i++) + { + for (int j = 0; j < rootBoardLength; j++) + { + if (boardState[row + i, col + j] == num) + { + return true; + } + } + } + return false; + } + + private bool RowFlag(int i, int num) + { + for (int j = 0; j < boardLength; j++) + { + if (num == boardState[i, j]) + { + return true; + } + } + return false; + } + + private bool ColFlag(int j, int num) + { + for (int i = 0; i < boardLength; i++) + { + if(num == boardState[i, j]) + { + return true; + } + } + return false; + } + + private bool FillSudoku(int row, int col) + { + if (row == boardLength - 1 && col == boardLength) + return true; + + if (col == boardLength) + { + row++; + col = 0; + } + + if (boardState[row, col] != -1) + { + return FillSudoku(row, col + 1); + } + + for (int num = 1; num <= boardLength; num++) + { + if (!DoAllChecks(row, col, num)) + { + boardState[row, col] = num; + + if (FillSudoku(row, col + 1)) + return true; + + boardState[row, col] = -1; + } + } + return false; + } + + private static string BoardToString(int[,] board) + { + string result = ""; + + for (int i = 0; i < board.GetLength(0); i++) + { + for (int j = 0; j < board.GetLength(1); j++) + { + result += (board[i, j] == emptySpace ? "." : board[i, j].ToString()); + } + result += "|"; + } + return result; + } + + private static int[,] BoardFromString(string board) + { + string[] parts = board.Split('|', StringSplitOptions.RemoveEmptyEntries); + int[,] result = new int[parts.Length, parts.Length]; + + for (int i = 0; i < result.GetLength(0); i++) + { + for (int j = 0; j < result.GetLength(1); j++) + { + string s = parts[i][j].ToString(); + if (s == ".") + result[i, j] = emptySpace; + else if (int.Parse(s) >= 0 && int.Parse(s) <= 8) + result[i, j] = int.Parse(s); + else + return null; + } + + } + + return result; + } + + public override void TileInput(Point? p, Keys k) + { + if (p == null) return; + int num = (int)k - 48; + if (num >= 1 && num <= 9) boardState[((Point)p).X, ((Point)p).Y] = num; + + } + public override void TileClick(Point p, int x) + { + if (x == 1) + { + x = -1; + } + if (x == 0) + { + x = 1; + } + + if (boardState[p.X, p.Y] == emptySpace) + { + if (x == 1) + { + boardState[p.X, p.Y] = 1; + return; + } + else + { + boardState[p.X, p.Y] = 9; + return; + } + } + else if (boardState[p.X, p.Y] == 9) + { + if (x == 1) + { + boardState[p.X, p.Y] = emptySpace; + return; + } + else + { + boardState[p.X, p.Y] += x; + return; + } + } + else if (boardState[p.X, p.Y] == 1) + { + if (x == -1) + { + boardState[p.X, p.Y] = emptySpace; + return; + } + else + { + boardState[p.X, p.Y] += x; + return; + } + } + else + { + boardState[p.X, p.Y] += x; + return; + } + } + + } +}