Пример #1
0
        private Move selectMoveRecur(Character c, MoveSet m, Stack <MoveSet> prev)
        {
            Dictionary <int, MoveTreeNode> objectMapping;
            string       input;
            int          entered;
            MoveTreeNode selected;

            while (true)
            {
                Console.WriteLine("What should {0} do?", c.Name);
                objectMapping = printMoves(m, prev);
                input         = Console.ReadLine().Trim();
                if (Int32.TryParse(input, out entered))
                {
                    if (entered == 0)
                    {
                        MoveSet last = prev.Pop();
                        return(selectMoveRecur(c, last, prev));
                    }
                    else if (objectMapping.TryGetValue(entered, out selected))
                    {
                        if (selected is Move)
                        {
                            return((Move)selected);
                        }
                        else
                        {
                            prev.Push(m);
                            return(selectMoveRecur(c, (MoveSet)selected, prev));
                        }
                    }
                }
                Console.WriteLine("incorrect entry, try again");
            }
        }
Пример #2
0
 public Character(MoveProvider mprovider, MoveSet mset, string name, Dictionary <string, int> stats)
 {
     _mprovider = mprovider;
     _mset      = mset;
     _hp        = new DepleteableStat(stats["hp"]);
     _strength  = new Stat(stats["strength"]);
     _speed     = new Stat(stats["speed"]);
     _vitality  = new Stat(stats["vitality"]);
     _name      = name;
 }
Пример #3
0
        public Character buildFromXmlNode(XmlNode root, MoveProvider provider = null)
        {
            provider = provider == null ? new NullMoveProvider() : provider;
            string  name     = root["name"].InnerText;
            MoveSet moveroot = XmlbuildMoveSet(root["moves"], name);
            Dictionary <string, int> stats = new Dictionary <string, int>();

            stats["speed"]    = int.Parse(root["speed"].InnerText);
            stats["strength"] = int.Parse(root["strength"].InnerText);
            stats["vitality"] = int.Parse(root["vitality"].InnerText);
            stats["hp"]       = int.Parse(root["hp"].InnerText);
            return(new Character(provider, moveroot, name, stats));
        }
Пример #4
0
        MoveSet XmlbuildMoveSet(XmlNode root, string rootname = "")
        {
            var rootset = new MoveSet(rootname);

            foreach (XmlNode node in root.ChildNodes)
            {
                if (node.Name == "moves" || node.Name == "movset")
                {
                    var text    = node.Attributes["name"].InnerText;
                    var newroot = XmlbuildMoveSet(node, text);
                    rootset.Add(newroot);
                }
                else
                {
                    var newmove = MoveBuilder.buildFromXml(node.InnerText);
                    rootset.Add(newmove);
                }
            }
            return(rootset);
        }
Пример #5
0
        private Dictionary <int, MoveTreeNode> printMoves(MoveSet mset, Stack <MoveSet> prev)
        {
            Dictionary <int, MoveTreeNode> mapping = new Dictionary <int, MoveTreeNode>();
            int    opt    = 1;
            string leadin = "";

            foreach (var prevset in prev)
            {
                Console.WriteLine("{0}{1}", leadin, prevset.Name);
                leadin += " ";
            }
            foreach (var item in mset.Children)
            {
                Console.WriteLine("{0}[{1}] {2}", leadin, opt, item.HasChildren() ? $">{item.Name}" : item.Name);
                mapping[opt] = item;
                opt++;
            }
            if (prev.Count != 0)
            {
                Console.WriteLine("{0}[0] Back...", leadin);
            }
            return(mapping);
        }