public bool StarveAnimal(string nname) { foreach (Animal a in Records) { if (String.Compare(a.NickName, nname, true) == 0) { switch (a.State) { case State.Full: a.State = State.Hungry; a.Health = Animal.MaxHealth(a.Kind); break; case State.Hungry: a.State = State.Ill; a.Health = Animal.MaxHealth(a.Kind); break; case State.Ill: if (--a.Health <= 0) { a.State = State.Dead; } break; case State.Dead: EraseAnimalIfDead(a.NickName); // Console.WriteLine("Animal was removed: " + a.ToString()); return(true); default: Console.WriteLine("nothing to do with: " + a.ToString()); return(false); } Console.WriteLine("Animal's condicion worsened: " + a.ToString()); return(true); } if (String.Compare(a.NickName, nname, true) == 0) { Console.WriteLine("Animal wasn't cured, because it wasn't ill: " + a.ToString()); return(false); } } Console.WriteLine("Animal not found " + nname); return(false); }
public bool CureAnimal(string nname) { foreach (Animal a in Records) { if (String.Compare(a.NickName, nname, true) == 0 && a.State == State.Ill) { if (++a.Health >= Animal.MaxHealth(a.Kind)) { a.Health = Animal.MaxHealth(a.Kind); a.State = State.Hungry; } Console.WriteLine("Animal was cured: " + a.ToString()); return(true); } if (String.Compare(a.NickName, nname, true) == 0) { Console.WriteLine("Animal wasn't cured, because it wasn't ill: " + a.ToString()); return(false); } } Console.WriteLine("Animal not found " + nname); return(false); }