using Penguloon.Enemies; using System; using System.Collections.Generic; using System.Threading; namespace Penguloon.Levels { public class WaveManager { public List Waves { get; set; } = new List(); public Map Map { get; set; } public int CurrentWave { get; set; } = 1; public bool RoundActive { get; set; } public bool DoneSpawning { get; set; } = false; public WaveManager(Map map) { this.Map = map; CreateWaves(); } private void CreateWaves() { Waves.Add(new Wave(new List>() { new Tuple(typeof(BlueBalloon), 250) }, 50)); Waves.Add(new Wave(new List>() { new Tuple(typeof(RedBalloon), 10) }, 500)); } public void StartSpawningEnemies() { RoundActive = true; DoneSpawning = false; new Thread(() => { Thread.CurrentThread.IsBackground = true; int waveToSpawn = CurrentWave - 1; if (waveToSpawn >= Waves.Count) waveToSpawn = Waves.Count - 1; for (int i = 0; i < Waves[waveToSpawn].EnemiesToSpawn.Count; i++) { for(int x = 0; x < Waves[waveToSpawn].EnemiesToSpawn[i].Item2; x++) { Map.SpawnEnemy(Waves[waveToSpawn].EnemiesToSpawn[i].Item1); Thread.Sleep(Waves[waveToSpawn].SpawnDelayMS); } } DoneSpawning = true; }).Start(); } internal void FinishRound() { CurrentWave++; } } public class Wave { public int SpawnDelayMS { get; set; } public List> EnemiesToSpawn { get; set; } = new List>(); public Wave(List> EnemiesToSpawn, int SpawnDelayMS) { this.SpawnDelayMS = SpawnDelayMS; this.EnemiesToSpawn = EnemiesToSpawn; } } }