예제 #1
0
        public void doAction(string input)
        {
            Console.WriteLine();
            try
            {
                if (Barkeeper.Isalive == false)
                {
                    OutdoorArea.Available = true;
                }
                if (input == "n" || input == "north")
                {
                    if (Player.Location.Northexit != null && (Player.Location.Northexit.Available == true))
                    {
                        Player.Location = Player.Location.Northexit;
                        Character.getCharacterLocation(Player);
                        Room.getCharacterlist(Player.Location);
                        Room.getRoominventory(Player.Location);
                    }
                    else
                    {
                        Console.WriteLine("There is no way! Choose another one!");
                    }
                }
                if (input == "e" || input == "east")
                {
                    if (Player.Location.Eastexit != null && (Player.Location.Eastexit.Available == true))
                    {
                        Player.Location = Player.Location.Eastexit;
                        Character.getCharacterLocation(Player);
                        Room.getCharacterlist(Player.Location);
                        Room.getRoominventory(Player.Location);
                    }
                    else
                    {
                        Console.WriteLine("There is no way! Choose another one!");
                    }
                }
                if (input == "s" || input == "south")
                {
                    if (Player.Location.Southexit != null && (Player.Location.Southexit.Available = true))
                    {
                        Player.Location = Player.Location.Southexit;
                        Character.getCharacterLocation(Player);
                        Room.getCharacterlist(Player.Location);
                        Room.getRoominventory(Player.Location);
                    }
                    else
                    {
                        Console.WriteLine("There is no way! Choose another one!");
                    }
                }

                if (input == "w" || input == "west")
                {
                    if (Player.Location.Westexit != null && (Player.Location.Westexit.Available == true))
                    {
                        Player.Location = Player.Location.Westexit;
                        Character.getCharacterLocation(Player);
                        Room.getCharacterlist(Player.Location);
                        Room.getRoominventory(Player.Location);
                    }
                    else
                    {
                        Console.WriteLine("There is no way! Choose another one!");
                    }
                }

                if (input == "help" || input == "h")
                {
                    Console.WriteLine("'l' or 'look':       Shows you the room and its exits");
                    Console.WriteLine("'lookat X':         Gives you information about a specific Character");
                    Console.WriteLine("'t' or 'take' <item>:    Attempts to pick up an item.");
                    Console.WriteLine("'d' or 'drop':       Attemps to drop an item.");
                    Console.WriteLine("'use '<item>:             Attempts to use an item.");
                    Console.WriteLine("'i' or 'inventory':      Allows you to see the items in your inventory.");
                    Console.WriteLine("'q' or 'quit':       Quits the game.");
                    Console.WriteLine();
                    Console.WriteLine("Directions can be input as either the full word, or the abbriviation, e.g. 'north or n'");
                    return;
                }

                if (input == "i" || input == "inventory")
                {
                    if (Player.Characterinventory.Count() > 0)
                    {
                        Console.WriteLine("Your inventory contains the following Items: ");
                        Character.getCharacterinventory(Player);
                        Console.WriteLine();
                        return;
                    }
                    else
                    {
                        Console.WriteLine("Your inventory contains no Items.");
                    }
                }

                if (input.StartsWith("t "))
                {
                    string chooseditem = input.Substring(2, input.Length - 2);
                    Character.take(Player.Location, Player, chooseditem);
                }
                if (input.StartsWith("take "))
                {
                    string chooseditem = input.Substring(5, input.Length - 5);
                    Character.take(Player.Location, Player, chooseditem);
                }
                if (input.StartsWith("d "))
                {
                    string chooseditem = input.Substring(2, input.Length - 2);
                    Character.drop(Player.Location, Player, chooseditem);
                }
                if (input.StartsWith("drop "))
                {
                    string chooseditem = input.Substring(5, input.Length - 5);
                    Character.drop(Player.Location, Player, chooseditem);
                }
                if (input == "t" || input == "take")
                {
                    Console.Write("Choose the Item you want to pick up : 't' or 'take' <item>");
                }

                if (input == "l" || input == "look")
                {
                    Console.WriteLine(Player.Location.Describtion);
                    Console.WriteLine("You see:");
                    Room.getCharacterlist(Player.Location);
                    Room.getRoominventory(Player.Location);
                    Room.getExitDescribtion(Player);
                }
                if (input.StartsWith("use "))
                {
                    string chooseditem = input.Substring(4, input.Length - 4);
                    Character.use(Player, chooseditem);
                }

                if (input.StartsWith("attack "))
                {
                    string choosedcharacter = input.Substring(7, input.Length - 7);
                    Character.attack(Player, choosedcharacter);
                }

                if (input.StartsWith("talkto "))
                {
                    string choosedcharacter = input.Substring(7, input.Length - 7);
                    Character.talkto(Player, choosedcharacter);
                }

                if (input.StartsWith("lookat "))
                {
                    string choosedcharacter = input.Substring(7, input.Length - 7);
                    Character.lookat(Player, choosedcharacter);
                }
            }
            catch (ArgumentException)
            {
                Console.WriteLine("Invalid command. Type 'h' or 'help to get the command list.");
            }
        }
