void EatFruit(Coordinate next_HeadCoordinate) { Fruit fruit = gameConsole.fruitGenerator.GetFruitFromCoordinate(next_HeadCoordinate); next_HeadCoordinate.ResetCoordinate(); IncludeHead(next_HeadCoordinate); ChangeState(fruit.FruitType); if (!fruit.FruitType.shouldSnakeGrow()) { ExcludeTail(); } else { gameConsole.UpdateSnakeLength(body.Count()); } fruit.StopRunningTimers(); FruitDisappearEventArgs args = new FruitDisappearEventArgs(); args.fruitCoordinateArg = next_HeadCoordinate; gameConsole.fruitGenerator.GenerateNewFruit(this, args); }
FruitDisappearEventArgs GetFruitDisappearEventArgs() { FruitDisappearEventArgs args = new FruitDisappearEventArgs(); args.fruitCoordinateArg = FruitCoordinate; return(args); }
void OnFruitDisappeared(FruitDisappearEventArgs args) { EventHandler <FruitDisappearEventArgs> handler = FruitDisappearHandler; if (handler != null) { handler(this, args); } }
/// <summary> /// Generate a new fruit on map everytime a fruit disappears /// </summary> public void GenerateNewFruit(object sender, FruitDisappearEventArgs args) { RemoveMapping(args.fruitCoordinateArg); // Remove old fruit from coordinate-fruit mapping fruitWaitEvent.Set(); }