From 750ee144863c7d5f5cdbca02bec8d1aa3786d9e2 Mon Sep 17 00:00:00 2001 From: lempamo Date: Mon, 27 Feb 2017 09:53:39 -0500 Subject: made shiftsweeper look a bit nicer --- ShiftOS.WinForms/Applications/ShiftSweeper.cs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'ShiftOS.WinForms/Applications/ShiftSweeper.cs') diff --git a/ShiftOS.WinForms/Applications/ShiftSweeper.cs b/ShiftOS.WinForms/Applications/ShiftSweeper.cs index 529a7e8..91d220c 100644 --- a/ShiftOS.WinForms/Applications/ShiftSweeper.cs +++ b/ShiftOS.WinForms/Applications/ShiftSweeper.cs @@ -1,4 +1,4 @@ -/* +/* * MIT License * * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs @@ -192,14 +192,14 @@ namespace ShiftOS.WinForms.Applications } } - private Button makeButton(int col, int row) + private PictureBox makeButton(int col, int row) { - Button bttn = new Button(); + PictureBox bttn = new PictureBox(); 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) + 10); + 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; @@ -211,9 +211,9 @@ namespace ShiftOS.WinForms.Applications { if (!ticking.Enabled) return; - Button bttnClick = sender as Button; + PictureBox bttnClick = sender as PictureBox; - if (bttnClick == null) return; //not a button. + if (bttnClick == null) return; string[] split = bttnClick.Name.Split(new Char[] { ' ' }); @@ -299,10 +299,10 @@ namespace ShiftOS.WinForms.Applications 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); + 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; } @@ -337,7 +337,7 @@ namespace ShiftOS.WinForms.Applications private void trueform(int x, int y) { - Button bttn = (Button)minefieldPanel.GetControlFromPosition(x, 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; -- cgit v1.2.3 From 52b9cd9c8051a8d95587e3ccc3ee3220609bcc56 Mon Sep 17 00:00:00 2001 From: lempamo Date: Tue, 28 Feb 2017 11:58:24 -0500 Subject: more snakey stuff someone fix the snakey bug plz --- ShiftOS.WinForms/Applications/ShiftSweeper.cs | 1 - ShiftOS.WinForms/Applications/Snakey.cs | 2 +- ShiftOS.WinForms/ShiftOS.WinForms.csproj | 19 +++++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) (limited to 'ShiftOS.WinForms/Applications/ShiftSweeper.cs') diff --git a/ShiftOS.WinForms/Applications/ShiftSweeper.cs b/ShiftOS.WinForms/Applications/ShiftSweeper.cs index 6c64d30..0b05bdf 100644 --- a/ShiftOS.WinForms/Applications/ShiftSweeper.cs +++ b/ShiftOS.WinForms/Applications/ShiftSweeper.cs @@ -41,7 +41,6 @@ namespace ShiftOS.WinForms.Applications [DefaultIcon("iconShiftSweeper")] public partial class ShiftSweeper : UserControl, IShiftOSWindow { - private bool gameplayed = false; private bool flagtime = false; private int mineCount = 0; private int origminecount; diff --git a/ShiftOS.WinForms/Applications/Snakey.cs b/ShiftOS.WinForms/Applications/Snakey.cs index c3bd5cf..c6f61e9 100644 --- a/ShiftOS.WinForms/Applications/Snakey.cs +++ b/ShiftOS.WinForms/Applications/Snakey.cs @@ -17,7 +17,7 @@ namespace ShiftOS.WinForms.Applications [DefaultIcon("iconSnakey")] public partial class Snakey : UserControl, IShiftOSWindow { - private int[,] snakemap; // 0 - Nothing, 1 - Body, 2 - Head, 3 - Tail + private int[,] snakemap = null; // 0 - Nothing, 1 - Body, 2 - Head, 3 - Tail private int snakedirection = 0; // 0 - Left, 1 - Down, 2 - Right, 3 - Up private Timer snakeupdater = new Timer(); private bool extending = false; diff --git a/ShiftOS.WinForms/ShiftOS.WinForms.csproj b/ShiftOS.WinForms/ShiftOS.WinForms.csproj index e061f82..480e11c 100644 --- a/ShiftOS.WinForms/ShiftOS.WinForms.csproj +++ b/ShiftOS.WinForms/ShiftOS.WinForms.csproj @@ -196,6 +196,12 @@ Skin Loader.cs + + UserControl + + + Snakey.cs + UserControl @@ -342,6 +348,9 @@ Skin Loader.cs + + Snakey.cs + TextPad.cs @@ -553,6 +562,16 @@ + + + + + + + + + + -- cgit v1.2.3 From 8656337c5dc64bea29f330a51b362f0a6b85ef78 Mon Sep 17 00:00:00 2001 From: lempamo Date: Tue, 28 Feb 2017 12:11:40 -0500 Subject: fixed snakey crashing bug --- ShiftOS.WinForms/Applications/ShiftSweeper.cs | 1 - ShiftOS.WinForms/Applications/Snakey.cs | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) (limited to 'ShiftOS.WinForms/Applications/ShiftSweeper.cs') diff --git a/ShiftOS.WinForms/Applications/ShiftSweeper.cs b/ShiftOS.WinForms/Applications/ShiftSweeper.cs index 0b05bdf..aaeed3f 100644 --- a/ShiftOS.WinForms/Applications/ShiftSweeper.cs +++ b/ShiftOS.WinForms/Applications/ShiftSweeper.cs @@ -134,7 +134,6 @@ namespace ShiftOS.WinForms.Applications buttonE.Enabled = false; buttonM.Enabled = false; buttonH.Enabled = false; - gameplayed = true; makegrid(); } diff --git a/ShiftOS.WinForms/Applications/Snakey.cs b/ShiftOS.WinForms/Applications/Snakey.cs index c6f61e9..f210c9c 100644 --- a/ShiftOS.WinForms/Applications/Snakey.cs +++ b/ShiftOS.WinForms/Applications/Snakey.cs @@ -155,6 +155,7 @@ namespace ShiftOS.WinForms.Applications clearGame(); makeGrid(); } + snakemap = new int[10, 10]; snakemap[5, 5] = 2; tableLayoutPanel1.GetControlFromPosition(5, 5).BackgroundImage = Properties.Resources.SnakeyHeadL; for (int x = 6; x < 8; x++) -- cgit v1.2.3 From 99ba9c1f9c7b433b7defd09fdb110522f3a2b4c2 Mon Sep 17 00:00:00 2001 From: pfg Date: Sun, 5 Mar 2017 09:49:47 -0800 Subject: ShiftSweeper right click flagging --- .../Applications/ShiftSweeper.Designer.cs | 1 + ShiftOS.WinForms/Applications/ShiftSweeper.cs | 12 +++++++++--- ShiftOS.WinForms/ShiftOSAudioProvider.cs | 22 +++++++++++++++++----- 3 files changed, 27 insertions(+), 8 deletions(-) (limited to 'ShiftOS.WinForms/Applications/ShiftSweeper.cs') diff --git a/ShiftOS.WinForms/Applications/ShiftSweeper.Designer.cs b/ShiftOS.WinForms/Applications/ShiftSweeper.Designer.cs index 55844f1..8782260 100644 --- a/ShiftOS.WinForms/Applications/ShiftSweeper.Designer.cs +++ b/ShiftOS.WinForms/Applications/ShiftSweeper.Designer.cs @@ -299,6 +299,7 @@ namespace ShiftOS.WinForms.Applications this.Controls.Add(this.pictureBox1); 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(); this.ResumeLayout(false); diff --git a/ShiftOS.WinForms/Applications/ShiftSweeper.cs b/ShiftOS.WinForms/Applications/ShiftSweeper.cs index aaeed3f..d8de58e 100644 --- a/ShiftOS.WinForms/Applications/ShiftSweeper.cs +++ b/ShiftOS.WinForms/Applications/ShiftSweeper.cs @@ -205,8 +205,9 @@ namespace ShiftOS.WinForms.Applications return bttn; } - private void bttnOnclick(object sender, EventArgs e) + private void bttnOnclick(object sender, EventArgs ee) { + MouseEventArgs e = (MouseEventArgs)ee; if (!ticking.Enabled) return; PictureBox bttnClick = sender as PictureBox; @@ -218,8 +219,9 @@ namespace ShiftOS.WinForms.Applications int x = System.Convert.ToInt32(split[0]); int y = System.Convert.ToInt32(split[1]); + - if (!flagtime) + if (!flagtime && e.Button == MouseButtons.Left) { if (minemap[x, y] == -1) { @@ -249,7 +251,7 @@ namespace ShiftOS.WinForms.Applications else if (minemap[x, y] < -1) return; else removeBlank(x, y); } - else + else if(flagtime || e.Button == MouseButtons.Right) { if (!bttnClick.Enabled) return; @@ -364,5 +366,9 @@ namespace ShiftOS.WinForms.Applications flagtime = true; } } + + private void ShiftSweeper_Load(object sender, EventArgs e) { + + } } } diff --git a/ShiftOS.WinForms/ShiftOSAudioProvider.cs b/ShiftOS.WinForms/ShiftOSAudioProvider.cs index 27c0e5f..fccc76a 100644 --- a/ShiftOS.WinForms/ShiftOSAudioProvider.cs +++ b/ShiftOS.WinForms/ShiftOSAudioProvider.cs @@ -39,8 +39,13 @@ namespace ShiftOS.WinForms { get { - var wc = new System.Net.WebClient(); - return JsonConvert.DeserializeObject>(wc.DownloadString("http://getshiftos.ml/api.php?q=soundtrack")).Count; + System.Net.WebClient wc = new System.Net.WebClient(); + try { + string result = wc.DownloadString("http://getshiftos.ml/api.php?q=soundtrack"); + return JsonConvert.DeserializeObject>(result).Count; + } catch { + return JsonConvert.DeserializeObject>("[]").Count; + } } } @@ -73,10 +78,17 @@ namespace ShiftOS.WinForms public byte[] GetTrack(int index) { - var wc = new System.Net.WebClient(); - var st = JsonConvert.DeserializeObject>(wc.DownloadString("http://getshiftos.ml/api.php?q=soundtrack")); + System.Net.WebClient wc = new System.Net.WebClient(); + + try { + string result = wc.DownloadString("http://getshiftos.ml/api.php?q=soundtrack"); - return wc.DownloadData(st[index]); + var st = JsonConvert.DeserializeObject>(result); + + return wc.DownloadData(st[index]); + } catch { + return null; + } } } -- cgit v1.2.3 From 1d8e6dfcd5fe853df47a5403e52239f6c83a43f1 Mon Sep 17 00:00:00 2001 From: pfg Date: Sun, 5 Mar 2017 12:06:21 -0800 Subject: RefactoredSweeper base, next is winning/losing and codepoints --- .../Applications/ShiftSweeper.Designer.cs | 280 ++++--------- ShiftOS.WinForms/Applications/ShiftSweeper.cs | 450 ++++++++------------- 2 files changed, 246 insertions(+), 484 deletions(-) (limited to 'ShiftOS.WinForms/Applications/ShiftSweeper.cs') 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 - // - 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; - // - // easyPanel - // - 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; - // - // buttonE - // - 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); - // - // buttonM - // - 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); - // - // buttonH - // - 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); + // panelGameStatus + // + 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); + // + // gamePanel + // + 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); + // + // buttonEasy + // + 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); + // + // buttonMedium + // + 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); + // + // buttonHard + // + 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 ShiftSweeper() { InitializeComponent(); } - - 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; + public partial class ShiftSweeper : UserControl, IShiftOSWindow { + int[,] game; + int[,] currentGame; + bool gameCreated = false; + int gameBombCount; + int currentGameWidth; + int currentGameHeight; + + private static readonly Random random = new Random(); + + 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 bool OnUnload() { return true; } + public void OnSkinLoad() { + } - public void OnUpgrade() { } + public bool OnUnload() { + return true; + } - private void buttonE_Click(object sender, EventArgs e) { startGame(0); } + public void OnUpgrade() { - 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); + for (int y = 0; y < h; y++) { + for (int x = 0; x < w; x++) { + updateTile(x, y, UNDISCOVERED); } } + } - // 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--; - } + public void updateTile(int x, int y, int type) { + Button tile = new Button(); + + if (type == REMOVE) { + } else { + tile.Text = buttonImages[type]; + tile.MouseUp += new MouseEventHandler(tile_Click); + + tile.Size = tileSize; + + currentGame[x, y] = type; } - // 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; - } - } + var controlToRemove = gamePanel.GetControlFromPosition(y, x); + + if (controlToRemove != null) + gamePanel.Controls.Remove(controlToRemove); + + if (type != REMOVE) + gamePanel.Controls.Add(tile, y, x); + } + + private void tile_Click(object sender, EventArgs ee) { + MouseEventArgs e = (MouseEventArgs)ee; + Control sen = (Control)sender; + TableLayoutPanelCellPosition tilePos = gamePanel.GetPositionFromControl(sen); + + 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 PictureBox makeButton(int col, int row) - { - PictureBox bttn = new PictureBox(); + private void createGameIfNotExists(int x, int y) { + createGameIfNotExists(); - 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; + /*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(); + }*/ + } - return bttn; + 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 bttnOnclick(object sender, EventArgs ee) - { - MouseEventArgs e = (MouseEventArgs)ee; - if (!ticking.Enabled) return; + private int getBombCountInArea(int x, int y) { + createGameIfNotExists(x, y); + + if (game[x, y] == 9) return 9; - PictureBox bttnClick = sender as PictureBox; + int count = 0; + int w = currentGameWidth - 1; + int h = currentGameHeight - 1; - if (bttnClick == null) return; + 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; - string[] split = bttnClick.Name.Split(new Char[] { ' ' }); + 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; - int x = System.Convert.ToInt32(split[0]); - int y = System.Convert.ToInt32(split[1]); + return count; + } - + private void revealTile(int x, int y) { + createGameIfNotExists(x, y); - if (!flagtime && e.Button == MouseButtons.Left) - { - if (minemap[x, y] == -1) - { - ticking.Enabled = false; + int bombs = getBombCountInArea(x, y); + int previousBombs = currentGame[x, y]; - buttonE.Enabled = true; - buttonM.Enabled = true; - buttonH.Enabled = true; + updateTile(x, y, bombs); - pictureBox1.BackgroundImage = Properties.Resources.SweeperLoseFace; + if (bombs == 0 && previousBombs == UNDISCOVERED) { + int w = currentGameWidth - 1; + int h = currentGameHeight - 1; - 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; - } + 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); - } - } - pictureBox1.Image = Properties.Resources.SweeperLoseFace; - } - else if (minemap[x, y] < -1) return; - else removeBlank(x, y); + 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); } - 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; - } - } + } + + 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 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 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 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 void buttonEasy_Click(object sender, EventArgs e) { + startGame(10, 10, 10); } - private void buttonM_Click(object sender, EventArgs e) { startGame(1); } + private void buttonMedium_Click(object sender, EventArgs e) { + startGame(11, 11, 11); + } - private void buttonH_Click(object sender, EventArgs e) { startGame(2); } + private void buttonHard_Click(object sender, EventArgs e) { + startGame(12, 12, 12); + } + + private void panelGameStatus_Click(object sender, EventArgs e) { - 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; - } } - private void ShiftSweeper_Load(object sender, EventArgs e) { + private void gamePanel_Paint(object sender, PaintEventArgs e) { } } -- cgit v1.2.3 From ca19c496ded9f4080ce99d927e9f1abf351fbaf0 Mon Sep 17 00:00:00 2001 From: pfg Date: Sun, 5 Mar 2017 14:27:00 -0800 Subject: Mineswapper complete --- ShiftOS.WinForms/Applications/ShiftSweeper.cs | 85 ++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) (limited to 'ShiftOS.WinForms/Applications/ShiftSweeper.cs') diff --git a/ShiftOS.WinForms/Applications/ShiftSweeper.cs b/ShiftOS.WinForms/Applications/ShiftSweeper.cs index a39bf41..477bd87 100644 --- a/ShiftOS.WinForms/Applications/ShiftSweeper.cs +++ b/ShiftOS.WinForms/Applications/ShiftSweeper.cs @@ -46,6 +46,9 @@ namespace ShiftOS.WinForms.Applications { int currentGameWidth; int currentGameHeight; + private Timer ticking = new Timer(); + private int minetimer; + private static readonly Random random = new Random(); Size tileSize; @@ -75,10 +78,21 @@ namespace ShiftOS.WinForms.Applications { InitializeComponent(); } + private void Ticking_Tick(object sender, EventArgs e) { + minetimer++; + lbltime.Text = "Time: " + minetimer.ToString(); + /*lbltime.Text = Localization.Parse("{SHIFTSWEEPER_TIME}", new Dictionary{ + {"%time", minetimer.ToString()} + });*/ + } + public void OnLoad() { buttonEasy.Visible = true; buttonMedium.Visible = ShiftoriumFrontend.UpgradeInstalled("shiftsweeper_medium"); buttonHard.Visible = ShiftoriumFrontend.UpgradeInstalled("shiftsweeper_hard"); + + ticking.Interval = 1000; + ticking.Tick += Ticking_Tick; } public void OnSkinLoad() { @@ -93,6 +107,8 @@ namespace ShiftOS.WinForms.Applications { } public void startGame(int w, int h, int b) { + panelGameStatus.Image = Properties.Resources.SweeperNormalFace; + if (gamePanel.RowCount > w || gamePanel.ColumnCount > h) { for (int y = 0; y < gamePanel.ColumnCount; y++) { for (int x = 0; x < gamePanel.RowCount; x++) { @@ -128,6 +144,7 @@ namespace ShiftOS.WinForms.Applications { if (type == REMOVE) { } else { tile.Text = buttonImages[type]; + tile.MouseDown += new MouseEventHandler(tile_ClickDown); tile.MouseUp += new MouseEventHandler(tile_Click); tile.Size = tileSize; @@ -145,6 +162,8 @@ namespace ShiftOS.WinForms.Applications { } private void tile_Click(object sender, EventArgs ee) { + panelGameStatus.Image = Properties.Resources.SweeperNormalFace; + MouseEventArgs e = (MouseEventArgs)ee; Control sen = (Control)sender; TableLayoutPanelCellPosition tilePos = gamePanel.GetPositionFromControl(sen); @@ -158,6 +177,10 @@ namespace ShiftOS.WinForms.Applications { } } + private void tile_ClickDown(object sender, EventArgs e) { + panelGameStatus.Image = Properties.Resources.SweeperClickFace; + } + private void createGameIfNotExists(int x, int y) { createGameIfNotExists(); @@ -225,6 +248,9 @@ namespace ShiftOS.WinForms.Applications { if (x < w && y > 0) revealTile(x + 1, y - 1); if (x > 0 && y < h) revealTile(x - 1, y + 1); } + + if (bombs != 0) checkWinGame(); + if (bombs == 9) loseGame(); } private void toggleTileFlag(int x, int y) { @@ -233,6 +259,8 @@ namespace ShiftOS.WinForms.Applications { } else if(currentGame[x, y] == FLAGGED) { updateTile(x, y, UNDISCOVERED); } + + checkWinGame(); } private void toggleTileQuestionMark(int x, int y) { @@ -241,10 +269,12 @@ namespace ShiftOS.WinForms.Applications { } else if (currentGame[x, y] == QUESTIONED) { updateTile(x, y, UNDISCOVERED); } + + checkWinGame(); } private void buttonEasy_Click(object sender, EventArgs e) { - startGame(10, 10, 10); + startGame(9, 9, 10); } private void buttonMedium_Click(object sender, EventArgs e) { @@ -255,6 +285,59 @@ namespace ShiftOS.WinForms.Applications { startGame(12, 12, 12); } + public void winGame() { + int cp = 0; + int origminecount = gameBombCount * 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); + panelGameStatus.Image = Properties.Resources.SweeperWinFace; + disableAllTiles(false); + } + + public void loseGame() { + disableAllTiles(true); + panelGameStatus.Image = Properties.Resources.SweeperLoseFace; + } + + 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; + } + + } + } + } + + public void checkWinGame() { + for(int y = 0; y < currentGameHeight; y++) { + for(int x = 0; x < currentGameWidth; x++) { + int tile = currentGame[x, y]; + if(tile == UNDISCOVERED || tile == QUESTIONED) { + return; + } + if(tile == FLAGGED) { + if(game[x,y] != 9) { + // looks like you flagged the wrong thing... + return; + } + } + if(tile == 9) { + loseGame(); + return; + } + + } + } + winGame(); + } + private void panelGameStatus_Click(object sender, EventArgs e) { } -- cgit v1.2.3 From 2b3a4f91b2809932c1a938b6ba4633d5606fcecd Mon Sep 17 00:00:00 2001 From: pfg Date: Sun, 5 Mar 2017 15:08:53 -0800 Subject: Minesweeper refactor complete --- .../Applications/ShiftSweeper.Designer.cs | 4 +-- ShiftOS.WinForms/Applications/ShiftSweeper.cs | 42 +++++++++++++--------- 2 files changed, 27 insertions(+), 19 deletions(-) (limited to 'ShiftOS.WinForms/Applications/ShiftSweeper.cs') 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; } } -- cgit v1.2.3 From 4989356d6797335b44060ae94c9af34404773506 Mon Sep 17 00:00:00 2001 From: pfg Date: Tue, 7 Mar 2017 17:33:39 -0800 Subject: Very early version of FormatEditor --- .../Applications/FormatEditor.Designer.cs | 210 +++++++++++++ ShiftOS.WinForms/Applications/FormatEditor.cs | 343 +++++++++++++++++++++ ShiftOS.WinForms/Applications/FormatEditor.resx | 120 +++++++ ShiftOS.WinForms/Applications/ShiftSweeper.cs | 9 +- ShiftOS.WinForms/Resources/Shiftorium.txt | 30 ++ ShiftOS.WinForms/ShiftOS.WinForms.csproj | 9 + ShiftOS_TheReturn/AudioManager.cs | 2 +- 7 files changed, 718 insertions(+), 5 deletions(-) create mode 100644 ShiftOS.WinForms/Applications/FormatEditor.Designer.cs create mode 100644 ShiftOS.WinForms/Applications/FormatEditor.cs create mode 100644 ShiftOS.WinForms/Applications/FormatEditor.resx (limited to 'ShiftOS.WinForms/Applications/ShiftSweeper.cs') diff --git a/ShiftOS.WinForms/Applications/FormatEditor.Designer.cs b/ShiftOS.WinForms/Applications/FormatEditor.Designer.cs new file mode 100644 index 0000000..2f628f1 --- /dev/null +++ b/ShiftOS.WinForms/Applications/FormatEditor.Designer.cs @@ -0,0 +1,210 @@ +/* + * MIT License + * + * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +namespace ShiftOS.WinForms.Applications +{ + partial class FormatEditor + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.panelEditor = new System.Windows.Forms.Panel(); + this.btnAddText = new System.Windows.Forms.Button(); + this.btnAddOptionalText = new System.Windows.Forms.Button(); + this.btnAddRegexText = new System.Windows.Forms.Button(); + this.btnAddCommand = new System.Windows.Forms.Button(); + this.lblExampleCommand = new System.Windows.Forms.Label(); + this.btnAddColor = new System.Windows.Forms.Button(); + this.richTextBox1 = new System.Windows.Forms.RichTextBox(); + this.btnTest = new System.Windows.Forms.Button(); + this.button1 = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // panelEditor + // + this.panelEditor.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.panelEditor.AutoScroll = true; + this.panelEditor.Location = new System.Drawing.Point(4, 4); + this.panelEditor.Name = "panelEditor"; + this.panelEditor.Size = new System.Drawing.Size(589, 46); + this.panelEditor.TabIndex = 1; + // + // btnAddText + // + this.btnAddText.Location = new System.Drawing.Point(4, 56); + this.btnAddText.Name = "btnAddText"; + this.btnAddText.Size = new System.Drawing.Size(75, 23); + this.btnAddText.TabIndex = 2; + this.btnAddText.Text = "Add Text"; + this.btnAddText.UseVisualStyleBackColor = true; + this.btnAddText.Click += new System.EventHandler(this.btnAddText_Click); + // + // btnAddOptionalText + // + this.btnAddOptionalText.Location = new System.Drawing.Point(85, 56); + this.btnAddOptionalText.Name = "btnAddOptionalText"; + this.btnAddOptionalText.Size = new System.Drawing.Size(107, 23); + this.btnAddOptionalText.TabIndex = 3; + this.btnAddOptionalText.Text = "Add Optional Text"; + this.btnAddOptionalText.UseVisualStyleBackColor = true; + this.btnAddOptionalText.Click += new System.EventHandler(this.btnAddOptionalText_Click); + // + // btnAddRegexText + // + this.btnAddRegexText.Location = new System.Drawing.Point(198, 56); + this.btnAddRegexText.Name = "btnAddRegexText"; + this.btnAddRegexText.Size = new System.Drawing.Size(107, 23); + this.btnAddRegexText.TabIndex = 4; + this.btnAddRegexText.Text = "Add Regex Text"; + this.btnAddRegexText.UseVisualStyleBackColor = true; + this.btnAddRegexText.Click += new System.EventHandler(this.btnAddRegexText_Click); + // + // btnAddCommand + // + this.btnAddCommand.Location = new System.Drawing.Point(4, 85); + this.btnAddCommand.Name = "btnAddCommand"; + this.btnAddCommand.Size = new System.Drawing.Size(75, 23); + this.btnAddCommand.TabIndex = 5; + this.btnAddCommand.Text = "+ Command"; + this.btnAddCommand.UseVisualStyleBackColor = true; + this.btnAddCommand.Click += new System.EventHandler(this.btnAddCommand_Click); + // + // lblExampleCommand + // + this.lblExampleCommand.AutoSize = true; + this.lblExampleCommand.Location = new System.Drawing.Point(4, 115); + this.lblExampleCommand.Name = "lblExampleCommand"; + this.lblExampleCommand.Size = new System.Drawing.Size(290, 13); + this.lblExampleCommand.TabIndex = 8; + this.lblExampleCommand.Text = "Create a command and an example usage will show up here"; + // + // btnAddColor + // + this.btnAddColor.Location = new System.Drawing.Point(311, 56); + this.btnAddColor.Name = "btnAddColor"; + this.btnAddColor.Size = new System.Drawing.Size(64, 23); + this.btnAddColor.TabIndex = 9; + this.btnAddColor.Text = "Add Color"; + this.btnAddColor.UseVisualStyleBackColor = true; + this.btnAddColor.Click += new System.EventHandler(this.btnAddColor_Click); + // + // richTextBox1 + // + this.richTextBox1.Location = new System.Drawing.Point(7, 132); + this.richTextBox1.Multiline = false; + this.richTextBox1.Name = "richTextBox1"; + this.richTextBox1.Size = new System.Drawing.Size(476, 23); + this.richTextBox1.TabIndex = 10; + this.richTextBox1.Text = ""; + this.richTextBox1.TextChanged += new System.EventHandler(this.richTextBox1_TextChanged); + // + // btnTest + // + this.btnTest.Location = new System.Drawing.Point(490, 132); + this.btnTest.Name = "btnTest"; + this.btnTest.Size = new System.Drawing.Size(47, 23); + this.btnTest.TabIndex = 11; + this.btnTest.Text = "Test"; + this.btnTest.UseVisualStyleBackColor = true; + this.btnTest.Click += new System.EventHandler(this.btnTest_Click); + // + // button1 + // + this.button1.Location = new System.Drawing.Point(7, 161); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(47, 23); + this.button1.TabIndex = 12; + this.button1.Text = "Apply"; + this.button1.UseVisualStyleBackColor = true; + // + // button2 + // + this.button2.Location = new System.Drawing.Point(60, 161); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(47, 23); + this.button2.TabIndex = 13; + this.button2.Text = "Save"; + this.button2.UseVisualStyleBackColor = true; + // + // FormatEditor + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.button2); + this.Controls.Add(this.button1); + this.Controls.Add(this.btnTest); + this.Controls.Add(this.richTextBox1); + this.Controls.Add(this.btnAddColor); + this.Controls.Add(this.lblExampleCommand); + this.Controls.Add(this.btnAddText); + this.Controls.Add(this.btnAddOptionalText); + this.Controls.Add(this.btnAddRegexText); + this.Controls.Add(this.btnAddCommand); + this.Controls.Add(this.panelEditor); + this.Name = "FormatEditor"; + this.Size = new System.Drawing.Size(596, 426); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + private System.Windows.Forms.Panel panelEditor; + private System.Windows.Forms.Button btnAddText; + private System.Windows.Forms.Button btnAddOptionalText; + private System.Windows.Forms.Button btnAddRegexText; + private System.Windows.Forms.Button btnAddCommand; + private System.Windows.Forms.Label lblExampleCommand; + private System.Windows.Forms.Button btnAddColor; + private System.Windows.Forms.RichTextBox richTextBox1; + private System.Windows.Forms.Button btnTest; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button button2; + } +} diff --git a/ShiftOS.WinForms/Applications/FormatEditor.cs b/ShiftOS.WinForms/Applications/FormatEditor.cs new file mode 100644 index 0000000..ef44b47 --- /dev/null +++ b/ShiftOS.WinForms/Applications/FormatEditor.cs @@ -0,0 +1,343 @@ +/* + * MIT License + * + * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using ShiftOS.Engine; + +namespace ShiftOS.WinForms.Applications { + [Launcher("FormatEditor", true, "al_format_editor", "Games")] + [RequiresUpgrade("format_editor")] + [WinOpen("formateditor")] + [DefaultIcon("iconFormatEditor")] + + public partial class FormatEditor : UserControl, IShiftOSWindow { + + IList parts = new List(); + IList editorBoxes = new List(); + + string commandMode = "command"; + int avcount = 0; + + public FormatEditor() { + InitializeComponent(); + } + + public void OnLoad() { + OnUpgrade(); + } + + public void OnSkinLoad() { } + + public bool OnUnload() { return true; } + + public void OnUpgrade() { + btnAddOptionalText.Visible = ShiftoriumFrontend.UpgradeInstalled("format_editor_optional_text"); + btnAddRegexText.Visible = ShiftoriumFrontend.UpgradeInstalled("format_editor_regex"); + btnAddColor.Visible = ShiftoriumFrontend.UpgradeInstalled("format_editor_syntax_highlighting"); + } + + private void addPart(CommandFormat part) { + parts.Add(part); + Panel container = new Panel(); + + Control drawnPart = part.Draw(); + container.Size = drawnPart.Size; + container.Controls.Add(drawnPart); + + int woffset = 0; + if (editorBoxes.Count > 0) { + woffset = editorBoxes.Last().Width + editorBoxes.Last().Location.X; + } else { + woffset = 0; + } + + container.Location = new Point(woffset, 0); + editorBoxes.Add(container); + panelEditor.Controls.Add(container); + } + + private void btnAddText_Click(object sender, EventArgs e) { + addPart(new CommandFormatText()); + } + + private void btnAddOptionalText_Click(object sender, EventArgs e) { + addPart(new CommandFormatOptionalText()); + } + + private void btnAddRegexText_Click(object sender, EventArgs e) { + + } + + private void btnAddColor_Click(object sender, EventArgs e) { + + } + + private void btnAddCommand_Click(object sender, EventArgs e) { + switch (commandMode) { + case "command": + addPart(new CommandFormatCommand()); + commandMode = "argument"; + btnAddCommand.Text = "+ Argument"; + break; + case "argument": + addPart(new CommandFormatArgument()); + commandMode = "value"; + btnAddCommand.Text = "+ \"Value\""; + break; + case "value": + addPart(new CommandFormatValue()); + avcount++; + if (avcount >= 2) { + commandMode = ""; + btnAddCommand.Text = ""; + btnAddCommand.Enabled = false; + }else { + commandMode = "argument"; + btnAddCommand.Text = "+ Argument"; + } + break; + } + } + + private void richTextBox1_TextChanged(object sender, EventArgs e) { + string command = ""; + Dictionary arguments = new Dictionary(); + + string text = richTextBox1.Text; + int position = 0; + + int commandPos; + int firstValuePos = -1; + int lastValuePos = -1; + + for(int ii = 0; ii < parts.Count; ii++) { + CommandFormat part = parts[ii]; + if (part is CommandFormatMarker) { + if (part is CommandFormatCommand) { + commandPos = ii; + } else if (part is CommandFormatValue) { + if (firstValuePos > -1) + lastValuePos = ii; + else + firstValuePos = ii; + } + } + } + + int i = 0; + string currentArgument = ""; + int help = -1; + + while (position < text.Length) { + + if (i >= parts.Count) { + position = text.Length; + command = "+FALSE+"; + i = 0; + } + + CommandFormat part = parts[i]; + string res = part.CheckValidity(text.Substring(position)); + + // ok so: + + // example + // COMMAND text[ --] ARGUMENT VALUE text[ --] ARGUMENT VALUE + // COMMAND text[{] ARGUMENT text[=] VALUE text[, ] ARGUMENT text[=] VALUE text[}] + + if (part is CommandFormatMarker) { + if (part is CommandFormatCommand) { + command = res; + help = -1; + } else if (part is CommandFormatArgument) { + currentArgument = res; + help = -1; + } else if (part is CommandFormatValue) { + arguments[currentArgument] = res; + + if(i == firstValuePos) + help = lastValuePos; + if (i == lastValuePos) + help = firstValuePos; + } + } + + if(res == "+FALSE+") { + if(help > -1) { + i = help; + if(i >= parts.Count) { + position = text.Length; + command = "+FALSE+"; + } + }else { + position = text.Length; + command = "+FALSE+"; + } + help = -1; + }else { + position += res.Length; + } + + i++; + } + + if (command == "+FALSE+") { + lblExampleCommand.Text = "Syntax Error"; + } else { + string argvs = "{"; + + foreach (KeyValuePair entry in arguments) { + argvs += entry.Key + "=" + entry.Value + ", "; + } + + argvs += "}"; + + lblExampleCommand.Text = command + argvs; + } + } + + private void btnTest_Click(object sender, EventArgs e) { + + } + } + + interface CommandFormat { + string CheckValidity(string check); + Control Draw(); + } + class CommandFormatText : CommandFormat { + protected string str; + TextBox textBox; + + public CommandFormatText() { + } + + public virtual string CheckValidity(string check) { + return check.StartsWith(str) ? str : "+FALSE+"; + } + + public Control Draw() { + textBox = new TextBox(); + textBox.TextChanged += new EventHandler(TextChanged); + textBox.Location = new Point(0,0); + + return textBox; + } + + void TextChanged(object sender, EventArgs e) { + str = textBox.Text; + } + } + + class CommandFormatOptionalText : CommandFormatText { + public override string CheckValidity(string check) { + return check.StartsWith(str) ? str : ""; + } + } + + class CommandFormatMarker : CommandFormat { + protected string str; + Button button; + + public CommandFormatMarker() { + } + + public virtual string CheckValidity(string check) { + string res = string.Empty; + string alphanumeric = "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm1234567890"; // not using regex for performance reasons + + foreach (char c in check) { + if (alphanumeric.IndexOf(c) > -1) { + res += c; + } else { + break; + } + } + + return res; + } + + public virtual Control Draw() { + button = new Button(); + button.Location = new Point(0, 0); + button.Text = "Marker"; + + return button; + } + } + + class CommandFormatCommand : CommandFormatMarker { + public override Control Draw() { + Button draw = (Button)base.Draw(); + draw.Text = "Command"; + return draw; + } + } + + class CommandFormatArgument : CommandFormatMarker { + public override Control Draw() { + Button draw = (Button)base.Draw(); + draw.Text = "Argument"; + return draw; + } + } + + class CommandFormatValue : CommandFormatMarker { + public override string CheckValidity(string cd) { + string res = string.Empty; + var check = ""; + + if (cd.StartsWith("\"")) + check = cd.Substring(1); + bool done = false; + + foreach (char c in check) { + Console.WriteLine(check); + if (c != '"') { + res += c; + } else { + done = true; + res += "\""; + break; + } + } + + return done ? "\""+res : "+FALSE+"; + } + + public override Control Draw() { + Button draw = (Button)base.Draw(); + draw.Text = "\"Value\""; + return draw; + } + } +} diff --git a/ShiftOS.WinForms/Applications/FormatEditor.resx b/ShiftOS.WinForms/Applications/FormatEditor.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/ShiftOS.WinForms/Applications/FormatEditor.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ShiftOS.WinForms/Applications/ShiftSweeper.cs b/ShiftOS.WinForms/Applications/ShiftSweeper.cs index 69db034..b13880f 100644 --- a/ShiftOS.WinForms/Applications/ShiftSweeper.cs +++ b/ShiftOS.WinForms/Applications/ShiftSweeper.cs @@ -87,15 +87,14 @@ namespace ShiftOS.WinForms.Applications { } public void OnLoad() { - buttonEasy.Visible = true; - buttonMedium.Visible = ShiftoriumFrontend.UpgradeInstalled("shiftsweeper_medium"); - buttonHard.Visible = ShiftoriumFrontend.UpgradeInstalled("shiftsweeper_hard"); + OnUpgrade(); ticking.Interval = 1000; ticking.Tick += Ticking_Tick; } public void OnSkinLoad() { + } public bool OnUnload() { @@ -103,7 +102,9 @@ namespace ShiftOS.WinForms.Applications { } public void OnUpgrade() { - + buttonEasy.Visible = true; + buttonMedium.Visible = ShiftoriumFrontend.UpgradeInstalled("shiftsweeper_medium"); + buttonHard.Visible = ShiftoriumFrontend.UpgradeInstalled("shiftsweeper_hard"); } public void startGame(int w, int h, int b) { diff --git a/ShiftOS.WinForms/Resources/Shiftorium.txt b/ShiftOS.WinForms/Resources/Shiftorium.txt index 841a24e..8e09d6e 100644 --- a/ShiftOS.WinForms/Resources/Shiftorium.txt +++ b/ShiftOS.WinForms/Resources/Shiftorium.txt @@ -251,6 +251,36 @@ Description: "Add a launcher item for the MUD cracker.", Dependencies: "mud_cracker;app_launcher" }, + { + Name: "Format Editor", + Cost: 6000, + Description: "Allows you to change the format of commands.", + Dependencies: "shifter;name_changer" + }, + { + Name: "Format Editor Optional Text", + Cost: 150, + Description: "Allows you to add an optional text to commands", + Dependencies: "format_editor" + }, + { + Name: "Format Editor Regex", + Cost: 150, + Description: "Allows you to customize your commands with regexes.", + Dependencies: "format_editor_optional_text" + }, + { + Name: "Format Editor Syntax Highligting", + Cost: 150, + Description: "Allows you to give color to commands as the user types them.", + Dependencies: "format_editor_regex" + }, + { + Name: "AL Format Editor", + Cost: 150, + Description: "Add a launcher item for the Format Editor.", + Dependencies: "format_editor;app_launcher" + }, { Name: "Textpad", Cost: 2500, diff --git a/ShiftOS.WinForms/ShiftOS.WinForms.csproj b/ShiftOS.WinForms/ShiftOS.WinForms.csproj index 7d4f0d3..8afa76e 100644 --- a/ShiftOS.WinForms/ShiftOS.WinForms.csproj +++ b/ShiftOS.WinForms/ShiftOS.WinForms.csproj @@ -178,6 +178,12 @@ ShiftoriumFrontend.cs + + UserControl + + + FormatEditor.cs + UserControl @@ -334,6 +340,9 @@ ShiftoriumFrontend.cs + + FormatEditor.cs + ShiftSweeper.cs diff --git a/ShiftOS_TheReturn/AudioManager.cs b/ShiftOS_TheReturn/AudioManager.cs index a548cf6..7f6f5e9 100644 --- a/ShiftOS_TheReturn/AudioManager.cs +++ b/ShiftOS_TheReturn/AudioManager.cs @@ -69,7 +69,7 @@ namespace ShiftOS.Engine { int track = rnd.Next(0, _provider.Count); byte[] mp3 = _provider.GetTrack(track); - System.IO.File.WriteAllBytes("temp.mp3", mp3); + System.IO.File.WriteAllBytes("temp.mp3", mp3); _reader = new AudioFileReader("temp.mp3"); _out = new WaveOut(); _out.Init(_reader); -- cgit v1.2.3 From a9754b7df28795b6bb2c5cfe04c1b38b19fb0d05 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 10 Mar 2017 12:29:28 -0500 Subject: Lock certain apps away when system offline. --- ShiftOS.WinForms/Applications/Artpad.cs | 1 + ShiftOS.WinForms/Applications/Chat.cs | 1 + ShiftOS.WinForms/Applications/Downloader.cs | 1 + ShiftOS.WinForms/Applications/FormatEditor.cs | 1 + ShiftOS.WinForms/Applications/GraphicPicker.cs | 1 + ShiftOS.WinForms/Applications/MUDControlCentre.cs | 1 + ShiftOS.WinForms/Applications/NameChanger.cs | 1 + ShiftOS.WinForms/Applications/Pong.cs | 1 + ShiftOS.WinForms/Applications/ShiftLetters.cs | 1 + ShiftOS.WinForms/Applications/ShiftLotto.cs | 1 + ShiftOS.WinForms/Applications/ShiftSweeper.cs | 1 + ShiftOS.WinForms/Applications/Shifter.cs | 1 + ShiftOS.WinForms/Applications/Shiftnet.cs | 1 + .../Applications/ShiftoriumFrontend.cs | 1 + ShiftOS.WinForms/HackerCommands.cs | 10 ++++++ ShiftOS.WinForms/WinformsWindowManager.cs | 18 ++++++++++ ShiftOS_TheReturn/AppLauncherDaemon.cs | 20 +++++++++--- ShiftOS_TheReturn/KernelWatchdog.cs | 38 +++++++++++++++++++++- ShiftOS_TheReturn/Scripting.cs | 7 ++-- 19 files changed, 100 insertions(+), 7 deletions(-) (limited to 'ShiftOS.WinForms/Applications/ShiftSweeper.cs') diff --git a/ShiftOS.WinForms/Applications/Artpad.cs b/ShiftOS.WinForms/Applications/Artpad.cs index 6c1bc1c..71f7afb 100644 --- a/ShiftOS.WinForms/Applications/Artpad.cs +++ b/ShiftOS.WinForms/Applications/Artpad.cs @@ -41,6 +41,7 @@ using ShiftOS.Engine; namespace ShiftOS.WinForms.Applications { + [MultiplayerOnly] [Launcher("Artpad", true, "al_artpad", "Graphics")] [RequiresUpgrade("artpad")] [WinOpen("artpad")] diff --git a/ShiftOS.WinForms/Applications/Chat.cs b/ShiftOS.WinForms/Applications/Chat.cs index 06a7873..caf8cd2 100644 --- a/ShiftOS.WinForms/Applications/Chat.cs +++ b/ShiftOS.WinForms/Applications/Chat.cs @@ -36,6 +36,7 @@ using ShiftOS.Engine; namespace ShiftOS.WinForms.Applications { + [MultiplayerOnly] public partial class Chat : UserControl, IShiftOSWindow { public Chat(string chatId) diff --git a/ShiftOS.WinForms/Applications/Downloader.cs b/ShiftOS.WinForms/Applications/Downloader.cs index da90c6d..1f240bf 100644 --- a/ShiftOS.WinForms/Applications/Downloader.cs +++ b/ShiftOS.WinForms/Applications/Downloader.cs @@ -41,6 +41,7 @@ using System.IO.Compression; namespace ShiftOS.WinForms.Applications { + [MultiplayerOnly] [Launcher("Downloader", false, null, "Networking")] [DefaultIcon("iconDownloader")] public partial class Downloader : UserControl, IShiftOSWindow diff --git a/ShiftOS.WinForms/Applications/FormatEditor.cs b/ShiftOS.WinForms/Applications/FormatEditor.cs index ef44b47..56b0253 100644 --- a/ShiftOS.WinForms/Applications/FormatEditor.cs +++ b/ShiftOS.WinForms/Applications/FormatEditor.cs @@ -34,6 +34,7 @@ using System.Windows.Forms; using ShiftOS.Engine; namespace ShiftOS.WinForms.Applications { + [MultiplayerOnly] [Launcher("FormatEditor", true, "al_format_editor", "Games")] [RequiresUpgrade("format_editor")] [WinOpen("formateditor")] diff --git a/ShiftOS.WinForms/Applications/GraphicPicker.cs b/ShiftOS.WinForms/Applications/GraphicPicker.cs index 2dfe7ec..b3dd8bf 100644 --- a/ShiftOS.WinForms/Applications/GraphicPicker.cs +++ b/ShiftOS.WinForms/Applications/GraphicPicker.cs @@ -37,6 +37,7 @@ using ShiftOS.WinForms.Tools; namespace ShiftOS.WinForms.Applications { + [MultiplayerOnly] [DefaultTitle("Choose graphic")] [DefaultIcon("icongraphicpicker")] public partial class GraphicPicker : UserControl, IShiftOSWindow { diff --git a/ShiftOS.WinForms/Applications/MUDControlCentre.cs b/ShiftOS.WinForms/Applications/MUDControlCentre.cs index 02fe868..e2668bd 100644 --- a/ShiftOS.WinForms/Applications/MUDControlCentre.cs +++ b/ShiftOS.WinForms/Applications/MUDControlCentre.cs @@ -38,6 +38,7 @@ using ShiftOS.WinForms.Tools; namespace ShiftOS.WinForms.Applications { + [MultiplayerOnly] [RequiresUpgrade("mud_fundamentals")] [Launcher("MUD Control Centre", true, "al_mud_control_centre", "Networking")] [WinOpen("mud_control_centre")] diff --git a/ShiftOS.WinForms/Applications/NameChanger.cs b/ShiftOS.WinForms/Applications/NameChanger.cs index ca76e57..d7c99f7 100644 --- a/ShiftOS.WinForms/Applications/NameChanger.cs +++ b/ShiftOS.WinForms/Applications/NameChanger.cs @@ -38,6 +38,7 @@ using ShiftOS.WinForms.Tools; namespace ShiftOS.WinForms.Applications { + [MultiplayerOnly] [Launcher("Name Changer", true, "al_name_changer", "Customization")] [RequiresUpgrade("name_changer")] [WinOpen("name_changer")] diff --git a/ShiftOS.WinForms/Applications/Pong.cs b/ShiftOS.WinForms/Applications/Pong.cs index af1e156..157ce8c 100644 --- a/ShiftOS.WinForms/Applications/Pong.cs +++ b/ShiftOS.WinForms/Applications/Pong.cs @@ -37,6 +37,7 @@ using ShiftOS.Objects; namespace ShiftOS.WinForms.Applications { + [MultiplayerOnly] [Launcher("Pong", true, "al_pong", "Games")] [WinOpen("pong")] [DefaultIcon("iconPong")] diff --git a/ShiftOS.WinForms/Applications/ShiftLetters.cs b/ShiftOS.WinForms/Applications/ShiftLetters.cs index 700df7e..b5e9aa4 100644 --- a/ShiftOS.WinForms/Applications/ShiftLetters.cs +++ b/ShiftOS.WinForms/Applications/ShiftLetters.cs @@ -36,6 +36,7 @@ using System.Windows.Forms; namespace ShiftOS.WinForms.Applications { + [MultiplayerOnly] [Launcher("ShiftLetters", false, null, "Games")] [RequiresUpgrade("shiftletters")] [WinOpen("shiftletters")] diff --git a/ShiftOS.WinForms/Applications/ShiftLotto.cs b/ShiftOS.WinForms/Applications/ShiftLotto.cs index 7acba3e..33f357f 100644 --- a/ShiftOS.WinForms/Applications/ShiftLotto.cs +++ b/ShiftOS.WinForms/Applications/ShiftLotto.cs @@ -35,6 +35,7 @@ using ShiftOS.Engine; namespace ShiftOS.WinForms.Applications { [Launcher("ShiftLotto", true, "al_shiftlotto", "Games")] + [MultiplayerOnly] [DefaultIcon("iconShiftLotto")] [RequiresUpgrade("shiftlotto")] [WinOpen("shiftlotto")] diff --git a/ShiftOS.WinForms/Applications/ShiftSweeper.cs b/ShiftOS.WinForms/Applications/ShiftSweeper.cs index b13880f..cf6d331 100644 --- a/ShiftOS.WinForms/Applications/ShiftSweeper.cs +++ b/ShiftOS.WinForms/Applications/ShiftSweeper.cs @@ -36,6 +36,7 @@ using ShiftOS.Engine; namespace ShiftOS.WinForms.Applications { [Launcher("ShiftSweeper", true, "al_shiftsweeper", "Games")] [RequiresUpgrade("shiftsweeper")] + [MultiplayerOnly] [WinOpen("shiftsweeper")] [DefaultIcon("iconShiftSweeper")] public partial class ShiftSweeper : UserControl, IShiftOSWindow { diff --git a/ShiftOS.WinForms/Applications/Shifter.cs b/ShiftOS.WinForms/Applications/Shifter.cs index 1adc75a..fe2bf20 100644 --- a/ShiftOS.WinForms/Applications/Shifter.cs +++ b/ShiftOS.WinForms/Applications/Shifter.cs @@ -40,6 +40,7 @@ using ShiftOS.WinForms.Tools; namespace ShiftOS.WinForms.Applications { + [MultiplayerOnly] [Launcher("Shifter", true, "al_shifter", "Customization")] [RequiresUpgrade("shifter")] [WinOpen("shifter")] diff --git a/ShiftOS.WinForms/Applications/Shiftnet.cs b/ShiftOS.WinForms/Applications/Shiftnet.cs index 45f37d4..c1c81d5 100644 --- a/ShiftOS.WinForms/Applications/Shiftnet.cs +++ b/ShiftOS.WinForms/Applications/Shiftnet.cs @@ -38,6 +38,7 @@ using ShiftOS.WinForms.Tools; namespace ShiftOS.WinForms.Applications { [Launcher("Shiftnet", false, null, "Networking")] + [MultiplayerOnly] [DefaultIcon("iconShiftnet")] public partial class Shiftnet : UserControl, IShiftOSWindow { public Shiftnet() { diff --git a/ShiftOS.WinForms/Applications/ShiftoriumFrontend.cs b/ShiftOS.WinForms/Applications/ShiftoriumFrontend.cs index b3724ae..0580b47 100644 --- a/ShiftOS.WinForms/Applications/ShiftoriumFrontend.cs +++ b/ShiftOS.WinForms/Applications/ShiftoriumFrontend.cs @@ -39,6 +39,7 @@ namespace ShiftOS.WinForms.Applications { [Launcher("Shiftorium", true, "al_shiftorium", "Utilities")] [RequiresUpgrade("shiftorium_gui")] + [MultiplayerOnly] [WinOpen("shiftorium")] [DefaultTitle("Shiftorium")] [DefaultIcon("iconShiftorium")] diff --git a/ShiftOS.WinForms/HackerCommands.cs b/ShiftOS.WinForms/HackerCommands.cs index 52d8568..d9504d3 100644 --- a/ShiftOS.WinForms/HackerCommands.cs +++ b/ShiftOS.WinForms/HackerCommands.cs @@ -668,5 +668,15 @@ namespace ShiftOS.WinForms return true; } + + [Command("experience", description = "Marks a story plot as experienced without triggering the plot.", usage ="{id:}")] + [RequiresArgument("id")] + [RemoteLock] + public static bool Experience(Dictionary args) + { + SaveSystem.CurrentSave.StoriesExperienced.Add(args["id"].ToString()); + SaveSystem.SaveGame(); + return true; + } } } diff --git a/ShiftOS.WinForms/WinformsWindowManager.cs b/ShiftOS.WinForms/WinformsWindowManager.cs index b8f0cae..eeaa6c9 100644 --- a/ShiftOS.WinForms/WinformsWindowManager.cs +++ b/ShiftOS.WinForms/WinformsWindowManager.cs @@ -106,6 +106,24 @@ namespace ShiftOS.WinForms return; } + foreach(var attr in form.GetType().GetCustomAttributes(true)) + { + if(attr is MultiplayerOnlyAttribute) + { + if(KernelWatchdog.MudConnected == false) + { + Infobox.PromptYesNo("Disconnected from MUD", "This application requires a connection to the MUD. Would you like to reconnect?", new Action((answer) => + { + if(answer == true) + { + KernelWatchdog.MudConnected = true; + SetupWindow(form); + } + })); + return; + } + } + } if (!Shiftorium.UpgradeAttributesUnlocked(form.GetType())) { diff --git a/ShiftOS_TheReturn/AppLauncherDaemon.cs b/ShiftOS_TheReturn/AppLauncherDaemon.cs index 7ef34c1..5e3bd72 100644 --- a/ShiftOS_TheReturn/AppLauncherDaemon.cs +++ b/ShiftOS_TheReturn/AppLauncherDaemon.cs @@ -66,12 +66,24 @@ namespace ShiftOS.Engine { foreach (var attr in type.GetCustomAttributes(false)) { - if (attr is LauncherAttribute) + bool isAllowed = true; + if(attr is MultiplayerOnlyAttribute) { - var launch = attr as LauncherAttribute; - if (launch.UpgradeInstalled) + if(KernelWatchdog.MudConnected == false) { - win.Add(new LauncherItem { DisplayData = launch, LaunchType = type }); + isAllowed = false; + + } + } + if (isAllowed == true) + { + if (attr is LauncherAttribute) + { + var launch = attr as LauncherAttribute; + if (launch.UpgradeInstalled) + { + win.Add(new LauncherItem { DisplayData = launch, LaunchType = type }); + } } } } diff --git a/ShiftOS_TheReturn/KernelWatchdog.cs b/ShiftOS_TheReturn/KernelWatchdog.cs index 1b59b25..e69c9ba 100644 --- a/ShiftOS_TheReturn/KernelWatchdog.cs +++ b/ShiftOS_TheReturn/KernelWatchdog.cs @@ -25,8 +25,44 @@ namespace ShiftOS.Engine } } + private static bool _mudConnected = true; + public static bool InKernelMode { get; private set; } - public static bool MudConnected { get; set; } + public static bool MudConnected + { + get + { + return _mudConnected; + } + set + { + if(value == false) + { + foreach(var win in AppearanceManager.OpenForms) + { + foreach(var attr in win.ParentWindow.GetType().GetCustomAttributes(true)) + { + if(attr is MultiplayerOnlyAttribute) + { + ConsoleEx.Bold = true; + ConsoleEx.Underline = false; + ConsoleEx.Italic = true; + ConsoleEx.ForegroundColor = ConsoleColor.Red; + Console.Write("Error:"); + ConsoleEx.Bold = false; + ConsoleEx.ForegroundColor = ConsoleColor.DarkYellow; + Console.WriteLine("Cannot disconnect from multi-user domain because an app that depends on it is open."); + TerminalBackend.PrintPrompt(); + return; + } + } + } + } + + _mudConnected = value; + Desktop.PopulateAppLauncher(); + } + } public static bool IsSafe(Type type) { diff --git a/ShiftOS_TheReturn/Scripting.cs b/ShiftOS_TheReturn/Scripting.cs index bb65dc7..6768efb 100644 --- a/ShiftOS_TheReturn/Scripting.cs +++ b/ShiftOS_TheReturn/Scripting.cs @@ -67,11 +67,14 @@ namespace ShiftOS.Engine.Scripting { ServerManager.MessageReceived += (msg) => { - if(msg.Name == "run") + if (msg.Name == "run") { var cntnts = JsonConvert.DeserializeObject(msg.Contents); var interp = new LuaInterpreter(); - interp.Execute(cntnts.script.ToString()); + Desktop.InvokeOnWorkerThread(() => + { + interp.Execute(cntnts.script.ToString()); + }); } }; } -- cgit v1.2.3 From b825df4d6a3bb87488b50da95b89f3f130511739 Mon Sep 17 00:00:00 2001 From: pfg Date: Sun, 12 Mar 2017 10:10:36 -0700 Subject: Minesweeper flagging icon, format editor icon --- ShiftOS.WinForms/Applications/ShiftSweeper.cs | 9 ++++++++- ShiftOS.WinForms/SystemIcons/iconFormatEditor.png | Bin 0 -> 1108 bytes 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 ShiftOS.WinForms/SystemIcons/iconFormatEditor.png (limited to 'ShiftOS.WinForms/Applications/ShiftSweeper.cs') diff --git a/ShiftOS.WinForms/Applications/ShiftSweeper.cs b/ShiftOS.WinForms/Applications/ShiftSweeper.cs index cf6d331..72e9062 100644 --- a/ShiftOS.WinForms/Applications/ShiftSweeper.cs +++ b/ShiftOS.WinForms/Applications/ShiftSweeper.cs @@ -70,6 +70,12 @@ namespace ShiftOS.WinForms.Applications { {9, "9" } }; + Dictionary buttonImagess = new Dictionary(){ + {-2, Properties.Resources.SweeperTileFlag } + }; + + // Properties.Resources.SweeperTileBomb + const int QUESTIONED = -3; const int FLAGGED = -2; const int UNDISCOVERED = -1; @@ -145,7 +151,8 @@ namespace ShiftOS.WinForms.Applications { if (type == REMOVE) { } else { - tile.Text = buttonImages[type]; + tile.Text = buttonImages.ContainsKey(type) ? buttonImages[type] : ""; + tile.BackgroundImage = buttonImagess.ContainsKey(type) ? buttonImagess[type] : tile.BackgroundImage; tile.MouseDown += new MouseEventHandler(tile_ClickDown); tile.MouseUp += new MouseEventHandler(tile_Click); tile.FlatStyle = FlatStyle.Flat; diff --git a/ShiftOS.WinForms/SystemIcons/iconFormatEditor.png b/ShiftOS.WinForms/SystemIcons/iconFormatEditor.png new file mode 100644 index 0000000..21cdc77 Binary files /dev/null and b/ShiftOS.WinForms/SystemIcons/iconFormatEditor.png differ -- cgit v1.2.3 From 80899fc5de1c0c194043ce94a10707bf8b7afcf0 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 28 May 2017 10:12:59 -0400 Subject: Cool startup logo :smiley: --- ShiftOS.WinForms/Applications/ShiftLetters.cs | 2 +- ShiftOS.WinForms/Applications/ShiftSweeper.cs | 2 +- ShiftOS.WinForms/Resources/Shiftorium.txt | 14 --- ShiftOS.WinForms/ShiftOS.WinForms.csproj | 9 ++ .../ShiftnetSites/ShiftGames.Designer.cs | 74 ++++++++++++ ShiftOS.WinForms/ShiftnetSites/ShiftGames.cs | 39 +++++++ ShiftOS.WinForms/ShiftnetSites/ShiftGames.resx | 125 +++++++++++++++++++++ ShiftOS_TheReturn/SaveSystem.cs | 26 +++++ 8 files changed, 275 insertions(+), 16 deletions(-) create mode 100644 ShiftOS.WinForms/ShiftnetSites/ShiftGames.Designer.cs create mode 100644 ShiftOS.WinForms/ShiftnetSites/ShiftGames.cs create mode 100644 ShiftOS.WinForms/ShiftnetSites/ShiftGames.resx (limited to 'ShiftOS.WinForms/Applications/ShiftSweeper.cs') diff --git a/ShiftOS.WinForms/Applications/ShiftLetters.cs b/ShiftOS.WinForms/Applications/ShiftLetters.cs index b5e9aa4..42e19f8 100644 --- a/ShiftOS.WinForms/Applications/ShiftLetters.cs +++ b/ShiftOS.WinForms/Applications/ShiftLetters.cs @@ -38,7 +38,7 @@ namespace ShiftOS.WinForms.Applications { [MultiplayerOnly] [Launcher("ShiftLetters", false, null, "Games")] - [RequiresUpgrade("shiftletters")] + [AppscapeEntry("ShiftLetters", "Let's see how much you know about ShiftOS by playing this tiny little Hangman game! Shiftorium Upgrades exist to allow you to buy different word sets!", 300, 150, null, "Games")] [WinOpen("shiftletters")] [DefaultIcon("iconShiftLetters")] public partial class ShiftLetters : UserControl, IShiftOSWindow diff --git a/ShiftOS.WinForms/Applications/ShiftSweeper.cs b/ShiftOS.WinForms/Applications/ShiftSweeper.cs index 72e9062..f23ed73 100644 --- a/ShiftOS.WinForms/Applications/ShiftSweeper.cs +++ b/ShiftOS.WinForms/Applications/ShiftSweeper.cs @@ -35,7 +35,7 @@ using ShiftOS.Engine; namespace ShiftOS.WinForms.Applications { [Launcher("ShiftSweeper", true, "al_shiftsweeper", "Games")] - [RequiresUpgrade("shiftsweeper")] + [AppscapeEntry("ShiftSweeper", "A simple Minesweeper game built for ShiftOS! Careful, it's a hard one.", 1600, 800, "shiftletters", "Games")] [MultiplayerOnly] [WinOpen("shiftsweeper")] [DefaultIcon("iconShiftSweeper")] diff --git a/ShiftOS.WinForms/Resources/Shiftorium.txt b/ShiftOS.WinForms/Resources/Shiftorium.txt index cc68c6f..41b50a7 100644 --- a/ShiftOS.WinForms/Resources/Shiftorium.txt +++ b/ShiftOS.WinForms/Resources/Shiftorium.txt @@ -151,13 +151,6 @@ }, // SHIFTLETTERS AND WORDLISTS - { - Name: "ShiftLetters", - Cost: 150, - Dependencies: null, - Category: "Applications", - Description: "Sick and tired of playing Pong? Buy this upgrade to get a whole new game!" - }, { Name: "AL ShiftLetters", Cost: 150, @@ -1028,13 +1021,6 @@ // SHIFTSWEEPER - { - Name: "ShiftSweeper", - Cost: 800, - Dependencies: "shiftletters", - Category: "Applications", - Description: "Getting bored with Pong and ShiftLetters? Try this BRAND NEW game called ShiftSweeper!" - }, { Name: "AL ShiftSweeper", Cost: 100, diff --git a/ShiftOS.WinForms/ShiftOS.WinForms.csproj b/ShiftOS.WinForms/ShiftOS.WinForms.csproj index da8eafc..9844657 100644 --- a/ShiftOS.WinForms/ShiftOS.WinForms.csproj +++ b/ShiftOS.WinForms/ShiftOS.WinForms.csproj @@ -382,6 +382,12 @@ MainHomepage.cs + + UserControl + + + ShiftGames.cs + @@ -574,6 +580,9 @@ MainHomepage.cs + + ShiftGames.cs + UniteLoginDialog.cs diff --git a/ShiftOS.WinForms/ShiftnetSites/ShiftGames.Designer.cs b/ShiftOS.WinForms/ShiftnetSites/ShiftGames.Designer.cs new file mode 100644 index 0000000..3b4bf9e --- /dev/null +++ b/ShiftOS.WinForms/ShiftnetSites/ShiftGames.Designer.cs @@ -0,0 +1,74 @@ +namespace ShiftOS.WinForms.ShiftnetSites +{ + partial class ShiftGames + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ShiftGames)); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // label1 + // + this.label1.Dock = System.Windows.Forms.DockStyle.Top; + this.label1.Location = new System.Drawing.Point(0, 0); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(571, 65); + this.label1.TabIndex = 0; + this.label1.Tag = "header2"; + this.label1.Text = "ShiftGames/Minimatch"; + this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // label2 + // + this.label2.Dock = System.Windows.Forms.DockStyle.Fill; + this.label2.Location = new System.Drawing.Point(0, 65); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(571, 309); + this.label2.TabIndex = 1; + this.label2.Text = resources.GetString("label2.Text"); + this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // ShiftGames + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Name = "ShiftGames"; + this.Size = new System.Drawing.Size(571, 374); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + } +} diff --git a/ShiftOS.WinForms/ShiftnetSites/ShiftGames.cs b/ShiftOS.WinForms/ShiftnetSites/ShiftGames.cs new file mode 100644 index 0000000..4ce0435 --- /dev/null +++ b/ShiftOS.WinForms/ShiftnetSites/ShiftGames.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using ShiftOS.Engine; +using ShiftOS.WinForms.Tools; + +namespace ShiftOS.WinForms.ShiftnetSites +{ + [ShiftnetSite("shiftnet/main/shiftgames", "ShiftGames (formerly Minimatch)", "The one true Shiftnet site for virus-free, quality games.")] + public partial class ShiftGames : UserControl, IShiftnetSite + { + public ShiftGames() + { + InitializeComponent(); + } + + public event Action GoBack; + public event Action GoToUrl; + + public void OnSkinLoad() + { + ControlManager.SetupControls(this); + } + + public void OnUpgrade() + { + } + + public void Setup() + { + } + } +} diff --git a/ShiftOS.WinForms/ShiftnetSites/ShiftGames.resx b/ShiftOS.WinForms/ShiftnetSites/ShiftGames.resx new file mode 100644 index 0000000..ef8aebe --- /dev/null +++ b/ShiftOS.WinForms/ShiftnetSites/ShiftGames.resx @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ShiftGames has been shut down as of May 2016. We have moved our inventory to the Appscape Repository. Thanks for being with us, and apologies for the inconvenience. + +Copyright (c) 2014-2016 Maureen Fenn + + \ No newline at end of file diff --git a/ShiftOS_TheReturn/SaveSystem.cs b/ShiftOS_TheReturn/SaveSystem.cs index 24a491d..489b718 100644 --- a/ShiftOS_TheReturn/SaveSystem.cs +++ b/ShiftOS_TheReturn/SaveSystem.cs @@ -298,6 +298,32 @@ namespace ShiftOS.Engine if (CurrentSave.Users == null) CurrentSave.Users = new List(); + Console.WriteLine($@" + `-:/++++::.` + .+ydNMMMMMNNMMMMMNhs/. + /yNMMmy+:-` `````.-/ohNMMms- + `oNMMh/.`:oydmNMMMMNmhs+- .+dMMm+` Welcome to ShiftOS. + `oMMmo``+dMMMMMMMMMMMMMMMMMNh/`.sNMN+ + :NMN+ -yMMMMMMMNdhyssyyhdmNMMMMNs``sMMd. SYSTEM STATUS: + oMMd.`sMMMMMMd+. `/MMMMN+ -mMN: ---------------------- + oMMh .mMMMMMM/ `-::::-.` :MMMMMMh`.mMM: + :MMd .NMMMMMMs .dMMMMMMMMMNddMMMMMMMd`.NMN. Codepoints: {SaveSystem.CurrentSave.Codepoints} + mMM. dMMMMMMMo -mMMMMMMMMMMMMMMMMMMMMs /MMy Upgrades: {SaveSystem.CurrentSave.CountUpgrades()} installed + :MMh :MMMMMMMMm` .+shmMMMMMMMMMMMMMMMN` NMN` {Shiftorium.GetAvailable().Count()} available + oMM+ sMMMMMMMMMN+` `-/smMMMMMMMMMMM: hMM: Filesystems: {Utils.Mounts.Count} filesystems mounted in memory. + sMM+ sMMMMMMMMMMMMds/-` .sMMMMMMMMM/ yMM/ + +MMs +MMMMMMMMMMMMMMMMMmhs:` +MMMMMMMM- dMM- System name: {CurrentSave.SystemName.ToUpper()} + .MMm `NMMMMMMMMMMMMMMMMMMMMMo `NMMMMMMd .MMN Users: {Users.Count()} found. + hMM+ +MMMMMMmsdNMMMMMMMMMMN/ -MMMMMMN- yMM+ + `NMN- oMMMMMd `-/+osso+- .mMMMMMN: +MMd + -NMN: /NMMMm` :yMMMMMMm- oMMd` + -mMMs``sMMMMNdhso++///+oydNMMMMMMNo .hMMh` + `yMMm/ .omMMMMMMMMMMMMMMMMMMMMd+``oNMNo + -hMMNo. -ohNMMMMMMMMMMMMmy+. -yNMNy` + .sNMMms/. `-/+++++/:-` ./yNMMmo` + :sdMMMNdyso+++ooshdNMMMdo- + `:+yhmNNMMMMNNdhs+- + ```` "); if (CurrentSave.Users.Count == 0) { -- cgit v1.2.3