From 077e0e527106a6d6ab27b31dc07cfd980198d757 Mon Sep 17 00:00:00 2001
From: lempamo <smartypantslf@gmail.com>
Date: Sun, 26 Feb 2017 17:31:19 -0500
Subject: [PATCH] working so hard

---
 .../Applications/ShiftSweeper.Designer.cs     |  14 ++
 ShiftOS.WinForms/Applications/ShiftSweeper.cs | 174 ++++++++++++++++--
 ShiftOS.WinForms/Resources/SweeperTile1.png   | Bin 285 -> 273 bytes
 ShiftOS.WinForms/Resources/SweeperTile2.png   | Bin 286 -> 275 bytes
 4 files changed, 174 insertions(+), 14 deletions(-)

diff --git a/ShiftOS.WinForms/Applications/ShiftSweeper.Designer.cs b/ShiftOS.WinForms/Applications/ShiftSweeper.Designer.cs
index f5d7ddd..729bc95 100644
--- a/ShiftOS.WinForms/Applications/ShiftSweeper.Designer.cs
+++ b/ShiftOS.WinForms/Applications/ShiftSweeper.Designer.cs
@@ -34,6 +34,7 @@
             this.buttonM = new System.Windows.Forms.Button();
             this.buttonH = new System.Windows.Forms.Button();
             this.lblmines = new System.Windows.Forms.Label();
+            this.lbltime = new System.Windows.Forms.Label();
             ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
             this.SuspendLayout();
             // 
@@ -92,6 +93,7 @@
             this.buttonM.TabIndex = 3;
             this.buttonM.Text = "Medium";
             this.buttonM.UseVisualStyleBackColor = true;
+            this.buttonM.Click += new System.EventHandler(this.buttonM_Click);
             // 
             // buttonH
             // 
@@ -101,6 +103,7 @@
             this.buttonH.TabIndex = 4;
             this.buttonH.Text = "Hard";
             this.buttonH.UseVisualStyleBackColor = true;
+            this.buttonH.Click += new System.EventHandler(this.buttonH_Click);
             // 
             // lblmines
             // 
@@ -111,10 +114,20 @@
             this.lblmines.TabIndex = 5;
             this.lblmines.Text = "Mines: 0";
             // 
+            // lbltime
+            // 
+            this.lbltime.AutoSize = true;
+            this.lbltime.Location = new System.Drawing.Point(188, 22);
+            this.lbltime.Name = "lbltime";
+            this.lbltime.Size = new System.Drawing.Size(42, 13);
+            this.lbltime.TabIndex = 6;
+            this.lbltime.Text = "Time: 0";
+            // 
             // ShiftSweeper
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.Controls.Add(this.lbltime);
             this.Controls.Add(this.lblmines);
             this.Controls.Add(this.buttonH);
             this.Controls.Add(this.buttonM);
@@ -137,5 +150,6 @@
         private System.Windows.Forms.Button buttonM;
         private System.Windows.Forms.Button buttonH;
         private System.Windows.Forms.Label lblmines;
+        private System.Windows.Forms.Label lbltime;
     }
 }
