9.6. Wanzenschwemme

Nun wird es endlich Zeit für eine Wanzenvermehrung. Die findet nur im Quelltext des Hauptprogramms statt. Zuerst brauchen wir ein Array, sagen wir zu Anfang mit fünf Elementen – es muss ja nicht sofort zu einer Plage werden:

const int Max = 5;
ABug[] Wanze = new ABug[Max];

Außerdem müssen wir auch im Hauptprogramm den Zufall um Hilfe bitten:

Random Zufall = new Random();

In der Methode Initialize() werden alle dann in einer for-Schleife erzeugt (→ XBuggy8):

for (int i = 0; i < Max; i++) { Wanze[i] = new ABug(Zufall.Next(Window.ClientBounds.Width), Zufall.Next(Window.ClientBounds.Height), 100, 100); int XX, YY, ZZ = 10; do { XX = Zufall.Next(-ZZ, ZZ); YY = Zufall.Next(-ZZ, ZZ); } while ((XX == 0) && (YY == 0)); Wanze[i].SetSpeed(XX, ...

Get Spieleprogrammierung mit dem XNA Framework: Entwickeln für PC und Xbox now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.