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); } }
// 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>(); }
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); }
void collisionSnakeHead(SnakeLogic s) { if (s == null || m_dead) { return; } if (s.isLastNode()) { s.kill(); } else { onDie(); } }
protected override void onAwake() { m_instance = this; m_snake = FindObjectOfType <SnakeLogic>(); }