/// <summary> /// Creates a new apple or reuses an old apple-object /// if the cache-pool is full /// </summary> /// <param name="position">Coord-object representing the coordinate of the new Apple</param> /// <returns>New or reused Apple-object</returns> public static Apple Create(Coord position) { if (_apples.Count < ApplesCached) { _apples.Add(new Apple(position)); return _apples.Last(); } else { if (_appleToUse >= ApplesCached) _appleToUse = 0; var apple = _apples[_appleToUse++]; apple.Position = position; return apple; } }
/// <summary> /// Generates a new apple based on a Coord-object /// </summary> /// <param name="position">Coord-object representing the position</param> private Apple(Coord position) { Position = position; }