Ejemplo n.º 1
0
        public static void StartProgram()
        {
            Console.Title = "My Classmates";
            if (FileHandling.CheckFileFolderExistance() > 0)
            {
                Classmates.Populate(myClassmates);

                //Method for saving mockdata and user changes to a file.
                FileHandling.BinarySerializer(myClassmates);
            }

            // Else read the file
            else
            {
                myClassmates = FileHandling.BinaryDeSerializer(myClassmates);
            }
            Console.SetWindowSize(100, 40);
            FileHandling.CreateLogos();

            //Runs the login method
            Login.UserLogin();
            //If the program had to add any files, then populate that file with the standard classmates

            Menus.StartMenu(myClassmates);
        }
Ejemplo n.º 2
0
        //Main menu
        public void StartMenu(Menu menuObject)
        {
            _menuObject = menuObject;

            //Start the music
            menuMusic.PlaySound(menu);
            bool   continueCode            = false;
            bool   firstTimeRunningProgram = true;
            string option;
            bool   error    = false;
            string errorMsg = default;

            do
            {
                //print the logo
                if (firstTimeRunningProgram)
                {
                    Print.LogoPrint();
                    firstTimeRunningProgram = false;
                }
                Print.ClearAllScreen();

                Print.EnemyPrint("Ending dragon");

                top = 13;

                //Print the menu
                for (int i = 0; i < startMenuOptions.Length; i++)
                {
                    Console.SetCursorPosition(left, top);
                    Console.WriteLine($"{i + 1}. {startMenuOptions[i]}");
                    top++;
                }

                //If there are errors (or messages to the player) they will be printed here.
                if (error)
                {
                    Console.SetCursorPosition(left, top + 2);
                    Print.Red(errorMsg);
                    errorMsg = default;
                }
                Console.SetCursorPosition(left, top + 1);
                Console.Write("Choose your option> ");
                Console.CursorVisible = true;
                option = Console.ReadLine();
                Console.CursorVisible = false;
                var sounds = _menuObject.SoundList();
                AudioPlaybackEngine sound = new AudioPlaybackEngine();
                sound.PlaySound(sounds[1]);
                Thread.Sleep(700);
                sound.Dispose();
                switch (option)
                {
                //New game
                case "1":
                    error = false;

                    if (File.Exists(pathway + file))
                    {
                        File.Delete(pathway + file);
                        Directory.Delete(pathway);
                    }
                    int check = FileHandling.CheckFileFolderExistance();
                    if (check == 1 || check == 2)
                    {
                        NewGame();
                    }

                    break;

                //Continue adventure
                case "2":
                    string pathwayFull = string.Concat(pathway, file);



                    if (FileHandling.CheckFileFolderExistance() == 1 || FileHandling.CheckFileFolderExistance() == 2)
                    {
                        error    = true;
                        errorMsg = "No previous games saved";
                    }
                    else
                    {
                        if (new FileInfo(pathwayFull).Length == 0)
                        {
                            error    = true;
                            errorMsg = "No previous games saved";
                        }
                        else
                        {
                            playerList = FileHandling.BinaryDeSerializer(playerList);

                            error = false;

                            NewGame();
                        }
                    }



                    break;

                //Exit game
                case "3":

                    Thread.Sleep(1000);
                    Environment.Exit(0);
                    break;

                default:
                    error = true;

                    errorMsg = "Wrong menu choice";
                    break;
                }
            } while (!continueCode);
        }