private void StartGame() { this.Wave = 1; this.messageLabel.Visible = false; this.messageLabel.Top = this.Height / 2; this.messageLabel.Left = this.Width / 2; this.Lives = 3; this.Score = 0; const int PADDING = 25; this.field = Field.create(this.Top + PADDING, this.Left + PADDING, this.Height - PADDING, this.Width - PADDING); rocketItem = Rocket.Create(this.field); rocketItem.Radius = 10; const int ASTEROID_SIZE = 60; const int ASTEROID_COUNT = 7; CurrentWaveCount = ASTEROID_COUNT; this.CurrentWaveSize = ASTEROID_SIZE; this.CreateAsteroidWave(ASTEROID_COUNT, ASTEROID_SIZE); this.starCollection.Clear(); this.bulletCollection.Clear(); const int STAR_COUNT = 55; for (int i = 0; i < STAR_COUNT; i++) { Star star = Star.Create(this.field); starCollection.Add(star); } this.IsGameOn = true; }
private void replacementTimer_Tick(object sender, EventArgs e) { if (this.IsGameOn) { if (this.asteroidCollection.Count == 0) { this.Wave++; CurrentWaveSize=CurrentWaveSize + 4; if (CurrentWaveSize > MAX_WAVE_SIZE) { CurrentWaveSize = MAX_WAVE_SIZE; } CurrentWaveCount++; CreateAsteroidWave(CurrentWaveCount, CurrentWaveSize); } } if (this.IsGameOn) { if (this.Lives == 0) { this.IsGameOn = false; this.messageLabel.Visible = true; this.messageLabel.Text = "GAME OVER (f2 to start)"; } else { if (rocketItem.IsDead) { const int SAFE_DISTANCE = 80; bool isSafeToMaterialize = true; foreach (Asteroid a in this.asteroidCollection) { if (a.GetDistance(rocketItem) < SAFE_DISTANCE) { isSafeToMaterialize = false; } } if (isSafeToMaterialize) { this.rocketItem = Rocket.Create(this.field); rocketItem.IsDead = false; } } } } }