Example #1
0
        public override bool Execute(Hero hero, List <string> args)
        {
            if (args != null && args.Count == 2 && args[1].Length > 0)
            {
                Directions dir;
                string     name = args[1].Substring(0, 1).ToUpper() + args[1].Substring(1).ToLower();
                name = name.Replace("-", "");

                if (Enum.TryParse(name, out dir) || DirectionsHelper.TryConvertAbbr(name, out dir))
                {
                    if (hero.Move(dir))
                    {
                        hero.Logger.Append(hero.CurrTile);
                    }
                    else
                    {
                        hero.Logger.Append("You can't go that way.\n");
                    }
                }
                else
                {
                    hero.Logger.Append("The direction ");
                    hero.Logger.Append(name);
                    hero.Logger.Append(" is not valid!\n");
                }

                return(true);
            }

            return(false);
        }
Example #2
0
        public override bool Execute(object obj, List <string> args)
        {
            if (obj == null || obj.GetType() != typeof(Hero))
            {
                return(false);
            }

            Hero hero = (Hero)obj;

            if (args != null && args.Count == 2 && args[1].Length > 0)
            {
                Directions dir;
                string     name = args[1].Substring(0, 1).ToUpper() + args[1].Substring(1).ToLower();
                name = name.Replace("-", "");

                if (Enum.TryParse(name, out dir) || DirectionsHelper.TryConvertAbbr(name, out dir))
                {
                    if (hero.Move(dir))
                    {
                        hero.Logger.WriteLine(hero.CurrTile);
                    }
                    else
                    {
                        hero.Logger.WriteLine("You can't go that way.");
                    }
                }
                else
                {
                    hero.Logger.Write("The direction ");
                    hero.Logger.Write(name);
                    hero.Logger.WriteLine(" is not valid!");
                }

                return(true);
            }

            return(false);
        }