public void AddObject(WorldObject obj) { this.allObjects.Add(obj); IControllable objAsControllable = obj as IControllable; if (objAsControllable != null) { this.controllables.Add(objAsControllable); } IResource objAsResource = obj as IResource; if (objAsResource != null) { this.resources.Add(objAsResource); } //IGatherer objAsGatherer = obj as IGatherer; //if (objAsGatherer != null) //{ // this.gatherers.Add(objAsGatherer); //} //IFighter objAsFighter = obj as IFighter; //if (objAsFighter != null) //{ // this.fighters.Add(objAsFighter); //} }
private void HandleBattle(IFighter attacker, WorldObject defender) { var defenderAsFighter = defender as IFighter; int defenderDefensePoints = 0; if (defenderAsFighter != null) { defenderDefensePoints = defenderAsFighter.DefensePoints; } int damage = attacker.AttackPoints - defenderDefensePoints; if (damage < 0) { damage = 0; } if (damage > defender.HitPoints) { damage = defender.HitPoints; } defender.HitPoints -= damage; Console.WriteLine("{0} attacked {1} and did {2} damage", attacker, defender, damage); }