diff options
| author | RogueAI42 <[email protected]> | 2017-06-25 16:34:56 +1000 |
|---|---|---|
| committer | RogueAI42 <[email protected]> | 2017-06-25 16:34:56 +1000 |
| commit | cd170687a5b15763e688f10a8d9bb478690dc2bd (patch) | |
| tree | b80d808d7a5d4eb674a5876a769c90aa80ada007 /ShiftOS.WinForms/Applications | |
| parent | 255ad0993d4334e306eb5475cee2cf82778dcecd (diff) | |
| download | shiftos_thereturn-cd170687a5b15763e688f10a8d9bb478690dc2bd.tar.gz shiftos_thereturn-cd170687a5b15763e688f10a8d9bb478690dc2bd.tar.bz2 shiftos_thereturn-cd170687a5b15763e688f10a8d9bb478690dc2bd.zip | |
ButtonMaster: new game for Appscape based on the Druaga1 video
Diffstat (limited to 'ShiftOS.WinForms/Applications')
| -rw-r--r-- | ShiftOS.WinForms/Applications/ButtonMaster.Designer.cs | 181 | ||||
| -rw-r--r-- | ShiftOS.WinForms/Applications/ButtonMaster.cs | 176 | ||||
| -rw-r--r-- | ShiftOS.WinForms/Applications/ButtonMaster.resx | 130 |
3 files changed, 487 insertions, 0 deletions
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 + { + /// <summary> + /// Required designer variable. + /// </summary> + private System.ComponentModel.IContainer components = null; + + /// <summary> + /// Clean up any resources being used. + /// </summary> + /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// <summary> + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// </summary> + 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 @@ +<?xml version="1.0" encoding="utf-8"?> +<root> + <!-- + Microsoft ResX Schema + + Version 2.0 + + The primary goals of this format is to allow a simple XML format + that is mostly human readable. The generation and parsing of the + various data types are done through the TypeConverter classes + associated with the data types. + + Example: + + ... ado.net/XML headers & schema ... + <resheader name="resmimetype">text/microsoft-resx</resheader> + <resheader name="version">2.0</resheader> + <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> + <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> + <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> + <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> + <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> + <value>[base64 mime encoded serialized .NET Framework object]</value> + </data> + <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> + <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> + <comment>This is a comment</comment> + </data> + + There are any number of "resheader" rows that contain simple + name/value pairs. + + Each data row contains a name, and value. The row also contains a + type or mimetype. Type corresponds to a .NET class that support + text/value conversion through the TypeConverter architecture. + Classes that don't support this are serialized and stored with the + mimetype set. + + The mimetype is used for serialized objects, and tells the + ResXResourceReader how to depersist the object. This is currently not + extensible. For a given mimetype the value must be set accordingly: + + Note - application/x-microsoft.net.object.binary.base64 is the format + that the ResXResourceWriter will generate, however the reader can + read any of the formats listed below. + + mimetype: application/x-microsoft.net.object.binary.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.soap.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Soap.SoapFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.bytearray.base64 + value : The object must be serialized into a byte array + : using a System.ComponentModel.TypeConverter + : and then encoded with base64 encoding. + --> + <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> + <xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> + <xsd:element name="root" msdata:IsDataSet="true"> + <xsd:complexType> + <xsd:choice maxOccurs="unbounded"> + <xsd:element name="metadata"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" /> + </xsd:sequence> + <xsd:attribute name="name" use="required" type="xsd:string" /> + <xsd:attribute name="type" type="xsd:string" /> + <xsd:attribute name="mimetype" type="xsd:string" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="assembly"> + <xsd:complexType> + <xsd:attribute name="alias" type="xsd:string" /> + <xsd:attribute name="name" type="xsd:string" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="data"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> + <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> + <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="resheader"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" /> + </xsd:complexType> + </xsd:element> + </xsd:choice> + </xsd:complexType> + </xsd:element> + </xsd:schema> + <resheader name="resmimetype"> + <value>text/microsoft-resx</value> + </resheader> + <resheader name="version"> + <value>2.0</value> + </resheader> + <resheader name="reader"> + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <resheader name="writer"> + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <data name="desclabel.Text" xml:space="preserve"> + <value>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?</value> + </data> +</root>
\ No newline at end of file |
