Esempio n. 1
0
        //Asks the player if they want to fight the monster
        private bool AskPlayer(Hero hero, int keys)
        {
            Console.Clear();
            Ascii.MonsterSpawn();
            Ascii.MonsterEncounter();
            Ascii.Decision();

            string input;

            input = Console.ReadLine().ToUpper().Trim();

            switch (input)
            {
            case "A":
            case "ATTACK":
                Fight(hero, keys);
                return(true);

            case "F":
            case "FLEE":
                Console.WriteLine("You decided to flee!");
                return(false);

            default:
                Console.WriteLine($"{hero.Name} Can't decide what to do! {hero.Name} retreated!");
                Console.ReadLine();
                return(false);
            }
        }
Esempio n. 2
0
        //If key, this function is called, to keep score on how many keys user has, and if it has 10, enable parameter for win senario.
        private void GetKey(Hero hero)
        {
            Ascii.CollectKey();
            Console.WriteLine("There was a key in this room!");
            hero.NumberOfKeys++;
            Console.WriteLine($"Key added to inventory, you now have {hero.NumberOfKeys}!");

            if (hero.NumberOfKeys == 10)
            {
                Console.WriteLine("You have gotten all the keys, head to the top right corner!");
                hero.CollectedAllKeys = true;
            }
            Console.ReadLine();
        }
Esempio n. 3
0
        //Starts menu
        private static bool Meny()
        {
            Console.Clear();
            Console.WriteLine("Write //START// or //S// to Play");
            Console.WriteLine("Write //LOAD// or //L// to Load a Saved Game");
            Console.WriteLine("Write //EXIT// or //E// to Exit Game");

            switch (Console.ReadLine().ToLower().Trim())
            {
            case "s":
            case "start":
                Console.Clear();
                Ascii.StartGame();
                Console.WriteLine();
                Console.WriteLine("Welcome to the textbased game: GET OUT OF THE DUNGEON!");
                Console.WriteLine("Under your adventure you happened to get stuck in a dungeon!");
                Console.WriteLine("To get out of the dungeon you will have to find 10 keys.");
                Console.WriteLine("You can find the keys by collecting them from different rooms.");
                Console.WriteLine("After colleting 10 keys you will have to reach the end of the dungeon to get out.");
                Console.WriteLine("However beware of the monsters!\n");

                //Starts game
                Start();
                return(true);

            case "e":
            case "exit":
                return(false);

            case "l":
            case "load":
                new RenderGame();
                return(true);

            default:
                return(true);
            }
        }
Esempio n. 4
0
 //If user dies, aka 0 or below HP, this method is called.
 private void GameOver(Hero hero)
 {
     //Console.WriteLine($"{hero.Name} died, pity. Game over.");
     Ascii.EndGameLose();
     PlayGame = false;
 }
