예제 #1
0
    public void NewGame()
    {
        if (Dead != null)
        {
            StopCoroutine(Dead);
        }
        grid = new CellGrid(Width, Height);
        int startX = Mathf.FloorToInt(Width / 2);
        int startY = Mathf.FloorToInt(Height / 2);

        body         = new SnakeBody(grid.GetGridCell(startX, startY));
        headPosition = new IntVector2(startX, startY);
    }
예제 #2
0
    public void MoveToNewCell()
    {
        switch (NewDirection)
        {
        case Directions.Left:
            headPosition.x -= 1;
            break;

        case Directions.Right:
            headPosition.x += 1;
            break;

        case Directions.Up:
            headPosition.y += 1;
            break;

        case Directions.Down:
            headPosition.y -= 1;
            break;

        default:
            break;
        }
        ;
        CurrentDirection = NewDirection;
        Cell newCell = grid.GetGridCell(headPosition.x, headPosition.y);

        switch (newCell.CheckCell())
        {
        case Cell.CellContent.Empty:
            body.MovetoNewCell(newCell);
            break;

        case Cell.CellContent.Food:
            body.AteFood(newCell);
            break;

        default:
            isAlive = false;
            Dead    = StartCoroutine(Vis.FlashDead(body.Head));
            break;
        }
    }