diff --git a/ShiftOS.WinForms/Applications/ShiftSweeper.cs b/ShiftOS.WinForms/Applications/ShiftSweeper.cs
index 70c69d7..360ef16 100644
--- a/ShiftOS.WinForms/Applications/ShiftSweeper.cs
+++ b/ShiftOS.WinForms/Applications/ShiftSweeper.cs
@@ -19,36 +19,33 @@ namespace ShiftOS.WinForms.Applications
     {
         private bool gameplayed = false;
         private int mineCount = 0;
-        private int[,] minemap;
+        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;
 
-        public ShiftSweeper()
-        {
-            InitializeComponent();
-        }
+        public ShiftSweeper() { InitializeComponent(); }
 
         public void OnLoad()
         {
             buttonE.Visible = true;
             buttonM.Visible = ShiftoriumFrontend.UpgradeInstalled("shiftsweeper_medium");
             buttonH.Visible = ShiftoriumFrontend.UpgradeInstalled("shiftsweeper_hard");
+            ticking.Interval = 1000;
         }
 
         public void OnSkinLoad() { }
 
         public bool OnUnload() { return true; }
 
-        public void OnUpgrade()
-        {
-            
-        }
+        public void OnUpgrade() { }
 
-        private void buttonE_Click(object sender, EventArgs e)
-        {
-            startGame(0);
-        }
+        private void buttonE_Click(object sender, EventArgs e) { startGame(0); }
 
         private void startGame(int d)
         {
+            lbltime.Text = "Time: 0";
+            minetimer = 0;
+            ticking.Start();
             switch (d)
             {
                 case 0:
@@ -57,9 +54,26 @@ namespace ShiftOS.WinForms.Applications
                     minefieldPanel.RowCount = 9;
                     break;
 
+                case 1:
+                    mineCount = 40;
+                    minefieldPanel.ColumnCount = 16;
+                    minefieldPanel.RowCount = 16;
+                    break;
+
+                case 2:
+                    mineCount = 99;
+                    minefieldPanel.ColumnCount = 30;
+                    minefieldPanel.RowCount = 16;
+                    break;
+
                 default:
                     throw new NullReferenceException();
             }
+            lblmines.Text = "Mines: " + mineCount.ToString();
+            buttonE.Enabled = false;
+            buttonM.Enabled = false;
+            buttonH.Enabled = false;
+            gameplayed = true;
             makegrid();
         }
 
@@ -68,6 +82,7 @@ namespace ShiftOS.WinForms.Applications
             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++)
@@ -76,6 +91,43 @@ namespace ShiftOS.WinForms.Applications
                     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;
+                    }
+                }
+            }
         }
 
         private Button makeButton(int col, int row)
@@ -85,15 +137,28 @@ namespace ShiftOS.WinForms.Applications
             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.MouseDown += new MouseEventHandler(mouseDwn);
             bttn.MouseUp += new MouseEventHandler(mauseUp);
             bttn.MouseHover += new EventHandler(mauseHov);
             bttn.BackgroundImage = Properties.Resources.SweeperTileBlock;
+            bttn.MouseClick += new System.Windows.Forms.MouseEventHandler(this.bttnOnRightClick);
 
             return bttn;
         }
 
+        private void bttnOnRightClick(object sender, MouseEventArgs e)
+        {
+            if (!ticking.Enabled) return;
+
+            Button bttnClick = sender as Button;
+
+            if (bttnClick == null) return;
+
+            if (e.Button == MouseButtons.Left | e.Button == MouseButtons.Middle) return;
+        }
+
         private void mauseHov(object sender, EventArgs e)
         {
             pictureBox1.BackgroundImage = Properties.Resources.SweeperNormalFace;
@@ -111,7 +176,88 @@ namespace ShiftOS.WinForms.Applications
 
         private void bttnOnclick(object sender, EventArgs e)
         {
-            
+            if (!ticking.Enabled) return;
+
+            Button bttnClick = sender as Button;
+
+            if (bttnClick == null) return; //not a button.
+
+            string[] split = bttnClick.Name.Split(new Char[] { ' ' });
+
+            int x = System.Convert.ToInt32(split[0]);
+            int y = System.Convert.ToInt32(split[1]);
+
+
+
+            if (minemap[x, y] == -1)
+            {
+                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;
+                        if (minemap[xx, yy] == -1)
+                        {
+                            minefieldPanel.GetControlFromPosition(xx, yy).BackgroundImage = Properties.Resources.SweeperTileBomb;
+                        }
+
+                    }
+                }
+            }
+            else if (minemap[x, y] < -1) return;
+            else removeBlank(x, y);
         }