Esempio n. 5
0
        //Handles player interaction on the the gamemap. Letting the player move the hero or use the menu to Save, Load or Exit the game.
        public void Move(Hero hero, int moveway)
        {
            if (moveway == 1)
            {
                ConsoleKeyInfo keyInfo = Console.ReadKey();
                if (keyInfo.Key == ConsoleKey.UpArrow)
                {
                    if (hero.PosX > 0)
                    {
                        CheckMove(hero, (-1), "X");
                    }
                }
                //If DownArrow, go down, but check what is there and so the location is not out of bounds
                if (keyInfo.Key == ConsoleKey.DownArrow)
                {
                    if (hero.PosX < 9)
                    {
                        CheckMove(hero, 1, "X");
                    }
                }
                //If LeftArrow, go Left, but check what is there and so the location is not out of bounds
                if (keyInfo.Key == ConsoleKey.LeftArrow)
                {
                    if (hero.PosY > 0)
                    {
                        CheckMove(hero, (-1), "Y");
                    }
                }
                //If RightArrow, go Right, but check what is there and so the location is not out of bounds
                if (keyInfo.Key == ConsoleKey.RightArrow)
                {
                    if (hero.PosY < 9)
                    {
                        CheckMove(hero, (1), "Y");
                    }
                }

                if (keyInfo.Key == ConsoleKey.Escape) //Pressing escape to bring up the Save, Load and Exit menu
                {
                    Console.Write("._");              //Prevents readkey from interfering with output, without this readkey eats from ascii text.
                    Console.Clear();
                    Ascii.MenuInstruct();
                    string testInput = Console.ReadLine().Trim().ToUpper();
                    if (true)
                    {
                        switch (testInput)
                        {
                        case "SAVE":
                            SaveLoad.SaveGameMenu(hero, Map);
                            break;

                        case "LOAD":
                            SaveLoad.LoadGameMenu(hero, ref _map);
                            break;

                        case "EXIT":
                            PlayGame = false;
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
            else if (moveway == 2)
            {
                string readInput = Console.ReadLine();

                if (readInput == "go up" || readInput == "up" || readInput == "u")
                {
                    if (hero.PosX > 0)
                    {
                        CheckMove(hero, (-1), "X");
                    }
                }
                //If DownArrow, go down, but check what is there and so the location is not out of bounds
                if (readInput == "go down" || readInput == "down" || readInput == "d")
                {
                    if (hero.PosX < 9)
                    {
                        CheckMove(hero, 1, "X");
                    }
                }
                //If LeftArrow, go Left, but check what is there and so the location is not out of bounds
                if (readInput == "go left" || readInput == "left" || readInput == "l")
                {
                    if (hero.PosY > 0)
                    {
                        CheckMove(hero, (-1), "Y");
                    }
                }
                //If RightArrow, go Right, but check what is there and so the location is not out of bounds
                if (readInput == "go right" || readInput == "right" || readInput == "r")
                {
                    if (hero.PosY < 9)
                    {
                        CheckMove(hero, (1), "Y");
                    }
                }
                if (readInput == "menu") //Typing menu to bring up the Save, Load and Exit menu
                {
                    Ascii.MenuInstruct();
                    string testInput = Console.ReadLine().Trim().ToUpper();
                    switch (testInput)
                    {
                    case "SAVE":
                        SaveLoad.SaveGameMenu(hero, Map);
                        break;

                    case "LOAD":
                        SaveLoad.LoadGameMenu(hero, ref _map);
                        break;

                    case "EXIT":
                        PlayGame = false;
                        break;

                    default:
                        break;
                    }
                }
            }
            //Check after every move if we have all the keys, and if we are in top right corner, if both are true, user wins and loop ends.
            if (hero.CollectedAllKeys && hero.PosX == 0 && hero.PosY == 9)
            {
                Console.Clear();
                Ascii.EndGameWin();
                Console.WriteLine();
                Console.WriteLine("You win, the game is over");
                Console.WriteLine("Press any key to continue\n");
                Console.ReadKey();
                PlayGame = false;
            }
        }
Esempio n. 6
0
        //The toplevel loop in running the game.
        //Determines the players input method and renders the game map.
        public void RenderLoop(Hero hero)
        {
            int moveWay = 0;

            if (moveWay == 0)
            {
                bool check = true;
                do
                { //Asks player to select an input method for the game.
                    Console.Clear();
                    Console.WriteLine("Do You Want to Use Arrow Keys or Text to Move Hero?");
                    Console.WriteLine();
                    Console.WriteLine("Write //ARROW// or //A// to Use Arrow Keys to Move Hero");
                    Console.WriteLine("Write //TEXT// or //T// to Use Text to Move Hero");

                    switch (Console.ReadLine().ToLower().Trim())
                    {
                    case "a":
                    case "arrow":
                        moveWay = 1;
                        check   = false;
                        break;

                    case "t":
                    case "text":
                        moveWay = 2;
                        check   = false;
                        break;

                    default:
                        continue;
                    }
                } while (check);
            }

            while (PlayGame)
            {
                Console.Clear();
                //Draw hero on Map
                Map[hero.PosX, hero.PosY] = " X ";

                if (moveWay == 2)
                {
                    Ascii.HowToMoveText();
                }
                else if (moveWay == 1)
                {
                    Ascii.HowToMoveArrow();
                }

                //Renders the game map
                for (int i = 0; i < 10; i++)
                {
                    Console.Write("                ");
                    for (int j = 0; j < 10; j++)
                    {
                        Console.Write(Map[i, j]);
                    }

                    if (i == Map.GetUpperBound(0) - 2)
                    {
                        Console.WriteLine($"{hero.Name}:");
                    }
                    else if (i == Map.GetUpperBound(0) - 1)
                    {
                        Console.WriteLine($"HP: {hero.HP}");
                    }
                    else if (i == Map.GetUpperBound(0))
                    {
                        Console.WriteLine($"Keys: {hero.NumberOfKeys}");
                    }
                    else
                    {
                        Console.WriteLine();
                    }
                }
                //Wait for move
                Move(hero, moveWay);
            }
        }