Ejemplo n.º 1
0
 //Initialize New Game with TA Object from LoadGame()
 private static void StartGame(TextAdventure _TA)
 {
     //Calls Play() from Text-Adventure-Class
     Console.WriteLine(_TA.Player.StartText);
     _TA.CurrentRoom.ShowRoom();
     _TA.DisplayCommands();
     _TA.Play();
 }
Ejemplo n.º 2
0
 public void PassDor(TextAdventure _TA)
 {
     foreach (Room room in _TA.AllRooms)
     {
         if (LeadsTo == room.Name)
         {
             _TA.CurrentRoom = room;
             _TA.CurrentRoom.ShowRoom();
         }
     }
 }
Ejemplo n.º 3
0
        public void GiveItemToNPC(TextAdventure _TA)
        {
            Console.WriteLine("Who do you want to give an Item?");
            string input = Console.ReadLine();

            input = input.ToLower();
            if (Npcs.Count > 0)
            {
                foreach (NPC npc in Npcs)
                {
                    if (input == npc.Name)
                    {
                        Console.WriteLine("Which Item do you want to give to " + input);
                        string item = Console.ReadLine();
                        item = item.ToLower();
                        if (item == npc.Interactions[2]) //Check if Item is the right Item for NPC
                        {
                            Console.WriteLine("Thank you so much for the " + item);
                            int counter = 0;
                            foreach (Item it in _TA.Player.Inventory)
                            {
                                if (item == it.Name)
                                {
                                    _TA.Player.Inventory.RemoveAt(counter);
                                    Console.WriteLine(item + " was removed from Inventory");
                                    Console.WriteLine("Here is Something in return: " + npc.Loot.Name);
                                    _TA.Player.Inventory.Add(npc.Loot); //NPC-Loot gets Added to Player Inventory
                                    break;
                                }
                                else
                                {
                                    counter = counter + 1;
                                }
                            }
                        }
                        else
                        {
                            Console.WriteLine(npc.Interactions[1]); //Display Wrong-Item Text
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
 public void TryPassDoor(TextAdventure _TA)
 {
     if (this.IsOpen == true)
     {
         this.PassDor(_TA);
     }
     else
     {
         if (LeadsTo == "FREEDOME")
         {
             Console.WriteLine("This is the Way out you just have to Fight Dr.Marcel and Freedom is yours");
         }
         else
         {
             Console.WriteLine("Leeds to: " + this.LeadsTo);
             if ((LeadsTo == "Entrance Hall") && (IsOpen == false))
             {
                 if (_TA.Player.Inventory.Count > 0)
                 {
                     Console.WriteLine("You need a Key to open the Door");
                     foreach (Item item in _TA.Player.Inventory)
                     {
                         if (item.Name == "key")
                         {
                             _TA.CurrentRoom.SouthDoor.IsOpen = true;
                             Console.WriteLine("You unlocked the Door!");
                             PassDor(_TA);
                             break;
                         }
                     }
                 }
                 else
                 {
                     Console.WriteLine("There are no Items in you Inventory, you need a Key to enter");
                 }
             }
         }
     }
 }
Ejemplo n.º 5
0
        public void FightNPC(TextAdventure _TA)
        {
            Console.WriteLine("Who do you want to attack?");
            string input = Console.ReadLine();

            input = input.ToLower();
            if (Npcs.Count > 0)
            {
                foreach (NPC npc in Npcs)
                {
                    if (input == npc.Name)
                    {
                        //Check if NPC is Dr.Marcel
                        if (input != "dr.marcel")
                        {
                            Console.WriteLine("Attacking " + npc.Name + " would cause even more trouble");
                        }
                        else
                        {
                            Console.WriteLine("Which Weapon do you want to choose: ");
                            foreach (Item item in _TA.Player.Inventory)
                            {
                                Console.Write(item.Name + ", ");
                            }
                            string weapon = Console.ReadLine();
                            weapon = weapon.ToLower();
                            foreach (Item item in _TA.Player.Inventory)
                            {
                                if (weapon == item.Name)
                                {
                                    if (item.IsWeapon)
                                    {
                                        Console.WriteLine(npc.Interactions[2]);
                                        Console.WriteLine("You defeated Dr.Marcel access to Freedome is now yours");
                                        _TA.CurrentRoom.SouthDoor.IsOpen = true;
                                        RemoveNPC(npc);
                                        break;
                                    }
                                    else
                                    {
                                        if (_TA.Player.Health > 0)
                                        {
                                            Console.WriteLine(npc.Interactions[1]);
                                            _TA.Player.Health = _TA.Player.Health - 5;
                                            Console.WriteLine("You got hit by Dr. Marcel!");
                                            Console.WriteLine("Your current Health is: " + _TA.Player.Health + ". Maybe you should Overthink your Strategy");
                                        }
                                        else
                                        {
                                            Console.WriteLine("You lost better Luck next time!");
                                            Console.ReadLine();
                                            _TA.GameStatus = false;
                                        }
                                    }
                                }
                            }
                            break;
                        }
                    }
                    else
                    {
                        Console.WriteLine(npc.Name + " is not here");
                    }
                }
            }
            else
            {
                Console.WriteLine("No Danger in this Room");
            }
        }
Ejemplo n.º 6
0
        private static void LoadGame()
        {
            TextAdventure TA;

            Console.WriteLine("Type the number of the Option you need:");
            Console.WriteLine("1. Start Game");
            Console.WriteLine("2. Quit Game");
            Console.Write(">");
            String input = Console.ReadLine();


            //Game Load
            if (input == "1")
            {
                System.IO.DirectoryInfo xmlPath = new System.IO.DirectoryInfo(@"../../GameBuild/");
                XmlDocument             doc     = new XmlDocument();

                List <Room> rooms = new List <Room>(); //Create Empty List of Rooms
                for (int j = 0; j <= xmlPath.GetFiles().Length - 3; j++)
                {
                    doc.Load(@"../../GameBuild/Room" + (j + 1) + ".xml");

                    //Get all Room Data from XML
                    XmlNodeList xmlRooms       = doc.GetElementsByTagName("Value");
                    XmlNodeList xmlDescription = doc.GetElementsByTagName("Description");

                    //Get all Door Data from XML
                    XmlNodeList xmlDoors     = doc.GetElementsByTagName("Doors");
                    XmlNodeList xmlNorthDoor = doc.GetElementsByTagName("NorthDoor");
                    XmlNodeList xmlSouthDoor = doc.GetElementsByTagName("SouthDoor");
                    XmlNodeList xmlWestDoor  = doc.GetElementsByTagName("WestDoor");
                    XmlNodeList xmlEastDoor  = doc.GetElementsByTagName("EastDoor");

                    //Get all Item Data from XML
                    XmlNodeList xmlItem            = doc.GetElementsByTagName("Item");
                    XmlNodeList xmlItemName        = doc.GetElementsByTagName("ItemName");
                    XmlNodeList xmlItemDescription = doc.GetElementsByTagName("ItemDescription");
                    XmlNodeList xmlItemIsWeapon    = doc.GetElementsByTagName("IsWeapon");

                    //Get all NPC Data from XML
                    XmlNodeList xmlNPC             = doc.GetElementsByTagName("NPC");
                    XmlNodeList xmlNpcName         = doc.GetElementsByTagName("Name");
                    XmlNodeList xmlNpcTalk         = doc.GetElementsByTagName("Talk");
                    XmlNodeList xmlNpcWrongItem    = doc.GetElementsByTagName("WrongItem");
                    XmlNodeList xmlNpcRightItem    = doc.GetElementsByTagName("RightItem");
                    XmlNodeList xmlLootName        = doc.GetElementsByTagName("LootName");
                    XmlNodeList xmlLootDescription = doc.GetElementsByTagName("LootDescription");
                    XmlNodeList xmlLootIsWeapon    = doc.GetElementsByTagName("LootIsWeapon");

                    for (int i = 0; i < xmlRooms.Count; i++)
                    {
                        //Set Data for Room
                        string name        = (xmlRooms[i].InnerXml);
                        string description = xmlDescription[i].InnerXml;

                        //Set Data for Doors in Room
                        Door northDoor = new Door(Convert.ToBoolean(xmlNorthDoor[i].FirstChild.InnerText),
                                                  xmlNorthDoor[i].LastChild.InnerText);
                        Door southDoor = new Door(Convert.ToBoolean(xmlSouthDoor[i].FirstChild.InnerText),
                                                  xmlSouthDoor[i].LastChild.InnerText);
                        Door westDoor = new Door(Convert.ToBoolean(xmlWestDoor[i].FirstChild.InnerText),
                                                 xmlWestDoor[i].LastChild.InnerText);
                        Door eastDoor = new Door(Convert.ToBoolean(xmlEastDoor[i].FirstChild.InnerText),
                                                 xmlEastDoor[i].LastChild.InnerText);

                        //Set Data for Items in Room
                        List <Item> items = new List <Item>();

                        for (int k = 0; k < xmlItem.Count; k++)
                        {
                            string itemName        = xmlItemName[k].InnerXml;
                            string itemDescription = xmlItemDescription[k].InnerXml;
                            bool   itemIsWeapon    = Convert.ToBoolean(xmlItemIsWeapon[k].InnerText);
                            Item   item            = new Item(itemName, itemDescription, itemIsWeapon);
                            items.Add(item);
                        }

                        //Set Data for NPC in Room
                        List <NPC> npcs = new List <NPC>();

                        for (int count = 0; count < xmlNPC.Count; count++)
                        {
                            string npcName = xmlNpcName[count].InnerXml;
                            Item   npcItem = new Item(xmlLootName[count].InnerXml, xmlLootDescription[count].InnerXml, Convert.ToBoolean(xmlLootIsWeapon[count].InnerText));

                            List <string> npcInteractions = new List <string>();
                            string        npcTalk         = xmlNpcTalk[count].InnerXml;
                            string        npcWrongItem    = xmlNpcWrongItem[count].InnerXml;
                            string        npcRightItem    = xmlNpcRightItem[count].InnerXml;
                            npcInteractions.Add(npcTalk);
                            npcInteractions.Add(npcWrongItem);
                            npcInteractions.Add(npcRightItem);

                            npcs.Add(new NPC(npcName, npcItem, npcInteractions));
                        }

                        rooms.Add(new Room(name, description, northDoor, southDoor, westDoor, eastDoor, items, npcs));
                        break;
                    }
                }

                //Set first Room to Start Room
                Room currentRoom = rooms[0];

                //Get Player Elements from XML
                XmlDocument doc2 = new XmlDocument();
                doc2.Load(@"../../GameBuild/Player.xml");
                XmlNodeList xmlPlayerName   = doc2.GetElementsByTagName("Name");
                XmlNodeList xmlPlayerHealth = doc2.GetElementsByTagName("Health");
                XmlNodeList xmlStartText    = doc2.GetElementsByTagName("StartText");
                XmlNodeList xmlEndText      = doc2.GetElementsByTagName("EndText");

                string      playerName      = xmlPlayerName[0].InnerXml;
                int         playerHealth    = int.Parse(xmlPlayerHealth[0].InnerXml);
                List <Item> playerInventory = new List <Item>();
                string      startText       = xmlStartText[0].InnerXml;
                string      endText         = xmlEndText[0].InnerXml;

                Player player = new Player(playerName, playerHealth, playerInventory, startText, endText);

                TA = new TextAdventure(rooms, player, currentRoom); //Create new Object Textadventure with all Data from XML

                //Call StartGame, with new TA Object
                StartGame(TA);
            }
            //Game Quit
            else if (input == "2")
            {
                return; //Ends Game
            }
            else
            {
                Console.WriteLine("Error! Please try again!");
                LoadGame();
            }
        }