Example #1
0
        // This is the Create new game menu
        static int NewGame(Hero[] hero, HeroSave[] heroSave, CellSave[,] cellSave, Cell[,] cell, string[] savedInfo, int currentGame, int newGameFile)
        {
            string saved      = System.IO.File.ReadAllText(@"SavedGames.txt");
            int    savedGames = int.Parse(saved);

            newGameFile           = 0;
            currentGame           = savedGames;
            hero[currentGame]     = new Hero();
            heroSave[currentGame] = new HeroSave();

            Console.Clear();
            Console.SetCursorPosition((Console.WindowWidth / 2) - 9, Console.CursorTop);
            Console.WriteLine("Character Creation");
            Console.Write("\n\n\nPlease enter the name of your hero (confirm with ENTER): ");
            string answer = Console.ReadLine();

            hero[currentGame].SetName(answer);
            Console.Clear();
            Console.WriteLine("\n\nWelcome {0}! You seem to be confused why you are here in this empty space.", answer);
            Console.WriteLine("The truth is, you are dead...but I'm willing to give you another chance to live...\nthat is if you can clear my quest for you.");
            Console.WriteLine("Behind me there is a portal and it will lead you to a dungeon of some sort with a lot of secrets.\nThere are 10 rooms filled with monsters, if you are lucky there will be none.");
            Console.WriteLine("You have to find 10 keys on this quest.\nAfter that you need to reach the last room in the top right corner of this land.\nThen enter the portal to go back to your normal life and your memory of me and this place will be erased.");
            Console.WriteLine("I wish you good luck..hehe..");
            Console.WriteLine("\n{0}: ..what was that creature..? *slowly enters the portal*", answer);

            HeroInfo(hero, ref currentGame);
            Console.WriteLine("\n\nStart Game: Press ENTER");
            Console.ReadLine();

            savedGames++;
            saved = savedGames.ToString();
            System.IO.File.WriteAllText(@"SavedGames.txt", saved);
            SaveGame(hero, heroSave, cell, cellSave, savedInfo, ref currentGame, newGameFile);
            return(currentGame);
        }
