From 1d8e6dfcd5fe853df47a5403e52239f6c83a43f1 Mon Sep 17 00:00:00 2001 From: pfg Date: Sun, 5 Mar 2017 12:06:21 -0800 Subject: [PATCH] RefactoredSweeper base, next is winning/losing and codepoints --- .../Applications/ShiftSweeper.Designer.cs | 262 +++------- ShiftOS.WinForms/Applications/ShiftSweeper.cs | 468 +++++++----------- 2 files changed, 246 insertions(+), 484 deletions(-) diff --git a/ShiftOS.WinForms/Applications/ShiftSweeper.Designer.cs b/ShiftOS.WinForms/Applications/ShiftSweeper.Designer.cs index 8782260..8090b96 100644 --- a/ShiftOS.WinForms/Applications/ShiftSweeper.Designer.cs +++ b/ShiftOS.WinForms/Applications/ShiftSweeper.Designer.cs @@ -52,90 +52,76 @@ namespace ShiftOS.WinForms.Applications /// private void InitializeComponent() { - this.pictureBox1 = new System.Windows.Forms.PictureBox(); - this.easyPanel = new System.Windows.Forms.TableLayoutPanel(); - this.buttonE = new System.Windows.Forms.Button(); - this.buttonM = new System.Windows.Forms.Button(); - this.buttonH = new System.Windows.Forms.Button(); + this.panelGameStatus = new System.Windows.Forms.PictureBox(); + this.gamePanel = new System.Windows.Forms.TableLayoutPanel(); + this.buttonEasy = new System.Windows.Forms.Button(); + this.buttonMedium = new System.Windows.Forms.Button(); + this.buttonHard = new System.Windows.Forms.Button(); this.lblmines = new System.Windows.Forms.Label(); this.lbltime = new System.Windows.Forms.Label(); this.lblinfo = new System.Windows.Forms.Label(); this.lblinfo2 = new System.Windows.Forms.Label(); - this.flagButton = new System.Windows.Forms.PictureBox(); - this.mediumPanel = new System.Windows.Forms.TableLayoutPanel(); - this.hardPanel = new System.Windows.Forms.TableLayoutPanel(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.flagButton)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.panelGameStatus)).BeginInit(); this.SuspendLayout(); // - // pictureBox1 + // panelGameStatus // - this.pictureBox1.BackgroundImage = global::ShiftOS.WinForms.Properties.Resources.SweeperNormalFace; - this.pictureBox1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None; - this.pictureBox1.Image = global::ShiftOS.WinForms.Properties.Resources.SweeperNormalFace; - this.pictureBox1.Location = new System.Drawing.Point(264, 3); - this.pictureBox1.Name = "pictureBox1"; - this.pictureBox1.Size = new System.Drawing.Size(32, 32); - this.pictureBox1.TabIndex = 0; - this.pictureBox1.TabStop = false; + this.panelGameStatus.BackgroundImage = global::ShiftOS.WinForms.Properties.Resources.SweeperNormalFace; + this.panelGameStatus.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None; + this.panelGameStatus.Image = global::ShiftOS.WinForms.Properties.Resources.SweeperNormalFace; + this.panelGameStatus.Location = new System.Drawing.Point(264, 3); + this.panelGameStatus.Name = "panelGameStatus"; + this.panelGameStatus.Size = new System.Drawing.Size(32, 32); + this.panelGameStatus.TabIndex = 0; + this.panelGameStatus.TabStop = false; + this.panelGameStatus.Click += new System.EventHandler(this.panelGameStatus_Click); // - // easyPanel + // gamePanel // - this.easyPanel.ColumnCount = 9; - this.easyPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 11.11111F)); - this.easyPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 11.11111F)); - this.easyPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 11.11111F)); - this.easyPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 11.11111F)); - this.easyPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 11.11111F)); - this.easyPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 11.11111F)); - this.easyPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 11.11111F)); - this.easyPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 11.11111F)); - this.easyPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 11.11111F)); - this.easyPanel.GrowStyle = System.Windows.Forms.TableLayoutPanelGrowStyle.FixedSize; - this.easyPanel.Location = new System.Drawing.Point(4, 40); - this.easyPanel.Name = "easyPanel"; - this.easyPanel.RowCount = 9; - this.easyPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 11.11136F)); - this.easyPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 11.11136F)); - this.easyPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 11.11136F)); - this.easyPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 11.11136F)); - this.easyPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 11.11136F)); - this.easyPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 11.11136F)); - this.easyPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 11.11136F)); - this.easyPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 11.11025F)); - this.easyPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 11.11025F)); - this.easyPanel.Size = new System.Drawing.Size(553, 308); - this.easyPanel.TabIndex = 1; + this.gamePanel.AutoScroll = true; + this.gamePanel.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.gamePanel.ColumnCount = 1; + this.gamePanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.gamePanel.GrowStyle = System.Windows.Forms.TableLayoutPanelGrowStyle.FixedSize; + this.gamePanel.Location = new System.Drawing.Point(4, 40); + this.gamePanel.MaximumSize = new System.Drawing.Size(553, 308); + this.gamePanel.MinimumSize = new System.Drawing.Size(553, 308); + this.gamePanel.Name = "gamePanel"; + this.gamePanel.RowCount = 1; + this.gamePanel.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.gamePanel.Size = new System.Drawing.Size(553, 308); + this.gamePanel.TabIndex = 1; + this.gamePanel.Paint += new System.Windows.Forms.PaintEventHandler(this.gamePanel_Paint); // - // buttonE + // buttonEasy // - this.buttonE.Location = new System.Drawing.Point(4, 354); - this.buttonE.Name = "buttonE"; - this.buttonE.Size = new System.Drawing.Size(75, 23); - this.buttonE.TabIndex = 2; - this.buttonE.Text = "Easy"; - this.buttonE.UseVisualStyleBackColor = true; - this.buttonE.Click += new System.EventHandler(this.buttonE_Click); + this.buttonEasy.Location = new System.Drawing.Point(4, 354); + this.buttonEasy.Name = "buttonEasy"; + this.buttonEasy.Size = new System.Drawing.Size(75, 23); + this.buttonEasy.TabIndex = 2; + this.buttonEasy.Text = "Easy"; + this.buttonEasy.UseVisualStyleBackColor = true; + this.buttonEasy.Click += new System.EventHandler(this.buttonEasy_Click); // - // buttonM + // buttonMedium // - this.buttonM.Location = new System.Drawing.Point(244, 354); - this.buttonM.Name = "buttonM"; - this.buttonM.Size = new System.Drawing.Size(75, 23); - this.buttonM.TabIndex = 3; - this.buttonM.Text = "Medium"; - this.buttonM.UseVisualStyleBackColor = true; - this.buttonM.Click += new System.EventHandler(this.buttonM_Click); + this.buttonMedium.Location = new System.Drawing.Point(244, 354); + this.buttonMedium.Name = "buttonMedium"; + this.buttonMedium.Size = new System.Drawing.Size(75, 23); + this.buttonMedium.TabIndex = 3; + this.buttonMedium.Text = "Medium"; + this.buttonMedium.UseVisualStyleBackColor = true; + this.buttonMedium.Click += new System.EventHandler(this.buttonMedium_Click); // - // buttonH + // buttonHard // - this.buttonH.Location = new System.Drawing.Point(482, 354); - this.buttonH.Name = "buttonH"; - this.buttonH.Size = new System.Drawing.Size(75, 23); - this.buttonH.TabIndex = 4; - this.buttonH.Text = "Hard"; - this.buttonH.UseVisualStyleBackColor = true; - this.buttonH.Click += new System.EventHandler(this.buttonH_Click); + this.buttonHard.Location = new System.Drawing.Point(482, 354); + this.buttonHard.Name = "buttonHard"; + this.buttonHard.Size = new System.Drawing.Size(75, 23); + this.buttonHard.TabIndex = 4; + this.buttonHard.Text = "Hard"; + this.buttonHard.UseVisualStyleBackColor = true; + this.buttonHard.Click += new System.EventHandler(this.buttonHard_Click); // // lblmines // @@ -173,135 +159,22 @@ namespace ShiftOS.WinForms.Applications this.lblinfo2.TabIndex = 8; this.lblinfo2.Text = "Click the button on the right to toggle flag mode."; // - // flagButton - // - this.flagButton.Image = global::ShiftOS.WinForms.Properties.Resources.SweeperTileBlock; - this.flagButton.Location = new System.Drawing.Point(537, 14); - this.flagButton.Name = "flagButton"; - this.flagButton.Size = new System.Drawing.Size(20, 20); - this.flagButton.TabIndex = 9; - this.flagButton.TabStop = false; - this.flagButton.Click += new System.EventHandler(this.flagButton_Click); - // - // mediumPanel - // - this.mediumPanel.ColumnCount = 16; - this.mediumPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 6.249042F)); - this.mediumPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 6.249044F)); - this.mediumPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 6.249044F)); - this.mediumPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 6.249044F)); - this.mediumPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 6.249044F)); - this.mediumPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 6.249044F)); - this.mediumPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 6.249044F)); - this.mediumPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 6.249044F)); - this.mediumPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 6.249044F)); - this.mediumPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 6.251231F)); - this.mediumPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 6.251231F)); - this.mediumPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 6.251231F)); - this.mediumPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 6.251231F)); - this.mediumPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 6.251231F)); - this.mediumPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 6.251231F)); - this.mediumPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 6.251231F)); - this.mediumPanel.GrowStyle = System.Windows.Forms.TableLayoutPanelGrowStyle.FixedSize; - this.mediumPanel.Location = new System.Drawing.Point(4, 41); - this.mediumPanel.Name = "mediumPanel"; - this.mediumPanel.RowCount = 16; - this.mediumPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 6.249183F)); - this.mediumPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 6.249182F)); - this.mediumPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 6.249182F)); - this.mediumPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 6.249182F)); - this.mediumPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 6.249182F)); - this.mediumPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 6.249182F)); - this.mediumPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 6.249182F)); - this.mediumPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 6.248558F)); - this.mediumPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 6.248558F)); - this.mediumPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 6.251231F)); - this.mediumPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 6.251231F)); - this.mediumPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 6.251231F)); - this.mediumPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 6.251231F)); - this.mediumPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 6.251231F)); - this.mediumPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 6.251231F)); - this.mediumPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 6.251231F)); - this.mediumPanel.Size = new System.Drawing.Size(553, 307); - this.mediumPanel.TabIndex = 2; - // - // hardPanel - // - this.hardPanel.ColumnCount = 30; - this.hardPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 3.448275F)); - this.hardPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 3.448275F)); - this.hardPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 3.448275F)); - this.hardPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 3.448275F)); - this.hardPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 3.448275F)); - this.hardPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 3.448275F)); - this.hardPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 3.448275F)); - this.hardPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 3.448275F)); - this.hardPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 3.448275F)); - this.hardPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 3.448275F)); - this.hardPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 3.448275F)); - this.hardPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 3.448275F)); - this.hardPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 3.448275F)); - this.hardPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 3.448275F)); - this.hardPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 3.448275F)); - this.hardPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 3.448275F)); - this.hardPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 3.448275F)); - this.hardPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 3.448275F)); - this.hardPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 3.448275F)); - this.hardPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 3.448275F)); - this.hardPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 3.448275F)); - this.hardPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 3.448275F)); - this.hardPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 3.448275F)); - this.hardPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 3.448275F)); - this.hardPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 3.448275F)); - this.hardPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 3.448275F)); - this.hardPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 3.448275F)); - this.hardPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 3.448275F)); - this.hardPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 3.448275F)); - this.hardPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); - this.hardPanel.GrowStyle = System.Windows.Forms.TableLayoutPanelGrowStyle.FixedSize; - this.hardPanel.Location = new System.Drawing.Point(4, 40); - this.hardPanel.Name = "hardPanel"; - this.hardPanel.RowCount = 16; - this.hardPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 6.249183F)); - this.hardPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 6.249182F)); - this.hardPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 6.249182F)); - this.hardPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 6.249182F)); - this.hardPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 6.249182F)); - this.hardPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 6.249182F)); - this.hardPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 6.249182F)); - this.hardPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 6.248558F)); - this.hardPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 6.248558F)); - this.hardPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 6.251231F)); - this.hardPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 6.251231F)); - this.hardPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 6.251231F)); - this.hardPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 6.251231F)); - this.hardPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 6.251231F)); - this.hardPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 6.251231F)); - this.hardPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 6.251231F)); - this.hardPanel.Size = new System.Drawing.Size(553, 308); - this.hardPanel.TabIndex = 3; - // // ShiftSweeper // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.hardPanel); - this.Controls.Add(this.mediumPanel); - this.Controls.Add(this.flagButton); this.Controls.Add(this.lblinfo2); this.Controls.Add(this.lblinfo); this.Controls.Add(this.lbltime); this.Controls.Add(this.lblmines); - this.Controls.Add(this.buttonH); - this.Controls.Add(this.buttonM); - this.Controls.Add(this.buttonE); - this.Controls.Add(this.easyPanel); - this.Controls.Add(this.pictureBox1); + this.Controls.Add(this.buttonHard); + this.Controls.Add(this.buttonMedium); + this.Controls.Add(this.buttonEasy); + this.Controls.Add(this.gamePanel); + this.Controls.Add(this.panelGameStatus); this.Name = "ShiftSweeper"; this.Size = new System.Drawing.Size(596, 426); - this.Load += new System.EventHandler(this.ShiftSweeper_Load); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.flagButton)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.panelGameStatus)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -309,17 +182,14 @@ namespace ShiftOS.WinForms.Applications #endregion - private System.Windows.Forms.PictureBox pictureBox1; - private System.Windows.Forms.TableLayoutPanel easyPanel; - private System.Windows.Forms.Button buttonE; - private System.Windows.Forms.Button buttonM; - private System.Windows.Forms.Button buttonH; + private System.Windows.Forms.PictureBox panelGameStatus; + private System.Windows.Forms.TableLayoutPanel gamePanel; + private System.Windows.Forms.Button buttonEasy; + private System.Windows.Forms.Button buttonMedium; + private System.Windows.Forms.Button buttonHard; private System.Windows.Forms.Label lblmines; private System.Windows.Forms.Label lbltime; private System.Windows.Forms.Label lblinfo; private System.Windows.Forms.Label lblinfo2; - private System.Windows.Forms.PictureBox flagButton; - private System.Windows.Forms.TableLayoutPanel mediumPanel; - private System.Windows.Forms.TableLayoutPanel hardPanel; } } diff --git a/ShiftOS.WinForms/Applications/ShiftSweeper.cs b/ShiftOS.WinForms/Applications/ShiftSweeper.cs index d8de58e..a39bf41 100644 --- a/ShiftOS.WinForms/Applications/ShiftSweeper.cs +++ b/ShiftOS.WinForms/Applications/ShiftSweeper.cs @@ -33,341 +33,233 @@ using System.Threading.Tasks; using System.Windows.Forms; using ShiftOS.Engine; -namespace ShiftOS.WinForms.Applications -{ +namespace ShiftOS.WinForms.Applications { [Launcher("ShiftSweeper", true, "al_shiftsweeper", "Games")] [RequiresUpgrade("shiftsweeper")] [WinOpen("shiftsweeper")] [DefaultIcon("iconShiftSweeper")] - public partial class ShiftSweeper : UserControl, IShiftOSWindow - { - private bool flagtime = false; - private int mineCount = 0; - private int origminecount; - private int[,] minemap; //Represents status of tiles. 0-8 = how many mines surrounding. -1 = mine. -2 = flagged mine. -3 to -11 = flagged safe. - private Timer ticking = new Timer(); - private int minetimer; - private TableLayoutPanel minefieldPanel; + public partial class ShiftSweeper : UserControl, IShiftOSWindow { + int[,] game; + int[,] currentGame; + bool gameCreated = false; + int gameBombCount; + int currentGameWidth; + int currentGameHeight; - public ShiftSweeper() { InitializeComponent(); } + private static readonly Random random = new Random(); - public void OnLoad() - { - buttonE.Visible = true; - buttonM.Visible = ShiftoriumFrontend.UpgradeInstalled("shiftsweeper_medium"); - buttonH.Visible = ShiftoriumFrontend.UpgradeInstalled("shiftsweeper_hard"); - ticking.Interval = 1000; - ticking.Tick += Ticking_Tick; - easyPanel.Visible = false; - mediumPanel.Visible = false; - hardPanel.Visible = false; + Size tileSize; + + Dictionary buttonImages = new Dictionary(){ + {-3, "?" }, + {-2, ">" }, + {-1, "#" }, + {0, " " }, + {1, "1" }, + {2, "2" }, + {3, "3" }, + {4, "4" }, + {5, "5" }, + {6, "6" }, + {7, "7" }, + {8, "8" }, + {9, "9" } + }; + + const int QUESTIONED = -3; + const int FLAGGED = -2; + const int UNDISCOVERED = -1; + const int REMOVE = -10; + + public ShiftSweeper() { + InitializeComponent(); } - private void Ticking_Tick(object sender, EventArgs e) - { - minetimer++; - lbltime.Text = "Time: " + minetimer.ToString(); + public void OnLoad() { + buttonEasy.Visible = true; + buttonMedium.Visible = ShiftoriumFrontend.UpgradeInstalled("shiftsweeper_medium"); + buttonHard.Visible = ShiftoriumFrontend.UpgradeInstalled("shiftsweeper_hard"); } - public void OnSkinLoad() { } + public void OnSkinLoad() { + } - public bool OnUnload() { return true; } + public bool OnUnload() { + return true; + } - public void OnUpgrade() { } + public void OnUpgrade() { - private void buttonE_Click(object sender, EventArgs e) { startGame(0); } + } - private void clearPreviousGame() - { - if (minemap != null) for (int x = 0; x < minefieldPanel.ColumnCount; x++) - { - for (int y = 0; y < minefieldPanel.RowCount; y++) - { - minemap[x, y] = 0; - - if (minefieldPanel.GetControlFromPosition(x,y) != null) - { - minefieldPanel.Controls.Remove(minefieldPanel.GetControlFromPosition(x, y)); + public void startGame(int w, int h, int b) { + if (gamePanel.RowCount > w || gamePanel.ColumnCount > h) { + for (int y = 0; y < gamePanel.ColumnCount; y++) { + for (int x = 0; x < gamePanel.RowCount; x++) { + updateTile(x, y, REMOVE); } } } - } + gamePanel.RowCount = w; + gamePanel.ColumnCount = h; - private void startGame(int d) - { - pictureBox1.Image = Properties.Resources.SweeperNormalFace; - clearPreviousGame(); - lbltime.Text = "Time: 0"; - minetimer = 0; - ticking.Start(); - if (minefieldPanel != null) minefieldPanel.Visible = false; - switch (d) - { - case 0: - minefieldPanel = easyPanel; - mineCount = 10; - minefieldPanel.ColumnCount = 9; - minefieldPanel.RowCount = 9; - break; + game = new int[w, h]; + currentGame = new int[w, h]; - case 1: - minefieldPanel = mediumPanel; - mineCount = 40; - minefieldPanel.ColumnCount = 16; - minefieldPanel.RowCount = 16; - break; + tileSize = new Size(23, 23); - case 2: - minefieldPanel = hardPanel; - mineCount = 99; - minefieldPanel.ColumnCount = 30; - minefieldPanel.RowCount = 16; - break; + gameCreated = false; - default: - throw new NullReferenceException(); - } - minefieldPanel.Visible = true; - origminecount = mineCount; - lblmines.Text = "Mines: " + mineCount.ToString(); - buttonE.Enabled = false; - buttonM.Enabled = false; - buttonH.Enabled = false; - makegrid(); - } + currentGameWidth = w; + currentGameHeight = h; + gameBombCount = b; - private void makegrid() - { - Random rnd1 = new Random(); - minemap = new int[minefieldPanel.ColumnCount, minefieldPanel.RowCount]; - - // Makes the minefield full of buttons - for (int x = 0; x < minefieldPanel.ColumnCount; x++) - { - for (int y = 0; y < minefieldPanel.RowCount; y++) - { - minemap[x, y] = 0; - minefieldPanel.Controls.Add(makeButton(x, y), x, y); - } - } - - // Placing the mines - int currminecount = mineCount; - while (currminecount > 0) - { - int mineX = rnd1.Next(minefieldPanel.ColumnCount); - int mineY = rnd1.Next(minefieldPanel.RowCount); - - if (minemap[mineX, mineY] == 0) - { - minemap[mineX, mineY] = -1; - currminecount--; - } - } - - // Setting the numbers - for (int x = 0; x < minefieldPanel.ColumnCount; x++) - { - for (int y = 0; y < minefieldPanel.RowCount; y++) - { - if (minemap[x, y] != -1) - { - int numMines = 0; - for (int xx = -1; xx < 2; xx++) - { - for (int yy = -1; yy < 2; yy++) - { - if (x + xx >= 0 && y + yy >= 0 && x + xx < minefieldPanel.ColumnCount && y + yy < minefieldPanel.RowCount) - { - if (minemap[x + xx, y + yy] == -1) numMines++; - } - } - } - minemap[x, y] = numMines; - } + for (int y = 0; y < h; y++) { + for (int x = 0; x < w; x++) { + updateTile(x, y, UNDISCOVERED); } } } - private PictureBox makeButton(int col, int row) - { - PictureBox bttn = new PictureBox(); + public void updateTile(int x, int y, int type) { + Button tile = new Button(); - bttn.Text = ""; - bttn.Name = col.ToString() + " " + row.ToString(); - Controls.AddRange(new System.Windows.Forms.Control[] { bttn, }); - bttn.Size = new System.Drawing.Size(minefieldPanel.Width / minefieldPanel.ColumnCount, minefieldPanel.Height / minefieldPanel.RowCount); - bttn.Click += new System.EventHandler(bttnOnclick); - bttn.BackgroundImage = Properties.Resources.SweeperTileBlock; - bttn.BackgroundImageLayout = ImageLayout.Stretch; + if (type == REMOVE) { + } else { + tile.Text = buttonImages[type]; + tile.MouseUp += new MouseEventHandler(tile_Click); - return bttn; + tile.Size = tileSize; + + currentGame[x, y] = type; + } + + var controlToRemove = gamePanel.GetControlFromPosition(y, x); + + if (controlToRemove != null) + gamePanel.Controls.Remove(controlToRemove); + + if (type != REMOVE) + gamePanel.Controls.Add(tile, y, x); } - private void bttnOnclick(object sender, EventArgs ee) - { + private void tile_Click(object sender, EventArgs ee) { MouseEventArgs e = (MouseEventArgs)ee; - if (!ticking.Enabled) return; + Control sen = (Control)sender; + TableLayoutPanelCellPosition tilePos = gamePanel.GetPositionFromControl(sen); - PictureBox bttnClick = sender as PictureBox; - - if (bttnClick == null) return; - - string[] split = bttnClick.Name.Split(new Char[] { ' ' }); - - int x = System.Convert.ToInt32(split[0]); - int y = System.Convert.ToInt32(split[1]); - - - - if (!flagtime && e.Button == MouseButtons.Left) - { - if (minemap[x, y] == -1) - { - ticking.Enabled = false; - - buttonE.Enabled = true; - buttonM.Enabled = true; - buttonH.Enabled = true; - - pictureBox1.BackgroundImage = Properties.Resources.SweeperLoseFace; - - for (int xx = 0; xx < minefieldPanel.ColumnCount; xx++) - { - for (int yy = 0; yy < minefieldPanel.RowCount; yy++) - { - pictureBox1.BackgroundImage = Properties.Resources.SweeperLoseFace; - minefieldPanel.GetControlFromPosition(xx, yy).Enabled = false; - if (minemap[xx, yy] == -1) - { - minefieldPanel.GetControlFromPosition(xx, yy).BackgroundImage = Properties.Resources.SweeperTileBomb; - } - - } - } - pictureBox1.Image = Properties.Resources.SweeperLoseFace; - } - else if (minemap[x, y] < -1) return; - else removeBlank(x, y); - } - else if(flagtime || e.Button == MouseButtons.Right) - { - if (!bttnClick.Enabled) return; - - if (minemap[x, y] < -1) - { - minemap[x, y] = (minemap[x, y] * -1) - 3; - bttnClick.BackgroundImage = Properties.Resources.SweeperTileBlock; - mineCount++; - } - else - { - minemap[x, y] = (minemap[x, y] * -1) - 3; - bttnClick.BackgroundImage = Properties.Resources.SweeperTileFlag; - mineCount--; - } - lblmines.Text = "Mines: " + mineCount.ToString(); - bool wrongflags = false; - if (mineCount == 0) - { - for (int xx = 0; xx < minefieldPanel.ColumnCount; xx++) - { - if (wrongflags) break; - for (int yy = 0; yy < minefieldPanel.RowCount; yy++) - { - if (wrongflags) break; - if (minemap[xx, yy] < -2) wrongflags = true; - } - } - if (!wrongflags) - { - ticking.Enabled = false; - - buttonE.Enabled = true; - buttonM.Enabled = true; - buttonH.Enabled = true; - - for (int xx = 0; xx < minefieldPanel.ColumnCount; xx++) - { - for (int yy = 0; yy < minefieldPanel.RowCount; yy++) - { - minefieldPanel.GetControlFromPosition(xx, yy).Enabled = false; - } - } - - Int32 cp = 0; - origminecount = origminecount * 10; - if (minetimer < 31) cp = (origminecount * 3); - else if (minetimer < 61) cp = (Int32)(origminecount * 2.5); - else if (minetimer < 91) cp = (origminecount * 2); - else if (minetimer < 121) cp = (Int32)(origminecount * 1.5); - else if (minetimer > 120) cp = (origminecount * 1); - SaveSystem.TransferCodepointsFrom("shiftsweeper", cp); - pictureBox1.Image = Properties.Resources.SweeperWinFace; - } - } + if (e.Button == MouseButtons.Left) { + revealTile(tilePos.Row, tilePos.Column); + } else if (e.Button == MouseButtons.Right) { + toggleTileFlag(tilePos.Row, tilePos.Column); + } else if (e.Button == MouseButtons.Middle) { + toggleTileQuestionMark(tilePos.Row, tilePos.Column); } } - private void removeBlank(int x, int y) - { - minefieldPanel.GetControlFromPosition(x, y).Enabled = false; - trueform(x, y); - if (minemap[x, y] != 0) return; - for (int xx = -1; xx < 2; xx++) - { - for (int yy = -1; yy < 2; yy++) - { - if (x + xx >= 0 && y + yy >= 0 && x + xx < minefieldPanel.ColumnCount && y + yy < minefieldPanel.RowCount) - { - if (minefieldPanel.GetControlFromPosition(x + xx, y + yy).Enabled && minemap[x+xx,y+yy] != -1 && minemap[x + xx, y + yy] != -2) - { - minefieldPanel.GetControlFromPosition(x + xx, y + yy).Enabled = false; - trueform(x + xx, y + yy); - if (minemap[x + xx, y + yy] == 0) - { - removeBlank(x + xx, y + yy); - } - } - } + 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; } + createGameIfNotExists(); + }*/ + } + + private void createGameIfNotExists() { + if (!gameCreated) { + for (int b = 0; b < gameBombCount; b++) { // place bombs + game[random.Next(0, currentGameWidth), random.Next(0, currentGameHeight)] = 9; + } + gameCreated = true; } } - private void trueform(int x, int y) - { - PictureBox bttn = (PictureBox)minefieldPanel.GetControlFromPosition(x, y); - if (minemap[x,y] == 0) bttn.BackgroundImage = Properties.Resources.SweeperTile0; - else if (minemap[x, y] == 1) bttn.BackgroundImage = Properties.Resources.SweeperTile1; - else if (minemap[x, y] == 2) bttn.BackgroundImage = Properties.Resources.SweeperTile2; - else if (minemap[x, y] == 3) bttn.BackgroundImage = Properties.Resources.SweeperTile3; - else if (minemap[x, y] == 4) bttn.BackgroundImage = Properties.Resources.SweeperTile4; - else if (minemap[x, y] == 5) bttn.BackgroundImage = Properties.Resources.SweeperTile5; - else if (minemap[x, y] == 6) bttn.BackgroundImage = Properties.Resources.SweeperTile6; - else if (minemap[x, y] == 7) bttn.BackgroundImage = Properties.Resources.SweeperTile7; - else if (minemap[x, y] == 8) bttn.BackgroundImage = Properties.Resources.SweeperTile8; + private int getBombCountInArea(int x, int y) { + createGameIfNotExists(x, y); + + if (game[x, y] == 9) return 9; + + int count = 0; + int w = currentGameWidth - 1; + int h = currentGameHeight - 1; + + if (x > 0) count += game[x - 1, y] == 9 ? 1 : 0; + if (y > 0) count += game[x, y - 1] == 9 ? 1 : 0; + if (x < w) count += game[x + 1, y] == 9 ? 1 : 0; + if (y < h) count += game[x, y + 1] == 9 ? 1 : 0; + + if (x > 0 && y > 0) count += game[x - 1, y - 1] == 9 ? 1 : 0; + if (x < w && y < h) count += game[x + 1, y + 1] == 9 ? 1 : 0; + if (x < w && y > 0) count += game[x + 1, y - 1] == 9 ? 1 : 0; + if (x > 0 && y < h) count += game[x - 1, y + 1] == 9 ? 1 : 0; + + return count; } - private void buttonM_Click(object sender, EventArgs e) { startGame(1); } + private void revealTile(int x, int y) { + createGameIfNotExists(x, y); - private void buttonH_Click(object sender, EventArgs e) { startGame(2); } + int bombs = getBombCountInArea(x, y); + int previousBombs = currentGame[x, y]; - private void flagButton_Click(object sender, EventArgs e) - { - if (flagtime) - { - flagButton.Image = Properties.Resources.SweeperTileBlock; - flagtime = false; - } - else - { - flagButton.Image = Properties.Resources.SweeperTileFlag; - flagtime = true; + updateTile(x, y, bombs); + + if (bombs == 0 && previousBombs == UNDISCOVERED) { + int w = currentGameWidth - 1; + int h = currentGameHeight - 1; + + if (x > 0) revealTile(x - 1, y); + if (y > 0) revealTile(x, y - 1); + if (x < w) revealTile(x + 1, y); + if (y < h) revealTile(x, y + 1); + + if (x > 0 && y > 0) revealTile(x - 1, y - 1); + if (x < w && y < h) revealTile(x + 1, y + 1); + if (x < w && y > 0) revealTile(x + 1, y - 1); + if (x > 0 && y < h) revealTile(x - 1, y + 1); } } - private void ShiftSweeper_Load(object sender, EventArgs e) { + private void toggleTileFlag(int x, int y) { + if(currentGame[x,y] == UNDISCOVERED) { + updateTile(x, y, FLAGGED); + } else if(currentGame[x, y] == FLAGGED) { + updateTile(x, y, UNDISCOVERED); + } + } + + private void toggleTileQuestionMark(int x, int y) { + if (currentGame[x, y] == UNDISCOVERED) { + updateTile(x, y, QUESTIONED); + } else if (currentGame[x, y] == QUESTIONED) { + updateTile(x, y, UNDISCOVERED); + } + } + + private void buttonEasy_Click(object sender, EventArgs e) { + startGame(10, 10, 10); + } + + private void buttonMedium_Click(object sender, EventArgs e) { + startGame(11, 11, 11); + } + + private void buttonHard_Click(object sender, EventArgs e) { + startGame(12, 12, 12); + } + + private void panelGameStatus_Click(object sender, EventArgs e) { + + } + + private void gamePanel_Paint(object sender, PaintEventArgs e) { } }