コード例 #1
0
ファイル: Snake.cs プロジェクト: XuYan/Greedy-Snake
        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);
        }
コード例 #2
0
        FruitDisappearEventArgs GetFruitDisappearEventArgs()
        {
            FruitDisappearEventArgs args = new FruitDisappearEventArgs();

            args.fruitCoordinateArg = FruitCoordinate;

            return(args);
        }
コード例 #3
0
        void OnFruitDisappeared(FruitDisappearEventArgs args)
        {
            EventHandler <FruitDisappearEventArgs> handler = FruitDisappearHandler;

            if (handler != null)
            {
                handler(this, args);
            }
        }
コード例 #4
0
 /// <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();
 }