public override GlyphNode Action(Spell spell, Glyph glyphOne, Glyph glyphTwo) { GlyphNode newGlyphNode = new GlyphNode(); newGlyphNode.glyph = Combination(glyphOne, glyphTwo); return(newGlyphNode); }
public SpellLinkedList() //Constructor for SpellLinkedLists { head = new GlyphNode(); tail = new GlyphNode(); length = 0; genCount = 0; Console.WriteLine("spellLinkedList Created!"); }
public void addEndNode(string glyphName) //Add head first, then tail, then adds nodes to end and they become the new tail { if (head.glyph == null) //Sets the head if there isn't one { head = new GlyphNode(glyphName); head.prev = null; head.next = null; length = 1; if (glyphName == "combinus") { genCount++; } Console.WriteLine("Head is now: {0}", head.glyph.name); } else if (tail.glyph == null) //Sets the tail if there isn't one { tail = new GlyphNode(glyphName); head.next = tail; tail.prev = head; tail.next = null; length = 2; if (glyphName == "combinus") { genCount++; } Console.WriteLine("Head is: {0} Tail is now: {1}", head.glyph.name, tail.glyph.name); } else //Add an end node, this new node is the new tail { GlyphNode newNode = new GlyphNode(glyphName); //Add a node of name glyphName newNode.prev = tail; newNode.next = null; tail.next = newNode; tail = newNode; length++; if (glyphName == "combinus") { genCount++; } // Combinus means a new node will be created from the previous two if (newNode.glyph != null) { Console.WriteLine("GlyphNode added of piece: {0}!", newNode.glyph.name); } } }
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++; } } }
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); }
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; } } }