diff options
| author | Michael <[email protected]> | 2017-06-28 16:33:07 -0400 |
|---|---|---|
| committer | Michael <[email protected]> | 2017-06-28 16:33:07 -0400 |
| commit | 27264a559d7fd40a0c2bc393a5e150c17da1539d (patch) | |
| tree | ed02811fbd109b1637cd9b6a818af3eb4ce46e59 /ShiftOS.WinForms/Viruses | |
| parent | 6cdb8cb0253230f6f845afb549517c5c3f12d2d1 (diff) | |
| download | shiftos_thereturn-27264a559d7fd40a0c2bc393a5e150c17da1539d.tar.gz shiftos_thereturn-27264a559d7fd40a0c2bc393a5e150c17da1539d.tar.bz2 shiftos_thereturn-27264a559d7fd40a0c2bc393a5e150c17da1539d.zip | |
Basics of the virus system
Diffstat (limited to 'ShiftOS.WinForms/Viruses')
| -rw-r--r-- | ShiftOS.WinForms/Viruses/WindowsEverywhere.cs | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/ShiftOS.WinForms/Viruses/WindowsEverywhere.cs b/ShiftOS.WinForms/Viruses/WindowsEverywhere.cs new file mode 100644 index 0000000..df73d58 --- /dev/null +++ b/ShiftOS.WinForms/Viruses/WindowsEverywhere.cs @@ -0,0 +1,83 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ShiftOS.Engine; + +namespace ShiftOS.WinForms.Viruses +{ + [Virus("windows_everywhere", "Windows Everywhere", "Makes the windows dance around the screen if the user has the WM Free Placement upgrade. Speed depends on threatlevel.")] + [RequiresUpgrade("wm_free_placement")] + public class WindowsEverywhere : IVirus + { + private System.Windows.Forms.Timer timer = null; + private int ThreatLevel = 1; + private Dictionary<string, System.Drawing.Point> Velocities = null; + + + public void Infect(int threatlevel) + { + Velocities = new Dictionary<string, System.Drawing.Point>(); + ThreatLevel = threatlevel; + timer = new System.Windows.Forms.Timer(); + timer.Interval = 50; + timer.Tick += (o, a) => + { + foreach (var win in AppearanceManager.OpenForms) + { + var border = (win as WindowBorder); + var loc = border.Location; + var velocity = new System.Drawing.Point(1, 1); + string vKey = border.GetType().Name + "_" + border.GetHashCode(); + if (!Velocities.ContainsKey(vKey)) + { + Velocities.Add(vKey, velocity); + } + else + { + velocity = Velocities[vKey]; + } + + //Calculate proper velocity. + if (border.Top <= 0) + { + velocity.Y = 1; + } + if (border.Top + border.Height >= System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height) + { + velocity.Y = -1; + } + if (border.Left <= 0) + { + velocity.X = 1; + } + if (border.Left + border.Width >= System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width) + { + velocity.X = -1; + } + //save velocity in memory. + Velocities[vKey] = velocity; + //convert using threatlevel + + var velocityX = velocity.X * (threatlevel * 4); + var velocityY = velocity.Y * (threatlevel * 4); + + loc.X += velocityX; + loc.Y += velocityY; + + border.Location = loc; + } + }; + timer.Start(); + } + + public void Disinfect() + { + timer.Stop(); + Velocities.Clear(); + ThreatLevel = 0; + timer = null; + } + } +} |