+
+        private void removeBlank(int x, int y)
+        {
+            if (!minefieldPanel.GetControlFromPosition(x, y).Enabled) return; 
+            else
+            {
+                minefieldPanel.GetControlFromPosition(x, y).Enabled = false;
+                trueform(x, y);
+                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, y).Enabled = false;
+                                if (minemap[x, y] == 0)
+                                {
+                                    removeBlank(x + xx, y + yy);
+                                }
+                            }
+
+                        }
+                    }
+                }
+            }
+        }
+
+        private void trueform(int x, int y)
+        {
+            Button bttn = (Button)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 void buttonM_Click(object sender, EventArgs e) { startGame(1); }
+
+        private void buttonH_Click(object sender, EventArgs e) { startGame(2); }
     }
 }
diff --git a/ShiftOS.WinForms/Resources/SweeperTile1.png b/ShiftOS.WinForms/Resources/SweeperTile1.png
index 06819d0930630268a4906b60adc88f02c8bd8dbd..5fc6871a858ef8d4c84c1929fa5c75f089654ecf 100644
GIT binary patch
delta 188
zcmV;t07L(s0+9lcB#|)~3c>&Y4#EKyC`y2lQz(CqNkl<ZI8U{X0S<s53<LT9r?DV4
zTT@UYHo0`RTckjBGo?1|@WDAS{OaKO@|_Rz3*W*!I+*_H$|&uKbT+)QDDAlu9oVqX
zDt3x=HcU{nE;_Jbf^uC$IvXaaSr;AHFhRMlA)O5q)U1mRY}n_OxTkl(hW&dby`uvg
qzCtAKa`@H3^W{4q{P4nklzIRjTn!%75Vvvw0000<MNUMnLSTZjv{Nzw

delta 198
zcmbQpG?!_D3KwH>kh>GZx^prwCn`#F9cEzQJIr`Ie?`hfH;wvUPZ!4!3;(TsjeHFX
z0#1Mb&o?v4lskMWGbcZ$V7pI%ozE#(^*x3BJms=y^y@2?_Z5iVyLj+}zrS0i`;yHM
zCx5*(&w4Mj^tH&NeiP5NF=k!)%9kUtASQeQ8t3b8-zs-@vo)V*?^s@bpzZR9KE9kC
qEq9cU7F<90=hJlax{8OELHihZtJzf!?AA+T00K`}KbLh*2~7ZnMOUu?

diff --git a/ShiftOS.WinForms/Resources/SweeperTile2.png b/ShiftOS.WinForms/Resources/SweeperTile2.png
index eec00e9d4ea3f0ac3171f5ef3510f2e25eff570e..22c5f0274506591d608f3da62aea0a98a7f619e6 100644
GIT binary patch
delta 190
zcmV;v073tr0+RxeB#|)~3c>&Y4#EKyC`y2lQz(CsNkl<ZI8U{X2@ZfD5Ci%Dr?Da>
zWm7pKHkp*2g=j+ZVN$+xqASmV@@s?j%d@WZf4B?ZvBB$?n$yHR@5pRrb1w0YHn6gs
znUSNH*-DE>oi?ztBgXAzwz3i9_S(S8HfwaJgq@XT*62>*jt#6V=TUesz5`a4d6f8$
s4Xh^IBE0M6*9PmCXI=T>56_YE1*PdT_u&op9smFU07*qoM6N<$f~t&Mr2qf`

delta 199
zcmV;&0671X0-gepBnkm@Qb$4nuFf3kks%uj!vFvd!vV){sAQ2wD1VMgL_t(IPqmJL
z4g(<!LjC`rcFc)E#yl_QNM2}Z8!b>hOsQ|3@Xn`T_|(Dv@|AbyAKry`bnx?~k*R#n
z9qD5@vLxS82Qh5*O5F215W_EAnyZ5tPPo!s`WOyeX|4`pIC_=N6r07c^(*-u9mKHJ
zD{;^7Kn%Cx9Ua8*79@5zhff{sFJF1*4?jFdsV{~wF#7$_SYQAE002ovPDHLkV1g(z
BSmFQx