Example #1
0
 public Game2()
 {
     this.positionGrid = new CharacterGrid();
     this.splashScreen = new GameIntro();
     this.jukebox      = new Jukebox();
 }
Example #2
0
        public (string, MusicNote[], int[], int[]) ChooseSong(CharacterGrid positionGrid)
        {
            string song = "";

            Console.WriteLine("          Choose your song:");
            Console.WriteLine("1) Twinkle Twinkle Little Star (Easy)");
            Console.WriteLine("2) The Entertainer (Medium)");
            Console.WriteLine("3) In the Hall of the Mountain King (Hard)");
            ConsoleKey choiceNumber = Console.ReadKey(true).Key;

            bool proceed = false;

            while (!proceed)
            {
                try
                {
                    if (choiceNumber == ConsoleKey.D1 || choiceNumber == ConsoleKey.D2 || choiceNumber == ConsoleKey.D3)
                    {
                        //goodPick = true;
                        proceed = true;
                        switch (choiceNumber)
                        {
                        case (ConsoleKey.D1): song += "TwinkleTwinkleLittleStar2.txt"; break;

                        case (ConsoleKey.D2): song += "Entertainer3.txt"; break;

                        case (ConsoleKey.D3): song += "MountainKing2.txt"; break;
                        }
                    }
                    else
                    {
                        Console.CursorLeft = 0;
                        Console.Write("Please press a valid number to choose your song...");
                        choiceNumber = Console.ReadKey(true).Key;
                    }
                }
                catch
                {
                    Console.Write("Please press a valid number to choose your song...");
                    choiceNumber = Console.ReadKey(true).Key;
                }
            }

            string songTitle = "";
            string fileLine;

            MusicNote[] noteArray;
            int[]       durationArray;
            int[]       timeToNextArray;

            using (StreamReader sf = File.OpenText(songDirectory + song))
            {
                songTitle = sf.ReadLine();
                int numberOfLines = Convert.ToInt32(sf.ReadLine());
                noteArray       = new MusicNote[numberOfLines];
                durationArray   = new int[numberOfLines];
                timeToNextArray = new int[numberOfLines];
                int index1 = 0;

                while ((fileLine = sf.ReadLine()) != null && fileLine != "")
                {
                    string[] noteinfo = fileLine.Split(',');

                    noteArray[index1]       = positionGrid.noteDict[noteinfo[0]];
                    durationArray[index1]   = Convert.ToInt32(noteinfo[1]);
                    timeToNextArray[index1] = Convert.ToInt32(noteinfo[2]);
                    index1++;
                }
            }
            Console.SetCursorPosition(0, 0);
            return(songTitle, noteArray, durationArray, timeToNextArray);
        }