コード例 #1
0
 public void Tear_RemovesDisksFromTowers()
 {
     var towers = new Towers();
     towers.Clear();
     towers.Tower1.Count.ShouldEqual(0);
     towers.Tower2.Count.ShouldEqual(0);
     towers.Tower3.Count.ShouldEqual(0);
 }
コード例 #2
0
        public void StartGame()
        {
            CurrentLevel = 1;
            CurrentScore = 0;
            Towers.Clear();
            Levels.Clear();

            PrintWelcome();                 // Print Welcome-Screen and Highscore
            SetDifficulty();                // Set difficulty and generate map & path
            AskToPlaceTowers();             // Ask player to place tower
            GenerateInvaderAndLevels();     // Generate all levels with their relative invaders

            try
            {
                // Run all levels, calculate score and increase towerpoints
                // After each level player can place more towers
                foreach (var level in Levels)
                {
                    level.Towers = Towers.ToArray();
                    if (level.Play())
                    {
                        foreach (var invader in level._invaders)
                        {
                            CurrentScore += invader.Score;
                        }
                        CurrentScore += 5;
                        Console.WriteLine("Level {0} completed, you earned {1} points!", CurrentLevel, CurrentScore);
                        CurrentLevel++;
                        continue;
                    }
                    else
                    {
                        Console.WriteLine();
                        Console.WriteLine("Game Over - You have lost!");
                        Console.WriteLine("You have reached level {0}", CurrentLevel);
                        Console.Write("Play again? (y/n): ");
                        if (Console.ReadKey().Key == ConsoleKey.Y)
                        {
                            StartGame();
                        }
                        else
                        {
                            throw new Exception("Game Over!");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // GameOver();
                // CheckForHighscore();
                Console.WriteLine(ex);
                SaveHighscore();
            }

        }