From 2b3a4f91b2809932c1a938b6ba4633d5606fcecd Mon Sep 17 00:00:00 2001 From: pfg Date: Sun, 5 Mar 2017 15:08:53 -0800 Subject: [PATCH] Minesweeper refactor complete --- .../Applications/ShiftSweeper.Designer.cs | 4 +- ShiftOS.WinForms/Applications/ShiftSweeper.cs | 42 +++++++++++-------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/ShiftOS.WinForms/Applications/ShiftSweeper.Designer.cs b/ShiftOS.WinForms/Applications/ShiftSweeper.Designer.cs index 8090b96..5ba0e0b 100644 --- a/ShiftOS.WinForms/Applications/ShiftSweeper.Designer.cs +++ b/ShiftOS.WinForms/Applications/ShiftSweeper.Designer.cs @@ -155,9 +155,9 @@ namespace ShiftOS.WinForms.Applications this.lblinfo2.AutoSize = true; this.lblinfo2.Location = new System.Drawing.Point(4, 22); this.lblinfo2.Name = "lblinfo2"; - this.lblinfo2.Size = new System.Drawing.Size(233, 13); + this.lblinfo2.Size = new System.Drawing.Size(231, 13); this.lblinfo2.TabIndex = 8; - this.lblinfo2.Text = "Click the button on the right to toggle flag mode."; + this.lblinfo2.Text = "Right click to flag, middle click to question mark"; // // ShiftSweeper // diff --git a/ShiftOS.WinForms/Applications/ShiftSweeper.cs b/ShiftOS.WinForms/Applications/ShiftSweeper.cs index 477bd87..69db034 100644 --- a/ShiftOS.WinForms/Applications/ShiftSweeper.cs +++ b/ShiftOS.WinForms/Applications/ShiftSweeper.cs @@ -146,6 +146,8 @@ namespace ShiftOS.WinForms.Applications { tile.Text = buttonImages[type]; tile.MouseDown += new MouseEventHandler(tile_ClickDown); tile.MouseUp += new MouseEventHandler(tile_Click); + tile.FlatStyle = FlatStyle.Flat; + tile.FlatAppearance.BorderSize = (type == 0) ? 0 : 1; tile.Size = tileSize; @@ -182,17 +184,19 @@ namespace ShiftOS.WinForms.Applications { } private void createGameIfNotExists(int x, int y) { - createGameIfNotExists(); - - /*int i = 0; - while (getBombCountInArea(x,y) != 0) { - i++; - if(i > 1000) { - // alert HUH IT DOESN"T SEEM LIKE THE NUMBERS YOU USED ARE CORRECT ARE YOU SURE THAT"S POSSIBEL - break; - } + if (!gameCreated) { createGameIfNotExists(); - }*/ + int i = 0; + + while (game[x, y] != 0 && i < 1000) { + i++; + createGameIfNotExists(); + } + + if(i > 999) + Infobox.Show("Error", "Failed to generate game"); + return; + } } private void createGameIfNotExists() { @@ -201,6 +205,7 @@ namespace ShiftOS.WinForms.Applications { game[random.Next(0, currentGameWidth), random.Next(0, currentGameHeight)] = 9; } gameCreated = true; + ticking.Start(); } } @@ -278,11 +283,11 @@ namespace ShiftOS.WinForms.Applications { } private void buttonMedium_Click(object sender, EventArgs e) { - startGame(11, 11, 11); + startGame(16, 16, 40); } private void buttonHard_Click(object sender, EventArgs e) { - startGame(12, 12, 12); + startGame(30, 30, 99); } public void winGame() { @@ -304,11 +309,14 @@ namespace ShiftOS.WinForms.Applications { } public void disableAllTiles(bool showBombs) { - for (int yy = 0; yy < gamePanel.ColumnCount; yy++) { - for (int xx = 0; xx < gamePanel.RowCount; xx++) { - gamePanel.GetControlFromPosition(xx, yy).Enabled = false; - if (game[xx, yy] == 9 && showBombs) { - gamePanel.GetControlFromPosition(xx, yy).BackgroundImage = Properties.Resources.SweeperTileBomb; + ticking.Stop(); + minetimer = 0; + for (int y = 0; y < currentGameHeight; y++) { + for (int x = 0; x < currentGameWidth; x++) { + gamePanel.GetControlFromPosition(y, x).Visible = true; + gamePanel.GetControlFromPosition(y,x).Enabled = false; + if (game[x,y] == 9 && showBombs) { + gamePanel.GetControlFromPosition(y,x).BackgroundImage = Properties.Resources.SweeperTileBomb; } }