From cd170687a5b15763e688f10a8d9bb478690dc2bd Mon Sep 17 00:00:00 2001 From: RogueAI42 Date: Sun, 25 Jun 2017 16:34:56 +1000 Subject: [PATCH] ButtonMaster: new game for Appscape based on the Druaga1 video --- .../Applications/ButtonMaster.Designer.cs | 181 ++++++++++++++++++ ShiftOS.WinForms/Applications/ButtonMaster.cs | 176 +++++++++++++++++ .../Applications/ButtonMaster.resx | 130 +++++++++++++ .../Properties/Resources.Designer.cs | 30 ++- ShiftOS.WinForms/Properties/Resources.resx | 3 + ShiftOS.WinForms/ShiftOS.WinForms.csproj | 10 + 6 files changed, 522 insertions(+), 8 deletions(-) create mode 100644 ShiftOS.WinForms/Applications/ButtonMaster.Designer.cs create mode 100644 ShiftOS.WinForms/Applications/ButtonMaster.cs create mode 100644 ShiftOS.WinForms/Applications/ButtonMaster.resx diff --git a/ShiftOS.WinForms/Applications/ButtonMaster.Designer.cs b/ShiftOS.WinForms/Applications/ButtonMaster.Designer.cs new file mode 100644 index 0000000..0ba9b96 --- /dev/null +++ b/ShiftOS.WinForms/Applications/ButtonMaster.Designer.cs @@ -0,0 +1,181 @@ +namespace ShiftOS.WinForms.Applications +{ + partial class ButtonMaster + { + /// + /// 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(ButtonMaster)); + this.startpnl = new System.Windows.Forms.Panel(); + this.quitbtn = new System.Windows.Forms.Button(); + this.playbtn = new System.Windows.Forms.Button(); + this.difficultysel = new System.Windows.Forms.ListBox(); + this.label3 = new System.Windows.Forms.Label(); + this.desclabel = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.scorecounter = new System.Windows.Forms.Label(); + this.startpnl.SuspendLayout(); + this.SuspendLayout(); + // + // startpnl + // + this.startpnl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.startpnl.Controls.Add(this.quitbtn); + this.startpnl.Controls.Add(this.playbtn); + this.startpnl.Controls.Add(this.difficultysel); + this.startpnl.Controls.Add(this.label3); + this.startpnl.Controls.Add(this.desclabel); + this.startpnl.Controls.Add(this.label2); + this.startpnl.Controls.Add(this.label1); + this.startpnl.Location = new System.Drawing.Point(27, 31); + this.startpnl.Name = "startpnl"; + this.startpnl.Size = new System.Drawing.Size(580, 409); + this.startpnl.TabIndex = 0; + // + // quitbtn + // + this.quitbtn.Anchor = System.Windows.Forms.AnchorStyles.Top; + this.quitbtn.Location = new System.Drawing.Point(291, 303); + this.quitbtn.Name = "quitbtn"; + this.quitbtn.Size = new System.Drawing.Size(58, 23); + this.quitbtn.TabIndex = 7; + this.quitbtn.Text = "Quit"; + this.quitbtn.UseVisualStyleBackColor = true; + this.quitbtn.Click += new System.EventHandler(this.quitbtn_Click); + // + // playbtn + // + this.playbtn.Anchor = System.Windows.Forms.AnchorStyles.Top; + this.playbtn.Location = new System.Drawing.Point(229, 303); + this.playbtn.Name = "playbtn"; + this.playbtn.Size = new System.Drawing.Size(56, 23); + this.playbtn.TabIndex = 6; + this.playbtn.Text = "Play"; + this.playbtn.UseVisualStyleBackColor = true; + this.playbtn.Click += new System.EventHandler(this.playbtn_Click); + // + // difficultysel + // + this.difficultysel.Anchor = System.Windows.Forms.AnchorStyles.Top; + this.difficultysel.FormattingEnabled = true; + this.difficultysel.Location = new System.Drawing.Point(152, 202); + this.difficultysel.Name = "difficultysel"; + this.difficultysel.Size = new System.Drawing.Size(276, 95); + this.difficultysel.TabIndex = 5; + // + // label3 + // + this.label3.Anchor = System.Windows.Forms.AnchorStyles.Top; + this.label3.AutoSize = true; + this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label3.Location = new System.Drawing.Point(243, 179); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(79, 20); + this.label3.TabIndex = 4; + this.label3.Tag = "header2"; + this.label3.Text = "Difficulty"; + // + // desclabel + // + this.desclabel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.desclabel.Location = new System.Drawing.Point(3, 67); + this.desclabel.Name = "desclabel"; + this.desclabel.Size = new System.Drawing.Size(577, 112); + this.desclabel.TabIndex = 2; + this.desclabel.Tag = ""; + this.desclabel.Text = resources.GetString("desclabel.Text"); + this.desclabel.TextAlign = System.Drawing.ContentAlignment.TopCenter; + // + // label2 + // + this.label2.Anchor = System.Windows.Forms.AnchorStyles.Top; + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(235, 37); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(105, 13); + this.label2.TabIndex = 1; + this.label2.Text = "by Appscape Games"; + // + // label1 + // + this.label1.Anchor = System.Windows.Forms.AnchorStyles.Top; + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label1.Location = new System.Drawing.Point(211, 12); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(152, 25); + this.label1.TabIndex = 0; + this.label1.Tag = "header1"; + this.label1.Text = "ButtonMaster"; + // + // scorecounter + // + this.scorecounter.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.scorecounter.BackColor = System.Drawing.Color.Transparent; + this.scorecounter.Font = new System.Drawing.Font("Courier New", 15.75F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.scorecounter.ForeColor = System.Drawing.Color.Red; + this.scorecounter.Location = new System.Drawing.Point(548, 454); + this.scorecounter.Name = "scorecounter"; + this.scorecounter.Size = new System.Drawing.Size(92, 26); + this.scorecounter.TabIndex = 1; + this.scorecounter.Tag = "keepfont keepfg keepbg"; + this.scorecounter.Text = "score"; + this.scorecounter.TextAlign = System.Drawing.ContentAlignment.BottomRight; + this.scorecounter.Visible = false; + // + // ButtonMaster + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackgroundImage = global::ShiftOS.WinForms.Properties.Resources.BlueBlueVerticalGradient; + this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.Controls.Add(this.scorecounter); + this.Controls.Add(this.startpnl); + this.Name = "ButtonMaster"; + this.Size = new System.Drawing.Size(640, 480); + this.startpnl.ResumeLayout(false); + this.startpnl.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Panel startpnl; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label desclabel; + private System.Windows.Forms.ListBox difficultysel; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Button playbtn; + private System.Windows.Forms.Button quitbtn; + private System.Windows.Forms.Label scorecounter; + } +} diff --git a/ShiftOS.WinForms/Applications/ButtonMaster.cs b/ShiftOS.WinForms/Applications/ButtonMaster.cs new file mode 100644 index 0000000..722bb14 --- /dev/null +++ b/ShiftOS.WinForms/Applications/ButtonMaster.cs @@ -0,0 +1,176 @@ +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 +{ + // Behold... The ShiftOS program that doesn't use threading. + [WinOpen("buttonmaster")] + [Launcher("Button Master", false, "", "Games")] + [AppscapeEntry("buttonmaster", "ButtonMaster", "Can you click all the buttons in 60 seconds?", 300, 10000)] + public partial class ButtonMaster : UserControl, IShiftOSWindow + { + public ushort Buttons; + public double Codepoints, Loss; + private ulong RoundedCodepoints { get { return (ulong) Math.Round(Codepoints); } } + public Timer clock = new Timer(); + private ButtonObject[] ButtonObjects; + private static ButtonMasterDifficulty[] difficulties = new ButtonMasterDifficulty[] + { + new ButtonMasterDifficulty("Easy", 24, 500), + new ButtonMasterDifficulty("Medium", 48, 1000), + new ButtonMasterDifficulty("Hard", 100, 2000), + new ButtonMasterDifficulty("Super Hard", 500, 10000) + }; + public ButtonMaster() + { + InitializeComponent(); + difficultysel.Items.AddRange(difficulties); + difficultysel.SelectedIndex = 0; + clock.Interval = 20; + clock.Tick += gameloop; + } + + public void OnLoad() + { + } + + public void OnSkinLoad() + { + + } + + public bool OnUnload() + { + return true; + } + + public void OnUpgrade() + { + + } + + private void quitbtn_Click(object sender, EventArgs e) + { + AppearanceManager.Close(this); + } + + private void playbtn_Click(object sender, EventArgs e) + { + var difficulty = difficultysel.SelectedItem as ButtonMasterDifficulty; + Buttons = difficulty.Buttons; + Codepoints = difficulty.Codepoints; + Loss = difficulty.Codepoints / 3000.0; + startpnl.Hide(); + scorecounter.Text = difficulty.Codepoints.ToString(); + scorecounter.Show(); + ButtonObjects = new ButtonObject[Buttons]; + for (ushort i = 0; i < Buttons; i++) + ButtonObjects[i] = new ButtonObject(this); + Controls.AddRange(ButtonObjects.Select(b => b.ctl).ToArray()); + clock.Start(); + } + + private void StopGame(string text) + { + desclabel.Text = text; + startpnl.Show(); + clock.Stop(); + scorecounter.Hide(); + foreach (var b in ButtonObjects) + { + clock.Tick -= b.move; + Controls.Remove(b.ctl); + } + } + + private void gameloop(object sender, EventArgs e) + { + if (Codepoints <= 0) + { + Codepoints = 0; + string text = String.Format("You lost. There were {0} buttons to go.", Buttons); + if (difficultysel.SelectedIndex > 0) + text += " Try an easier difficulty?"; + StopGame(text); + } + else if (Buttons <= 0) + { + SaveSystem.CurrentSave.Codepoints += RoundedCodepoints; + string text = String.Format("You won! {0} Codepoints have been transferred to your system.", RoundedCodepoints); + StopGame(text); + } + else + { + Codepoints -= Loss; + scorecounter.Text = RoundedCodepoints.ToString(); + } + } + } + public class ButtonMasterDifficulty + { + public string Name { get; private set; } + public ushort Buttons { get; private set; } + public uint Codepoints { get; private set; } + public string Display { get; private set; } + public override string ToString() + { + return Display; + } + public ButtonMasterDifficulty(string in_Name, ushort in_Buttons, uint in_Codepoints) + { + Name = in_Name; + Buttons = in_Buttons; + Codepoints = in_Codepoints; + Display = String.Format("{0} ({1} Buttons, {2} Codepoints)", Name, Buttons, Codepoints); + } + } + + public class ButtonObject + { + public Button ctl; + public sbyte xspeed, yspeed; + public ButtonMaster parent; + private static Random rnd = new Random(); + public void move(object sender, EventArgs e) + { + ctl.Top += yspeed; + if (ctl.Top < 0 || ctl.Bottom > parent.Height) + yspeed = (sbyte)(Math.Abs(yspeed) * -(ctl.Top / Math.Abs(ctl.Top))); // Change the sign of yspeed to be the opposite of that of ctl.Top + ctl.Left += xspeed; + if (ctl.Left < 0 || ctl.Right > parent.Width) + xspeed = (sbyte)(Math.Abs(xspeed) * -(ctl.Left / Math.Abs(ctl.Left))); + } + public void click(object sender, EventArgs e) + { + parent.Buttons--; + ctl.Hide(); + parent.clock.Tick -= move; + } + public ButtonObject(ButtonMaster in_parent) + { + xspeed = (sbyte) rnd.Next(10, 20); + yspeed = (sbyte) rnd.Next(10, 20); + parent = in_parent; + parent.clock.Tick += move; + ctl = new Button(); + ctl.Click += click; + ctl.Top = rnd.Next(parent.Height); + ctl.Left = rnd.Next(parent.Width); + ctl.Width = 75; + ctl.Height = 23; + ctl.Text = "Click"; + // Time to invoke a private method using reflection. What could possibly go wrong? + // This stops the player from just holding down space to beat the level. + typeof(Button).GetMethod("SetStyle", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).Invoke(ctl, new object[] { ControlStyles.Selectable, false }); + } + + } +} diff --git a/ShiftOS.WinForms/Applications/ButtonMaster.resx b/ShiftOS.WinForms/Applications/ButtonMaster.resx new file mode 100644 index 0000000..6742cee --- /dev/null +++ b/ShiftOS.WinForms/Applications/ButtonMaster.resx @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + In the game of ButtonMaster, dozens of buttons bounce +around the window. Your task is to click all of them in +60 seconds. The quicker you pull it off, the more points +you earn. + +In this special ShiftOS version, any points you earn are +added to your Codepoints balance at the end of the game. +So, what are you waiting for? + + \ No newline at end of file diff --git a/ShiftOS.WinForms/Properties/Resources.Designer.cs b/ShiftOS.WinForms/Properties/Resources.Designer.cs index dd84e94..b8012c6 100644 --- a/ShiftOS.WinForms/Properties/Resources.Designer.cs +++ b/ShiftOS.WinForms/Properties/Resources.Designer.cs @@ -359,6 +359,16 @@ namespace ShiftOS.WinForms.Properties { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap BlueBlueVerticalGradient { + get { + object obj = ResourceManager.GetObject("BlueBlueVerticalGradient", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Byte[]. /// @@ -1121,7 +1131,8 @@ namespace ShiftOS.WinForms.Properties { /// "ReadAccessToLowUsers": false, /// "permissions": 0 /// }, - /// [rest of string was truncated]";. + /// { + /// "Name" [rest of string was truncated]";. /// internal static string PebcakDevelFS { get { @@ -1155,7 +1166,7 @@ namespace ShiftOS.WinForms.Properties { /// Name: "NetXtreme Hyper Edition", /// CostPerMonth: 150, /// DownloadSpeed: 524288, //512 kb/s - /// Description: "It's time to supercharge your Shift [rest of string was truncated]";. + /// Description: "It's time to supercharge your Shiftnet experience. [rest of string was truncated]";. /// internal static string ShiftnetServices { get { @@ -1177,7 +1188,8 @@ namespace ShiftOS.WinForms.Properties { /// Name: "Icon Manager", /// Cost: 450, /// Description: "This tool allows you to add and edit application icons within ShiftOS for the small prive of 450 Codepoints!", - /// Dependencies: "skinning [rest of string was truncated]";. + /// Dependencies: "skinning", + /// Category [rest of string was truncated]";. /// internal static string Shiftorium { get { @@ -1187,7 +1199,7 @@ namespace ShiftOS.WinForms.Properties { /// /// Looks up a localized string similar to {\rtf1\adeflang1025\ansi\ansicpg1252\uc1\adeff0\deff0\stshfdbch31505\stshfloch31506\stshfhich31506\stshfbi0\deflang1033\deflangfe1033\themelang1033\themelangfe0\themelangcs0{\fonttbl{\f0\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f0\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;} - ///{\f37\fbidi \fswiss\fcharset0\fprq2{\*\panose 020f0502020204030204}Calibri;}{\f38\fbidi \fswiss\fcharset0\fprq2{\*\panose 020f0302020204030204}Calibri Light;}{\fl [rest of string was truncated]";. + ///{\f37\fbidi \fswiss\fcharset0\fprq2{\*\panose 020f0502020204030204}Calibri;}{\f38\fbidi \fswiss\fcharset0\fprq2{\*\panose 020f0302020204030204}Calibri Light;}{\flo [rest of string was truncated]";. /// internal static string ShiftOS { get { @@ -1336,7 +1348,8 @@ namespace ShiftOS.WinForms.Properties { ///Eine kurze Erklärung wie du das Terminal benutzt lautet wiefolgt. Du kannst das command 'sos.help' benutzen um eine Liste aller commands aufzurufen. Schreib es ///einfach in das Terminal und drücke <enter> um alle commands anzuzeigen. /// - ///Commands können mit argumenten versehen werden, indem du ein key-value Paar in einem {} Block hinter dem command angibst. Zum Be [rest of string was truncated]";. + ///Commands können mit argumenten versehen werden, indem du ein key-value Paar in einem {} Block hinter dem command angibst. Zum Beispiel: + /// [rest of string was truncated]";. /// internal static string strings_de { get { @@ -1361,7 +1374,7 @@ namespace ShiftOS.WinForms.Properties { /// "{GEN_WELCOME}": "Welcome to ShiftOS.", /// "{GEN_SYSTEMNAME}": "System name", /// "{GEN_PASSWORD}": "Password", - /// "{GEN_LPROMPT [rest of string was truncated]";. + /// "{GEN_LPROMPT}": "%sysname lo [rest of string was truncated]";. /// internal static string strings_en { get { @@ -1385,7 +1398,8 @@ namespace ShiftOS.WinForms.Properties { /// "{GEN_CURRENTPROCESSES}": "Les procèdures actuelles", /// "{GEN_WELCOME}": "Bienvenue au ShiftOS.", /// "{GEN_SYSTEMNAME}": "Nom de système", - /// "{GEN_PASSWORD}": "Mot de [rest of string was truncated]";. + /// "{GEN_PASSWORD}": "Mot de passe", + /// "{GEN [rest of string was truncated]";. /// internal static string strings_fr { get { @@ -1573,7 +1587,7 @@ namespace ShiftOS.WinForms.Properties { /// "Before you can begin with ShiftOS, you'll need to know a few things about it.", /// "One: Terminal command syntax.", /// "Inside ShiftOS, the bulk of your time is going to be spent within the Terminal.", - /// "The Terminal is an application that starts up when you turn on your computer. It allows you to execute system commands, ope [rest of string was truncated]";. + /// "The Terminal is an application that starts up when you turn on your computer. It allows you to execute system commands, open program [rest of string was truncated]";. /// internal static string sys_shiftoriumstory { get { diff --git a/ShiftOS.WinForms/Properties/Resources.resx b/ShiftOS.WinForms/Properties/Resources.resx index 07cf941..447bbb0 100644 --- a/ShiftOS.WinForms/Properties/Resources.resx +++ b/ShiftOS.WinForms/Properties/Resources.resx @@ -34624,4 +34624,7 @@ ..\Resources\PebcakDevelFS.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 + + ..\Resources\BlueBlueVerticalGradient.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/ShiftOS.WinForms/ShiftOS.WinForms.csproj b/ShiftOS.WinForms/ShiftOS.WinForms.csproj index 570d049..43bd04b 100644 --- a/ShiftOS.WinForms/ShiftOS.WinForms.csproj +++ b/ShiftOS.WinForms/ShiftOS.WinForms.csproj @@ -71,6 +71,12 @@ About.cs + + UserControl + + + ButtonMaster.cs + UserControl @@ -483,6 +489,9 @@ About.cs + + ButtonMaster.cs + Clock.cs @@ -875,6 +884,7 @@ +