/// <summary> /// If snake moves then check is feed is near. If yes then dispatch FeedEatenEvent. /// </summary> private void OnSnakeMove(EventArgs args) { Type type = _foodSpawningController.IsFeedAvailable(_snakeParts.head.transform.position); if (type == null) { return; } _eventController.Dispatch <FeedEatenEvent>(new FeedEatenEventArgs(type)); }
/// <summary> /// Adds score points when snake has eaten feed. /// </summary> private void OnFeedEaten(EventArgs args) { FeedEatenEventArgs feedArgs = args as FeedEatenEventArgs; if (feedArgs.eatenFeedType == typeof(NormalFeed)) { score += 1; } else if (feedArgs.eatenFeedType == typeof(SpecialFeed)) { score += 10; } _eventController.Dispatch <ScoreChangedEvent>(new ScoreChangedEventArgs(score)); }
/// <summary> /// Moves snake. /// </summary> private void ProcessMovement() { Move(CheckMoveDir()); _eventController.Dispatch <SnakeMoveEvent>(new SnakeMoveEventArgs(_snakeParts)); }