From c37f4a7874416ff68e2e75f50f1c6802c9e3bb20 Mon Sep 17 00:00:00 2001 From: lempamo Date: Sun, 26 Feb 2017 20:36:01 -0500 Subject: [PATCH] almost there --- .../Applications/ShiftSweeper.Designer.cs | 40 ++- ShiftOS.WinForms/Applications/ShiftSweeper.cs | 235 +++++++++--------- ShiftOS.WinForms/ShiftOS.WinForms.csproj | 12 + 3 files changed, 154 insertions(+), 133 deletions(-) diff --git a/ShiftOS.WinForms/Applications/ShiftSweeper.Designer.cs b/ShiftOS.WinForms/Applications/ShiftSweeper.Designer.cs index b5cc13f..691bdb4 100644 --- a/ShiftOS.WinForms/Applications/ShiftSweeper.Designer.cs +++ b/ShiftOS.WinForms/Applications/ShiftSweeper.Designer.cs @@ -37,14 +37,17 @@ 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(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.flagButton)).BeginInit(); this.SuspendLayout(); // // pictureBox1 // this.pictureBox1.BackgroundImage = global::ShiftOS.WinForms.Properties.Resources.SweeperNormalFace; this.pictureBox1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None; - this.pictureBox1.Location = new System.Drawing.Point(150, 3); + this.pictureBox1.Image = global::ShiftOS.WinForms.Properties.Resources.SweeperNormalFace; + this.pictureBox1.Location = new System.Drawing.Point(222, 3); this.pictureBox1.Name = "pictureBox1"; this.pictureBox1.Size = new System.Drawing.Size(32, 32); this.pictureBox1.TabIndex = 0; @@ -74,12 +77,12 @@ this.minefieldPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 11.11111F)); this.minefieldPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 11.11111F)); this.minefieldPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 11.11111F)); - this.minefieldPanel.Size = new System.Drawing.Size(329, 215); + this.minefieldPanel.Size = new System.Drawing.Size(471, 241); this.minefieldPanel.TabIndex = 1; // // buttonE // - this.buttonE.Location = new System.Drawing.Point(4, 261); + this.buttonE.Location = new System.Drawing.Point(4, 287); this.buttonE.Name = "buttonE"; this.buttonE.Size = new System.Drawing.Size(75, 23); this.buttonE.TabIndex = 2; @@ -89,7 +92,7 @@ // // buttonM // - this.buttonM.Location = new System.Drawing.Point(129, 261); + this.buttonM.Location = new System.Drawing.Point(201, 287); this.buttonM.Name = "buttonM"; this.buttonM.Size = new System.Drawing.Size(75, 23); this.buttonM.TabIndex = 3; @@ -99,7 +102,7 @@ // // buttonH // - this.buttonH.Location = new System.Drawing.Point(258, 261); + this.buttonH.Location = new System.Drawing.Point(400, 287); this.buttonH.Name = "buttonH"; this.buttonH.Size = new System.Drawing.Size(75, 23); this.buttonH.TabIndex = 4; @@ -110,7 +113,7 @@ // lblmines // this.lblmines.AutoSize = true; - this.lblmines.Location = new System.Drawing.Point(188, 3); + this.lblmines.Location = new System.Drawing.Point(272, 4); this.lblmines.Name = "lblmines"; this.lblmines.Size = new System.Drawing.Size(47, 13); this.lblmines.TabIndex = 5; @@ -119,7 +122,7 @@ // lbltime // this.lbltime.AutoSize = true; - this.lbltime.Location = new System.Drawing.Point(188, 22); + this.lbltime.Location = new System.Drawing.Point(272, 22); this.lbltime.Name = "lbltime"; this.lbltime.Size = new System.Drawing.Size(42, 13); this.lbltime.TabIndex = 6; @@ -130,23 +133,34 @@ this.lblinfo.AutoSize = true; this.lblinfo.Location = new System.Drawing.Point(4, 4); this.lblinfo.Name = "lblinfo"; - this.lblinfo.Size = new System.Drawing.Size(129, 13); + this.lblinfo.Size = new System.Drawing.Size(108, 13); this.lblinfo.TabIndex = 7; - this.lblinfo.Text = "Left Click to uncover tiles."; + this.lblinfo.Text = "Click to uncover tiles."; // // lblinfo2 // this.lblinfo2.AutoSize = true; this.lblinfo2.Location = new System.Drawing.Point(4, 22); this.lblinfo2.Name = "lblinfo2"; - this.lblinfo2.Size = new System.Drawing.Size(114, 13); + this.lblinfo2.Size = new System.Drawing.Size(128, 13); this.lblinfo2.TabIndex = 8; - this.lblinfo2.Text = "Right Click to flag tiles."; + this.lblinfo2.Text = "Right Button: Toggle Flag"; + // + // flagButton + // + this.flagButton.Image = global::ShiftOS.WinForms.Properties.Resources.SweeperTileBlock; + this.flagButton.Location = new System.Drawing.Point(455, 15); + 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); // // ShiftSweeper // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.flagButton); this.Controls.Add(this.lblinfo2); this.Controls.Add(this.lblinfo); this.Controls.Add(this.lbltime); @@ -157,8 +171,9 @@ this.Controls.Add(this.minefieldPanel); this.Controls.Add(this.pictureBox1); this.Name = "ShiftSweeper"; - this.Size = new System.Drawing.Size(366, 328); + this.Size = new System.Drawing.Size(536, 358); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.flagButton)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -175,5 +190,6 @@ private System.Windows.Forms.Label lbltime; private System.Windows.Forms.Label lblinfo; private System.Windows.Forms.Label lblinfo2; + private System.Windows.Forms.PictureBox flagButton; } } diff --git a/ShiftOS.WinForms/Applications/ShiftSweeper.cs b/ShiftOS.WinForms/Applications/ShiftSweeper.cs index 0f9c700..4b83b3f 100644 --- a/ShiftOS.WinForms/Applications/ShiftSweeper.cs +++ b/ShiftOS.WinForms/Applications/ShiftSweeper.cs @@ -18,6 +18,7 @@ namespace ShiftOS.WinForms.Applications public partial class ShiftSweeper : UserControl, IShiftOSWindow { private bool gameplayed = false; + 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. @@ -32,6 +33,13 @@ namespace ShiftOS.WinForms.Applications buttonM.Visible = ShiftoriumFrontend.UpgradeInstalled("shiftsweeper_medium"); buttonH.Visible = ShiftoriumFrontend.UpgradeInstalled("shiftsweeper_hard"); ticking.Interval = 1000; + ticking.Tick += Ticking_Tick; + } + + private void Ticking_Tick(object sender, EventArgs e) + { + minetimer++; + lbltime.Text = "Time: " + minetimer.ToString(); } public void OnSkinLoad() { } @@ -61,6 +69,7 @@ namespace ShiftOS.WinForms.Applications private void startGame(int d) { + pictureBox1.Image = Properties.Resources.SweeperNormalFace; clearPreviousGame(); lbltime.Text = "Time: 0"; minetimer = 0; @@ -157,102 +166,14 @@ 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.Size = new System.Drawing.Size(minefieldPanel.Width / minefieldPanel.ColumnCount, (minefieldPanel.Height / minefieldPanel.RowCount) + 10); 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); + bttn.BackgroundImageLayout = ImageLayout.Stretch; 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; - if (!bttnClick.Enabled) return; - - 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) - { - 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--; - } - - 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] == -1 | 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); - if (minetimer < 61) cp = (Int32)(origminecount * 2.5); - if (minetimer < 91) cp = (origminecount * 2); - if (minetimer < 121) cp = (Int32)(origminecount * 1.5); - if (minetimer > 120) cp = (origminecount * 1); - SaveSystem.TransferCodepointsFrom("shiftsweeper", cp); - pictureBox1.BackgroundImage = Properties.Resources.SweeperWinFace; - //TODO add win - } - } - } - - private void mauseHov(object sender, EventArgs e) - { - if (ticking.Enabled) pictureBox1.BackgroundImage = Properties.Resources.SweeperNormalFace; - } - - private void mauseUp(object sender, MouseEventArgs e) - { - if (!ticking.Enabled) pictureBox1.BackgroundImage = Properties.Resources.SweeperNormalFace; - } - - private void mouseDwn(object sender, EventArgs e) - { - if (!ticking.Enabled) pictureBox1.BackgroundImage = Properties.Resources.SweeperClickFace; - } - private void bttnOnclick(object sender, EventArgs e) { if (!ticking.Enabled) return; @@ -267,56 +188,114 @@ namespace ShiftOS.WinForms.Applications int y = System.Convert.ToInt32(split[1]); - - if (minemap[x, y] == -1) + if (!flagtime) { - 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++) + if (minemap[x, y] == -1) { - for (int yy = 0; yy < minefieldPanel.RowCount; yy++) + 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++) { - minefieldPanel.GetControlFromPosition(xx, yy).Enabled = false; - if (minemap[xx, yy] == -1) + for (int yy = 0; yy < minefieldPanel.RowCount; yy++) { - minefieldPanel.GetControlFromPosition(xx, yy).BackgroundImage = Properties.Resources.SweeperTileBomb; + 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 (!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); + if (minetimer < 61) cp = (Int32)(origminecount * 2.5); + if (minetimer < 91) cp = (origminecount * 2); + if (minetimer < 121) cp = (Int32)(origminecount * 1.5); + if (minetimer > 120) cp = (origminecount * 1); + SaveSystem.TransferCodepointsFrom("shiftsweeper", cp); + pictureBox1.Image = Properties.Resources.SweeperWinFace; } } } - 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); + if (minemap[x, y] != 0) return; + for (int xx = -1; xx < 2; xx++) { - minefieldPanel.GetControlFromPosition(x, y).Enabled = false; - trueform(x, y); - for (int xx = -1; xx < 2; xx++) + for (int yy = -1; yy < 2; yy++) { - for (int yy = -1; yy < 2; yy++) + if (x + xx >= 0 && y + yy >= 0 && x + xx < minefieldPanel.ColumnCount && y + yy < minefieldPanel.RowCount) { - 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) { - 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) { - minefieldPanel.GetControlFromPosition(x + xx, y + yy).Enabled = false; - if (minemap[x + xx, y + yy] == 0) - { - removeBlank(x + xx, y + yy); - } + removeBlank(x + xx, y + yy); } - } } } @@ -340,5 +319,19 @@ namespace ShiftOS.WinForms.Applications private void buttonM_Click(object sender, EventArgs e) { startGame(1); } private void buttonH_Click(object sender, EventArgs e) { startGame(2); } + + 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; + } + } } } diff --git a/ShiftOS.WinForms/ShiftOS.WinForms.csproj b/ShiftOS.WinForms/ShiftOS.WinForms.csproj index 1802675..e061f82 100644 --- a/ShiftOS.WinForms/ShiftOS.WinForms.csproj +++ b/ShiftOS.WinForms/ShiftOS.WinForms.csproj @@ -541,6 +541,18 @@ + + + + + + + + + + + +