Ejemplo n.º 1
0
        // Spawns a wave of the given virus.
        public static void spawnWave(int waveSize, Virus virus)
        {
            // Always Delay the spawn by 10 seconds
            Game.DelayInvoke(2000, () => {
                Object[,] map        = DataManager.Map.mapArray;
                List <Virus> viruses = DataManager.Map.Viruses;
                virus.Position       = DataManager.Map.SpawnLocation;
                Random rnd           = new Random();
                // Viruses will spawn one second at a time
                Timer spawnTimer = new Timer(2000 + rnd.Next(500, 3000));
                spawnTimer.Start();
                spawnTimer.Elapsed += (sender, args) =>
                {
                    try
                    {
                        Tindrider t = new Tindrider();
                        t.Position  = virus.Position;
                        t.Health    = virus.Health;
                        t.Money     = virus.Money;
                        t.Speed     = virus.Speed;


                        int score = DataManager.Board.Score;

                        if (score % 500 == 0)
                        {
                            increase = true;
                        }

                        if (increase)
                        {
                            health   = (int)(health * 1.1);
                            increase = false;
                        }

                        t.Health    = health;
                        t.MaxHealth = health;
                        Console.WriteLine(health);

                        viruses.Add(t);
                        waveSize--;
                        if (waveSize <= 0)
                        {
                            spawnTimer.Stop();
                        }
                    }
                    catch (IndexOutOfRangeException e)
                    {
                    }
                };
            });
        }
Ejemplo n.º 2
0
        public Map()
        {
            Home = new Home();
            // add handler for virus deaths
            virusDeath += (virus, isLifeLost) => {
                if (isLifeLost == true)
                {
                    if (Home.takeDamage())
                    {
                        int highestScore;

                        //Check if the file exists.
                        if (!File.Exists("highScore.txt"))
                        {
                            //Create the file if it doesn't exist and save 0 as the high score.
                            using (StreamWriter sr = new StreamWriter("highScore.txt"))
                            {
                                sr.WriteLine("0");
                            }
                        }

                        //Read the score in the file, even if it was just created.
                        using (TextReader reader = File.OpenText("highScore.txt"))
                        {
                            highestScore = int.Parse(reader.ReadLine());
                        }

                        //Check if the user's final score is greater than the highscore saved in the file.
                        if (DataManager.Board.Score > highestScore)
                        {
                            //Update the score in the file if the user's final score is higher.
                            using (StreamWriter sr = new StreamWriter("highScore.txt"))
                            {
                                sr.WriteLine(DataManager.Board.Score + "");
                            }
                        }

                        Game.SetGameState(GameState.GameOver);
                    }
                }
                else
                {
                    DataManager.Board.AddMoney(virus.Money);
                    DataManager.Board.AddScore(virus.Score);
                }
                Viruses.Remove(virus);
                if (Viruses.Count <= 0)
                {
                    // TODO should determine virus type by wave number
                    int       score = DataManager.Board.Score;
                    Tindrider tind  = new Tindrider();

                    if (score >= 500)
                    {
                        //tind.Health = 200;
                        //tind.Money = 5;
                        tind.Speed -= 25;
                    }

                    /* if(score >= 1000)
                     * {
                     *   tind.Health = 300;
                     *
                     * }
                     * if(score >= 1500)
                     * {
                     *   tind.Health = 450;
                     *   tind.Speed -= 50;
                     * }
                     * if (score >= 2000)
                     * {
                     *   tind.Health = 600;
                     * }
                     * if (score >= 2000)
                     * {
                     *   tind.Health = 750;
                     * }*/
                    SpawnManager.spawnWave(1000, tind);
                }
            };
            // Spawn one wave on creation of the map
            SpawnManager.spawnWave(10, new Tindrider());
        }