public static int CompareByAttack(Unit a, Unit b) { if (a.Attack > b.Attack) { return -1; } else if (a.Attack < b.Attack) { return 1; } else { return a.Name.CompareTo(b.Name); } }
public IEnumerable<Unit> GetTop(int count) { var bottom = new Unit { Attack = 1000, Type = "nqma", Name = "test" }; var range = this.productsByAttack.RangeFrom(bottom, fromInclusive: true); return this.ApplyOrdering(range.Take(count), count); }
private int Comparison(Unit a, Unit b) { return b.Attack - a.Attack; }
public bool AddUnit(string unitName, string type, string attack) { if (this.productsMapByName.ContainsKey(unitName)) { return false; } var unit = new Unit { Name = unitName, Attack = int.Parse(attack), Type = type }; if (!this.mapByType.ContainsKey(unit.Type)) { this.mapByType[type] = new List<Unit>(); } this.productsMapByName.Add(unit.Name, unit); this.mapByType[unit.Type].Add(unit); this.productsByAttack.Add(unit); return true; }