Ejemplo n.º 1
0
        public static SpellLinkedList parseSpell(string spellString)
        {
            SpellLinkedList spell = new SpellLinkedList();

            char[]   delimiters = { ' ', '\n', '\t' };
            string[] words      = spellString.Split(delimiters);

            foreach (string s in words)
            {
                spell.addEndNode(s);
            }
            return(spell);
        }
Ejemplo n.º 2
0
        static void Main()
        {
            String          spellString = getSpell();
            SpellLinkedList spell       = parseSpell(spellString);

            printSpell(spell);
            Spell mySpell = new Spell(spell);

            Console.WriteLine("Final Spell");
            mySpell.printSpell();

            Console.WriteLine("Press any key to exit...");
            //Console.ReadKey();
        }
Ejemplo n.º 3
0
 static void printSpell(SpellLinkedList spell)
 {
     if (spell.head.glyph == null)
     {
         Console.WriteLine("Spell is empty");
     }
     else
     {
         GlyphNode iter = spell.head;
         int       i    = 0;
         while (i < spell.length)
         {
             iter.printNode(i);
             iter = iter.next;
             i++;
         }
     }
 }
Ejemplo n.º 4
0
        public static string printSpell(SpellLinkedList spell)
        {
            string returnString = "";

            if (spell.head.glyph == null)
            {
                Console.WriteLine("Spell is empty");
            }
            else
            {
                GlyphNode iter = spell.head;
                int       i    = 0;
                while (i < spell.length)
                {
                    returnString += iter.printNode(i) + "\n";
                    iter          = iter.next;
                    i++;
                }
            }
            return(returnString);
        }
Ejemplo n.º 5
0
        public Spell(SpellLinkedList spellLinkedList)                                                       //Spells are created from spellLinkedLists, iterating through nodes
        {
            manaCost    = 0;
            offPower    = 0;
            defPower    = 0;
            nodeCount   = 0;
            spellType   = null;
            target      = null;
            velocity    = 0;
            description = new String[spellLinkedList.length + spellLinkedList.genCount];
            GlyphNode currentGlyph = spellLinkedList.head;

            while (currentGlyph != null)                                                                    //Iterates through spell until it has hit all nodes
            {
                if (currentGlyph.glyph.type == 0)                                                           //If the node contains an element change: manaCost, spellType, offPower, defPower
                {
                    manaCost += currentGlyph.glyph.manaCost;
                    spellType = currentGlyph.glyph.name;
                    offPower  = currentGlyph.glyph.offPower;
                    defPower  = currentGlyph.glyph.defPower;
                    if (currentGlyph.glyph.ID < 10)
                    {
                        description[nodeCount] = currentGlyph.glyph.description;
                    }
                    nodeCount++;
                    currentGlyph = currentGlyph.next;
                    printSpell();
                }
                else if (currentGlyph.glyph.type == 1)                                                      //If the node contains an action
                {
                    ActionGlyph tempGlyph = (ActionGlyph)currentGlyph.glyph;
                    if (tempGlyph.numArgs == 0)                                                             //Action with 0 arguments, just changes spell values, does not return a node
                    {
                        tempGlyph.Action(this);                                                             //Interact with the spell
                        description[nodeCount] = currentGlyph.glyph.description;
                        nodeCount++;
                        currentGlyph = currentGlyph.next;                                                   //Become the next node
                    }
                    else
                    {
                        GlyphNode newGlyph = new GlyphNode();
                        if (tempGlyph.numArgs == 1)                                                         //Action with 1 argument
                        {
                            newGlyph = tempGlyph.Action(this, currentGlyph.prev.glyph);                     //Perform action
                            if (newGlyph == null)
                            {
                                break;
                            }
                            newGlyph.prev = currentGlyph.prev.prev;                                         //If a node is returned, put it inside the spellLinkedList
                        }

                        if (tempGlyph.numArgs == 2)                                                                   //Action with 2 arguments
                        {
                            newGlyph = tempGlyph.Action(this, currentGlyph.prev.glyph, currentGlyph.prev.prev.glyph); //Perform action
                            if (newGlyph == null)
                            {
                                break;
                            }
                            newGlyph.prev = currentGlyph.prev.prev.prev;                                    //If a node is returned, put it inside the spellLinkedList
                        }
                        if (newGlyph.prev != null)
                        {
                            newGlyph.prev.next = newGlyph;
                        }
                        else
                        {
                            spellLinkedList.head = newGlyph;
                        }
                        newGlyph.next = currentGlyph.next;
                        if (newGlyph.next != null)
                        {
                            newGlyph.next.prev = newGlyph;
                        }
                        else
                        {
                            spellLinkedList.tail = newGlyph;
                        }
                        description[nodeCount] = currentGlyph.glyph.description;
                        nodeCount++;
                        currentGlyph = newGlyph;                                                            //CurrentGlyph becomes the returned glyph
                    }
                }
                else if (currentGlyph.glyph.type == 2)                                                      //If the glyph contains a Shape
                {
                    shape = currentGlyph.glyph.name;
                    description[nodeCount] = String.Format("You form it into the shape of a {0}", shape);
                    nodeCount++;
                    currentGlyph = currentGlyph.next;
                }
                else if (currentGlyph.glyph.type == 3)                                                      //If the glyph contains a Target
                {
                    target = currentGlyph.glyph.name;
                    description[nodeCount] = String.Format("and send it towards {0}", target);
                    nodeCount++;
                    currentGlyph = currentGlyph.next;
                }
            }
        }