Ejemplo n.º 1
0
    bool deform()
    {
        int [,] ns = curRock.shape.Clone() as int[, ];
        int t;

        for (int i = 0; i != ns.GetLength(0); ++i)
        {
            //rotate 90 degrees
            t        = ns[i, 0];
            ns[i, 0] = -ns[i, 1];
            ns[i, 1] = t;
        }
        for (int i = 0; i != ns.GetLength(0); ++i)
        {
            int ny = curRock.originY + ns[i, 1];
            int?v  = field.checkValid(curRock.originX + ns[i, 0], ny);
            if (v != (int)FieldType.Empty && ny < field_row)
            {
                return(false);
            }
        }
        curRock.shape = ns;
        moveRockTo(curRock, curRock.originX, curRock.originY);
        return(true);
    }
Ejemplo n.º 2
0
    GameState ClimbSnake()
    {
        timeline += Time.deltaTime;
        if (timeline > time_interval)
        {
            timeline -= time_interval;

            int nx = 0, ny = 0;
            switch (snake.ori)
            {
            case SnakeStruct.Orientaion.Up:         ny = 1; break;

            case SnakeStruct.Orientaion.Down:       ny = -1; break;

            case SnakeStruct.Orientaion.Left:       nx = -1; break;

            case SnakeStruct.Orientaion.Right:      nx = 1; break;
            }

            nx += snake.posX[snake.head];
            ny += snake.posY[snake.head];

            int?v = field.checkValid(nx, ny);
            //Debug.LogFormat("npos = {{{0}, {1}}}", nx, ny);
            if ((int)FieldType.Snake == v || null == v)
            {
                return(GameState.Fail);
            }
            else if ((int)FieldType.Empty == v)
            {
                int ot = snake.tail;
                int nh = (snake.head + 1) % snake.icons.Length;

                snake.icons[snake.head].GetComponent <SpriteRenderer>().color = Color.white;
                snake.icons[nh] = snake.icons[ot];
                snake.icons[ot] = null;
                snake.icons[nh].transform.position = field.calcPos(nx, ny);
                snake.icons[nh].GetComponent <SpriteRenderer>().color = head_color;

                snake.head = nh;
                snake.tail = (snake.tail + 1) % snake.icons.Length;

                snake.posX[nh] = nx;
                snake.posY[nh] = ny;
                field.moveGrid(snake.posX[ot], snake.posY[ot], nx, ny, (int)FieldType.Empty);
            }
            else if ((int)FieldType.Food == v)
            {
                int maxlen = snake.icons.Length;
                int nh     = (snake.head + 1) % maxlen;

                snake.icons[snake.head].GetComponent <SpriteRenderer>().color = Color.white;
                snake.icons[nh] = Instantiate(block_prefab, field.calcPos(nx, ny), Quaternion.identity, this.transform);
                snake.icons[nh].GetComponent <SpriteRenderer>().color = head_color;
                snake.posX[nh] = nx;
                snake.posY[nh] = ny;
                snake.head     = nh;
                field[nx, ny]  = (int)FieldType.Snake;

                if (snake.tail == (nh + 1) % maxlen)
                {
                    return(GameState.Win);
                }
                int snakelen   = (nh + maxlen - snake.tail + 1) % maxlen;
                int availspace = snake.icons.Length - snakelen;
                moveFood(availspace);
            }
        }
        return(GameState.Loop);
    }