public static void SpawnVirus() { string type = ""; if (UiComponents.Viruses.Count < 9) { type = VirusSpawnOrder[SpawnOrderIteration]; SpawnOrderIteration++; if (SpawnOrderIteration > VirusSpawnOrder.Count - 1) { SpawnOrderIteration = 0; } } if (type.Equals("nv")) { var normalV = new NormalVirus(); } if (type.Equals("sv")) { var shieldedV = new ShieldedVirus(); ((ISupportInitialize)(shieldedV)).BeginInit(); shieldedV.MouseClick += new MouseEventHandler(Game.instance.MouseClickShootBullet); shieldedV.BackColor = Color.Transparent; shieldedV.Parent = Game.instance.pbBackGround; shieldedV.DoubleBuffered = true; UiComponents.AddVirus(shieldedV); ((ISupportInitialize)(shieldedV)).EndInit(); } if (type.Equals("av")) { var aggroV = new AggroVirus(); ((ISupportInitialize)(aggroV)).BeginInit(); aggroV.MouseClick += new MouseEventHandler(Game.instance.MouseClickShootBullet); aggroV.BackColor = Color.Transparent; aggroV.Parent = Game.instance.pbBackGround; aggroV.DoubleBuffered = true; UiComponents.AddVirus(aggroV); ((ISupportInitialize)(aggroV)).EndInit(); } if (type.Equals("tv")) { var teleporterV = new TeleporterVirus(); ((ISupportInitialize)(teleporterV)).BeginInit(); teleporterV.MouseClick += new MouseEventHandler(Game.instance.MouseClickShootBullet); teleporterV.BackColor = Color.Transparent; teleporterV.Parent = Game.instance.pbBackGround; teleporterV.DoubleBuffered = true; UiComponents.AddVirus(teleporterV); ((ISupportInitialize)(teleporterV)).EndInit(); } if (DateTime.Now >= Game.instance.MutatedVirusSpawnTimer) { var mutatedV = new MutatedVirus(); ((ISupportInitialize)(mutatedV)).BeginInit(); mutatedV.MouseClick += new MouseEventHandler(Game.instance.MouseClickShootBullet); mutatedV.BackColor = Color.Transparent; mutatedV.Parent = Game.instance.pbBackGround; mutatedV.DoubleBuffered = true; UiComponents.AddVirus(mutatedV); ((ISupportInitialize)(mutatedV)).EndInit(); Game.instance.MutatedVirusSpawnTimer = Game.instance.MutatedVirusSpawnTimer.AddSeconds(25); } if (type.Equals("dv")) { var dividerV = new DividerVirus(); ((ISupportInitialize)(dividerV)).BeginInit(); dividerV.MouseClick += new MouseEventHandler(Game.instance.MouseClickShootBullet); dividerV.BackColor = Color.Transparent; dividerV.Parent = Game.instance.pbBackGround; dividerV.DoubleBuffered = true; UiComponents.AddVirus(dividerV); ((ISupportInitialize)(dividerV)).EndInit(); } }
public void DivideAction(Virus virus) { DividerVirus dvKlein1 = new DividerVirus(); DividerVirus dvKlein2 = new DividerVirus(); ((ISupportInitialize)(dvKlein1)).BeginInit(); dvKlein1.MouseClick += new MouseEventHandler(Game.instance.MouseClickShootBullet); dvKlein1.BackColor = Color.Transparent; dvKlein1.Parent = Game.instance.pbBackGround; // evtl noch einen Killswitch einbauen, sodass es in seltenen Fällen, bei denen absoulut kein Platz in der randomZone ist es zu keinem loop kommt Rectangle r; Point newLocation; int x; int y; do { x = randomizer.Next(virus.Bounds.X - virus.Bounds.Width, virus.Bounds.X + virus.Bounds.Width * 2); y = randomizer.Next(virus.Bounds.Y - virus.Bounds.Height, virus.Bounds.Y + virus.Bounds.Width * 2); newLocation = new Point(x, y); r = new Rectangle(x, y, 70, 50); } while (IsThisAFreeSpace(r) == false); dvKlein1.VirusHealth = 1; dvKlein1.Location = newLocation; dvKlein1.Size = new Size(70, 50); dvKlein1.DoubleBuffered = true; dvKlein1.Points = 1; UiComponents.AddVirus(dvKlein1); ((ISupportInitialize)(dvKlein1)).EndInit(); ((ISupportInitialize)(dvKlein2)).BeginInit(); dvKlein2.MouseClick += new MouseEventHandler(Game.instance.MouseClickShootBullet); dvKlein2.BackColor = Color.Transparent; dvKlein2.Parent = Game.instance.pbBackGround; // evtl noch einen Killswitch einbauen, sodass es in seltenen Fällen, bei denen absoulut kein Platz in der randomZone ist es zu keinem loop kommt do { x = randomizer.Next(virus.Bounds.X - virus.Bounds.Width, virus.Bounds.X + virus.Bounds.Width * 2); y = randomizer.Next(virus.Bounds.Y - virus.Bounds.Height, virus.Bounds.Y + virus.Bounds.Width * 2); newLocation = new Point(x, y); r = new Rectangle(x, y, 70, 50); } while (IsThisAFreeSpace(r) == false); dvKlein2.Location = newLocation; dvKlein2.Size = new Size(70, 50); dvKlein2.DoubleBuffered = true; dvKlein2.VirusHealth = 1; dvKlein2.Points = 1; UiComponents.AddVirus(dvKlein2); ((ISupportInitialize)(dvKlein2)).EndInit(); dvKlein1.RecalculateTargetPosition(); dvKlein2.RecalculateTargetPosition(); Game.instance.Controls.Remove(virus); UiComponents.Viruses.Remove(virus); virus.Dispose(); }