Example #1
0
 public void ResetState()
 {
     if (currentState == swimmingState)
     {
         CurtailSnakeBody();
     }
     CurrentState = normalState;
 }
Example #2
0
        public void InitializeSnake()
        {
            _shouldStop = false;
            body.Clear();
            directionChangeOps.Clear();

            body.Enqueue(gameConsole.GetCoordinate(10, 1));
            body.Enqueue(gameConsole.GetCoordinate(10, 2));
            body.Enqueue(gameConsole.GetCoordinate(10, 3));
            direction = Direction.Right;

            normalState   = new NormalState(this);
            swimmingState = new SwimmingState(this);
            breakingState = new BreakingState(this);
            fanaticState  = new FanaticState(this);

            ResetState();

            PaintSnake(Color.Black);

            gameConsole.UpdateSnakeLength(body.Count());
        }
Example #3
0
        void ChangeState(FruitType fruitType)
        {
            switch (fruitType)
            {
            case FruitType.Strawberry:
                CurrentState = fanaticState;
                break;

            case FruitType.Banana:
                CurrentState = breakingState;
                break;

            case FruitType.Blueberry:
                CurrentState = swimmingState;
                break;

            default:
                // When an orange is eaten, state shouldn't change.
                // Snake color needs to remain
                break;
            }
        }