예제 #2
0
        public void doAction(string input)
        {
            Console.WriteLine();

            if (Lady.Dialougeline > 1)
            {
                Random rnd = new Random();
                Ladysboyfriend.IsAgressive = true;
                //Ladysboyfriend.Location.CharacterList.Remove(Ladysboyfriend);
                //Roomlist[rnd.Next(Roomlist.Count)].CharacterList.Add(Ladysboyfriend);
            }
            if (Penn.Dialougeline > 0)
            {
                Penn.IsAgressive = true;
            }
            if (Man.Isalive == false)
            {
                Growroom.Available = true;
            }
            foreach (var item in Player.Characterinventory)
            {
                if (item.Name == "Herbs")
                {
                    Wayhome.Available = true;
                }
            }
            foreach (var character in Player.Location.CharacterList)
            {
                if (character.IsAgressive == true)
                {
                    Character.getattack(Player, character);
                }
            }

            try
            {
                string pattern     = @"([a-zA-Z]+) ";
                Match  firststring = Regex.Match(input, pattern);

                if (input == "n" || input == "north")
                {
                    if (Player.Location.Northexit != null && (Player.Location.Northexit.Available == true))
                    {
                        Player.Location = Player.Location.Northexit;
                        Character.getCharacterLocation(Player);
                        Room.getCharacterlist(Player.Location);
                        Room.getRoominventory(Player.Location);
                    }
                    else
                    {
                        Console.WriteLine("There is no way! Choose another one!");
                    }
                }
                if (input == "e" || input == "east")
                {
                    if (Player.Location.Eastexit != null && (Player.Location.Eastexit.Available == true))
                    {
                        Player.Location = Player.Location.Eastexit;
                        Character.getCharacterLocation(Player);
                        Room.getCharacterlist(Player.Location);
                        Room.getRoominventory(Player.Location);
                    }
                    else
                    {
                        Console.WriteLine("There is no way! Choose another one!");
                    }
                }
                if (input == "s" || input == "south")
                {
                    if (Player.Location.Southexit != null && (Player.Location.Southexit.Available = true))
                    {
                        Player.Location = Player.Location.Southexit;
                        Character.getCharacterLocation(Player);
                        Room.getCharacterlist(Player.Location);
                        Room.getRoominventory(Player.Location);
                    }
                    else
                    {
                        Console.WriteLine("There is no way! Choose another one!");
                    }
                }
                if (input == "w" || input == "west")
                {
                    if (Player.Location.Westexit != null && (Player.Location.Westexit.Available == true))
                    {
                        Player.Location = Player.Location.Westexit;
                        Character.getCharacterLocation(Player);

                        Room.getCharacterlist(Player.Location);
                        Room.getRoominventory(Player.Location);
                    }
                    else
                    {
                        Console.WriteLine("There is no way! Choose another one!");
                    }
                }

                if (input == "help" || input == "h")
                {
                    Console.WriteLine("'l' or 'look' ---------> Shows you the room and its exits");
                    Console.WriteLine("'t' or 'take' <item>: -> Attempts to pick up an item.");
                    Console.WriteLine("'d' or 'drop': --------> Attempts to drop an item.");
                    Console.WriteLine("'u' or 'use' <item>: --> Attempts to use an item.");
                    Console.WriteLine("'i' or 'inventory': ---> Allows you to see the items in your inventory.");
                    Console.WriteLine("'q' or 'quit': --------> Quits the game.");
                    Console.WriteLine("'a' or 'attack' <char>:  Attempts to attack a character");
                    Console.WriteLine("'lookat' <x>: ---------> Gives you information about a specific item in your inventory or your current room,\n " +
                                      "                        either more information about a character in your current room. ( <x> = <char> or <item> )");
                    Console.WriteLine("'talkto' <character> --> Attempts you to talk to characters.");
                    Console.WriteLine();
                    Console.WriteLine("Directions can be input as either the full word, or the abbriviation, e.g. 'north' or 'n'");
                    return;
                }

                if (input == "i" || input == "inventory")
                {
                    if (Player.Characterinventory.Count() > 0)
                    {
                        Console.WriteLine("Your inventory contains the following Items: ");
                        Character.getCharacterinventory(Player);
                        Console.WriteLine();
                        return;
                    }
                    else
                    {
                        Console.WriteLine("Your inventory contains no Items.");
                    }
                }
                //if (input.StartsWith("a "))
                if (input.StartsWith("t ") || input.StartsWith("take "))
                {
                    string chooseditem = input.Substring(firststring.Value.Length, input.Length - firststring.Value.Length);
                    Character.take(Player.Location, Player, chooseditem);
                }
                if (input.StartsWith("d ") || input.StartsWith("drop "))
                {
                    string chooseditem = input.Substring(firststring.Value.Length, input.Length - firststring.Value.Length);
                    Character.drop(Player.Location, Player, chooseditem);
                }
                if (input == "t" || input == "take")
                {
                    Console.Write("Choose the Item you want to pick up: 't' or 'take' <item>");
                }

                if (input == "l" || input == "look")
                {
                    Console.Write(Player.Location.Name + ": ");
                    Console.WriteLine(Player.Location.Describtion);
                    Room.getExitDescribtion(Player);
                    Console.WriteLine("You see");
                    Room.getCharacterlist(Player.Location);
                    Room.getRoominventory(Player.Location);
                }
                if (input.StartsWith("use ") || input.StartsWith("u "))
                {
                    string chooseditem = input.Substring(firststring.Value.Length, input.Length - firststring.Value.Length);;
                    Character.use(Player, chooseditem);
                }
                if (input.StartsWith("a ") || input.StartsWith("attack "))
                {
                    string choosedcharacter = input.Substring(firststring.Value.Length, input.Length - firststring.Value.Length);
                    Character.attack(Player, choosedcharacter);
                }
                if (input.StartsWith("lookat "))
                {
                    string choice = input.Substring(firststring.Value.Length, input.Length - firststring.Value.Length);
                    Character.lookat(Player, choice);
                }
                if (input.StartsWith("talkto "))
                {
                    string choosedcharacter = input.Substring(firststring.Value.Length, input.Length - firststring.Value.Length);
                    Character.talkto(Player, choosedcharacter);
                }
            }


            //if (Player.Location)
            catch (ArgumentException)
            {
                Console.WriteLine("Invalid command. Type 'h' or 'help to get the command list.");
            }
        }