public void Kill(Status killReason) { if (killReason == Status.Alive) { throw new ArgumentException(); } // Clean up from tail up Coord current = Tail; for (;;) { Debug.Assert(world.fields[current.Y, current.X].occupant == FastWorld.Occupant.Snake); Debug.Assert(world.fields[current.Y, current.X].id == index); Direction d = world.fields[current.Y, current.X].direction; world.fields[current.Y, current.X] = new FastWorld.Field(FastWorld.Occupant.Empty); if (current.Equals(Head)) { break; } current = current.Advanced(d); } Status = killReason; }
/// <summary> /// Enumerate snake parts from tail to head. Enumerator only valid without simulating ticks. /// </summary> /// <returns>Enumeration of all parts of this snake</returns> public IEnumerable <Coord> EnumerateParts() { Coord current = Tail; for (;;) { Debug.Assert(world[current].occupant == FastWorld.Occupant.Snake); Debug.Assert(world[current].id == index); yield return(current); if (current == Head) { break; } current = current.Advanced(world[current].direction); } yield break; }