Example #2
0
        // ============================================================================================
        // ============================================================================================
        // MAIN
        static void Main(string[] args)
        {
            Console.SetCursorPosition((Console.WindowWidth - 8) / 2, Console.CursorTop + 6);
            Console.WriteLine("KeyQuest");
            Console.SetCursorPosition((Console.WindowWidth - 23) / 2, Console.CursorTop + 4);
            Console.WriteLine("Press ENTER to continue");
            BuildVersion();
            Console.ReadLine();

            Console.Clear();
            Console.Write("\n\n\n\n\n\n\t\tLoading awesome adventures.");
            for (int i = 0; i < 10; i++)
            {
                System.Threading.Thread.Sleep(200);
                Console.Write(".");
            }

            string choice = "0";
            int    alive = 1, clearGame = 0, newGameFile = 0;

            Hero[]     hero     = new Hero[10];
            HeroSave[] heroSave = new HeroSave[10];
            Cell[,] cell         = new Cell[10, 10];
            CellSave[,] cellSave = new CellSave[10, 10];
            string[] savedInfo = new string[10];
            bool     exit      = false;

            while (!exit)
            {
                newGameFile = 0;
                int savedGames = MainMenu(savedInfo);
                BuildVersion();
                bool runGame = false, newGame = false, loadGame = false;
                int  currentGame = 0;

                Console.SetCursorPosition((Console.WindowWidth) / 2 - 7, Console.CursorTop - 12);
                choice = Console.ReadLine();

                if (choice == "1")
                {
                    if (savedGames < 10)
                    {
                        currentGame = NewGame(hero, heroSave, cellSave, cell, savedInfo, currentGame, newGameFile);
                        runGame     = true;
                        newGame     = true;
                    }
                    else
                    {
                        ErrorInput();
                        Console.SetCursorPosition((Console.WindowWidth / 2) - 14, Console.CursorTop + 2);
                        Console.WriteLine("There are no free slots for new games");
                        Console.SetCursorPosition((Console.WindowWidth / 2) - 14, Console.CursorTop + 2);
                        Console.WriteLine("Please delete a saved game to be able to create a new game");
                        Console.SetCursorPosition((Console.WindowWidth / 2) - 14, Console.CursorTop + 2);
                        Console.WriteLine("Press ENTER to continue");
                        Console.ReadLine();
                    }
                }
                else if (choice == "2")
                {
                    if (savedGames > 0)
                    {
                        exit = false;
                        while (!exit)
                        {
                            if (savedGames > 0)
                            {
                                choice = ManageGamesMenu();
                                if (choice == "1")
                                {
                                    int answer = LoadGameMenu(savedInfo, savedGames);
                                    if (answer >= 0 && answer < savedGames)
                                    {
                                        currentGame = answer;
                                        runGame     = true;
                                        loadGame    = true;
                                        newGameFile = 1;
                                        exit        = true;
                                    }
                                }
                                else if (choice == "2")
                                {
                                    if (savedGames > 0)
                                    {
                                        int answer = DeleteGameMenu(savedInfo, savedGames);
                                        if (answer >= 0 && answer <= savedGames)
                                        {
                                            savedGames = DeleteGame(answer, savedInfo);
                                        }
                                        else
                                        {
                                            exit = true;
                                        }
                                    }
                                    else
                                    {
                                        LoadGameError();
                                        exit = true;
                                    }
                                }
                                else if (choice == "3")
                                {
                                    exit = true;
                                }
                            }
                            else
                            {
                                LoadGameError();
                                exit = true;
                            }
                        }
                        exit = false;
                        if (loadGame)
                        {
                            exit = true;
                        }
                    }
                    else
                    {
                        ErrorInput();
                        LoadGameError();
                    }
                }
                else if (choice == "3")
                {
                    exit = true;
                }
                else
                {
                    ErrorInput();
                }

                if (runGame)
                {
                    if (newGame)
                    {
                        BuildNewWorld(cell, cellSave, newGameFile);
                        newGameFile = 1;
                    }
                    else if (loadGame)
                    {
                        newGameFile = 1;
                        BuildNewWorld(cell, cellSave, newGameFile);
                        currentGame = LoadGame(hero, heroSave, cell, cellSave, savedInfo, currentGame, newGameFile);
                    }
                    choice = "0";
                    exit   = false;
                    while (!exit)
                    {
                        Console.Clear();
                        choice = HeroAction(hero, ref currentGame, ref cell);
                        int test = 0;

                        switch (choice)
                        {
                        case "1":
                            test = hero[currentGame].GetPositionY();
                            if (test == 1)
                            {
                                WallError();
                            }
                            else
                            {
                                hero[currentGame].SetPositionY(-1);
                            }
                            break;

                        case "2":
                            test = hero[currentGame].GetPositionX();
                            if (test == 10)
                            {
                                WallError();
                            }
                            else
                            {
                                hero[currentGame].SetPositionX(+1);
                            }
                            break;

                        case "3":
                            test = hero[currentGame].GetPositionY();
                            if (test == 10)
                            {
                                WallError();
                            }
                            else
                            {
                                hero[currentGame].SetPositionY(+1);
                            }
                            break;

                        case "4":
                            test = hero[currentGame].GetPositionX();
                            if (test == 1)
                            {
                                WallError();
                            }
                            else
                            {
                                hero[currentGame].SetPositionX(-1);
                            }
                            break;

                        case "5":
                            if (hero[currentGame].GetPotion() >= 1 && hero[currentGame].GetHealth() < 100)
                            {
                                int potion = hero[currentGame].GetHealth();
                                potion += 10;
                                hero[currentGame].SetHealth(potion);
                                hero[currentGame].SetPotion(-1);
                            }
                            break;

                        case "6":
                            SaveGame(hero, heroSave, cell, cellSave, savedInfo, ref currentGame, newGameFile);
                            break;

                        case "7":
                            exit = true;
                            break;

                        case "2020":
                            ShowKey(cell);
                            break;

                        default:
                            break;
                        }
                        if (choice == "1" || choice == "2" || choice == "3" || choice == "4")
                        {
                            int heroX = hero[currentGame].GetPositionX() - 1;
                            int heroY = hero[currentGame].GetPositionY() - 1;
                            clearGame = Landscape(cell, ref hero, ref currentGame, ref heroX, ref heroY);
                            if (cell[heroX, heroY].GetMobs() > 0)
                            {
                                choice = Encounter(cell, ref hero, ref currentGame, ref heroX, ref heroY);
                                if (choice == "1" || choice == "2")
                                {
                                    alive = MonsterFight(cell, hero, ref currentGame, ref heroX, ref heroY);
                                }
                                else
                                {
                                    Console.Clear();
                                    Console.SetCursorPosition((Console.WindowWidth / 2) - 36, Console.CursorTop + 6);
                                    Console.WriteLine("You turn around and run for your life. You can hear the evil snarls and shouts behind you..");
                                    Console.SetCursorPosition((Console.WindowWidth / 2) - 36, Console.CursorTop + 2);
                                    System.Console.WriteLine("Press ENTER to continue your adventure");
                                    Console.ReadLine();
                                }
                            }
                            else
                            {
                                if (cell[heroX, heroY] == cell[0, 9] || cell[heroX, heroY] == cell[9, 0])
                                {
                                    Console.SetCursorPosition((Console.WindowWidth / 2) - 34, Console.CursorTop + 2);
                                    Console.WriteLine("Once again you go to face the dangers of the mysterious world");
                                    Console.SetCursorPosition((Console.WindowWidth / 2) - 34, Console.CursorTop + 2);
                                    System.Console.WriteLine("Press ENTER to continue your adventure");
                                    Console.ReadLine();
                                }
                                else
                                {
                                    Console.SetCursorPosition((Console.WindowWidth / 2) - 34, Console.CursorTop + 2);
                                    Console.WriteLine("Your exceptional senses can not find anything hiding");
                                    Console.SetCursorPosition((Console.WindowWidth / 2) - 34, Console.CursorTop + 2);
                                    System.Console.WriteLine("Press ENTER to continue your adventure");
                                    Console.ReadLine();
                                }
                            }
                            FindKey(cell, hero, ref currentGame, ref heroX, ref heroY);
                        }
                        if (alive == 0 || clearGame == 1)
                        {
                            exit = true;
                        }
                    }
                    exit = false;
                }
            }

            Console.Clear();
            Console.SetCursorPosition((Console.WindowWidth - 21) / 2, Console.CursorTop + 6);
            Console.WriteLine("Thank you for playing!");
            Console.SetCursorPosition((Console.WindowWidth - 19) / 2, Console.CursorTop + 4);
            Console.WriteLine("Press ENTER to exit");
            Console.ReadLine();
            Console.Clear();
            Console.SetCursorPosition((Console.WindowWidth / 2) - 30, Console.CursorTop + 10);
            Console.Write("Chasing away the last monsters.");
            for (int i = 0; i < 15; i++)
            {
                System.Threading.Thread.Sleep(200);
                Console.Write(".");
                if (i == 4)
                {
                    Console.Write("Shoo shoo.");
                }
            }
        }