public void MyAppleTest()
        {
            SnakeLogic appleLogic = new SnakeLogic();

            int fieldSize = Snake.GameField.SIZE;
            int dotSize   = Snake.GameField.DOT_SIZE;

            appleLogic.createApple(fieldSize, dotSize);

            int currentX = appleLogic.getAppleX;
            int currentY = appleLogic.getAppleY;

            bool isXTrue = false;
            bool isYTrue = false;

            if (currentX >= dotSize && currentX <= (fieldSize - dotSize))
            {
                isXTrue = true;
            }

            if (currentY >= dotSize && currentY <= (fieldSize - dotSize))
            {
                isYTrue = true;
            }

            if (!(isXTrue && isYTrue))
            {
                // ќшибка
                Assert.Fail("Error has been detected! Apple coordinates: X = " + currentX + " Y = " + currentY);
            }
        }
Exemple #2
0
    // Use this for initialization
    void Start()
    {
        int x = (int)Random.Range(borderLeft.position.x + 2, borderRight.position.x - 2);
        int y = (int)Random.Range(borderTop.position.y - 2, borderBottom.position.y + 2);

        Instantiate(foodPrefab, new Vector2(x, y), Quaternion.identity);
        foodSpawned = true;

        InvokeRepeating("SpawnFood", .5f, .5f);
        sl = Snake.GetComponent <SnakeLogic>();
    }
Exemple #3
0
    private void Start()
    {
        local.init("local");
        snakeLogic = new SnakeLogic(local.general.snake.count);
        snakeLogic.RegisterHandler(ChangePos, SnakeGrow);

        GetComponent <Transform>().position = new Vector3(_x, _y, _z);

        for (int i = 0; i < local.general.snake.count; i++)
        {
            snakeLogic.SnakeBody.Add(transform.GetChild(i));
        }

        Grid.UpdateGrid3D(this);
    }
Exemple #4
0
    void collisionSnakeHead(SnakeLogic s)
    {
        if (s == null || m_dead)
        {
            return;
        }

        if (s.isLastNode())
        {
            s.kill();
        }
        else
        {
            onDie();
        }
    }
Exemple #5
0
 protected override void onAwake()
 {
     m_instance = this;
     m_snake    = FindObjectOfType <SnakeLogic>();
 }