Exemplo n.º 1
0
 public void AddSnake(Snake snake)
 {
     AddGameObject(snake.GetHead());
     foreach (Tail tail in snake.GetTail())
     {
         AddGameObject(tail);
     }
 }
Exemplo n.º 2
0
        public bool Tick(Snake snake, Fruit fruit)
        {
            if (snake.moveStatus is MoveStatus.Stopping) return false;
            TypeVector needSave = TypeVector.Down;
            bool need = false;
            while (snake.StackVectors.Count > 0)
            {
                TypeVector vector = snake.StackVectors.Pop();
                if (!snake != vector)
                {
                    snake.currentVector = vector;
                    break;
                }
                need = true;
                needSave = vector;
            }
            snake.StackVectors.Clear();

            if (need)
                snake.StackVectors.Push(needSave);
            

            if (snake.IsObstecle(this))
            {
                return true;
            }
            
            snake.Move(this);
            AddSnake(snake);
            if (snake.IsFruit(fruit))
            {
                _score += 10;
                if (snake.speed > 100) snake.UpSpeed();
                snake.GetTail().Add(snake.GetTail().Count is 0
                    ? new Tail(snake.GetHead().GetCell())
                    : new Tail(snake.GetTail().Last().GetCell()));
                do
                {
                    fruit.NewPosition(this);
                } while (fruit.GetCell().obj != null);
                AddGameObject(fruit);
            }
            Render();
            return false;
        }