public bool raiseCost(EnemyUnit unit, float amount) { Debug.Log("Raising the price of " + unit.name + " by " + amount); if (table.ContainsKey(unit.name)) { CreditTableEntry target = new CreditTableEntry(unit); table.TryGetValue(unit.name, out target); target.alterCost(amount); return(true); } return(false); }
public bool addEntry(EnemyUnit unit) { Debug.Log("Adding " + unit.name + " the credit table."); if (table.ContainsKey(unit.name)) { throw(new Exception("Already in table!!!")); return(false); } CreditTableEntry newEntry = new CreditTableEntry(unit); table.Add(unit.name, newEntry); return(true); }
//Returns negative 1 if failure // public float lookUp(EnemyUnit unit){ public float lookUp(String name) { if (table.ContainsKey(name)) { CreditTableEntry target = new CreditTableEntry(5f); table.TryGetValue(name, out target); return(target.cost); } else { return(-1f); } }
public bool cheapen(EnemyUnit unit, float amount) { if (table.ContainsKey(unit.name)) { CreditTableEntry target = new CreditTableEntry(unit); table.TryGetValue(unit.name, out target); target.alterCost(-amount); Debug.Log("Reducing the price of " + unit.name + " by " + amount + " it now costs " + lookUp(unit.name)); return(true); } return(false); }
void Start() { table = new Dictionary <String, CreditTableEntry> (); // Debug.Log ("Started the credit table."); //Debug.Log (table.ToString()); table.Add("Goblin", new CreditTableEntry(25f)); CreditTableEntry dummy = new CreditTableEntry(35f); //Debug.Log(table.TryGetValue(("Goblin"),out dummy )); displayTable(); //TESTING cheapen and raiseCost table["Goblin"].alterCost(10); //Debug.Log ("RAISING THE PRICE OF GOBLIN BY 10, EXPECT 35:" + table ["Goblin"].cost); table["Goblin"].alterCost(-20); //Debug.Log ("LOWERING THE PRICE OF GOBLIN BY 20, EXPECT 15:" + table ["Goblin"].cost); //TESTING LOOKUP //Debug.Log("Lookup should yield 15: " + lookUp("Goblin")); }