Ejemplo n.º 1
0
    public void RotatePieces(TileCoord topLeft, bool direction)
    {
        Tile      one        = getTile(topLeft);
        TilePiece pieceOne   = one.getPiece();
        Tile      two        = getTile(TileCoord.add(topLeft, TileCoord.right));
        TilePiece pieceTwo   = two.getPiece();
        Tile      three      = getTile(TileCoord.add(topLeft, TileCoord.up));
        TilePiece pieceThree = three.getPiece();
        Tile      four       = getTile(TileCoord.add(topLeft, TileCoord.add(TileCoord.right, TileCoord.up)));
        TilePiece pieceFour  = four.getPiece();

        Debug.Log("P00: " + getTileType(one.pos) + " P10: " + getTileType(two.pos) + " P01: " + getTileType(three.pos) + " P11: " + getTileType(four.pos));
        if (direction)
        {
            one.SetPiece(pieceThree);
            two.SetPiece(pieceOne);
            three.SetPiece(pieceFour);
            four.SetPiece(pieceTwo);
        }
        else
        {
            one.SetPiece(pieceTwo);
            two.SetPiece(pieceFour);
            three.SetPiece(pieceOne);
            four.SetPiece(pieceThree);
        }
        Debug.Log("P00: " + getTileType(one.pos) + " P10: " + getTileType(two.pos) + " P01: " + getTileType(three.pos) + " P11: " + getTileType(four.pos));
        update.Add(pieceOne);
        update.Add(pieceTwo);
        update.Add(pieceThree);
        update.Add(pieceFour);
    }
Ejemplo n.º 2
0
    List <TileCoord> matchFinder(TileCoord pos, bool initial)
    {
        List <TileCoord> matches = new List <TileCoord>();
        int type = getTileType(pos);

        TileCoord[] directions =
        {
            TileCoord.up,
            TileCoord.right,
            TileCoord.down,
            TileCoord.left
        };

        foreach (TileCoord dir in directions)
        {
            List <TileCoord> line = new List <TileCoord>();

            int match = 0;
            for (int i = 1; i < 3; i++)
            {
                TileCoord check  = TileCoord.add(pos, TileCoord.mult(dir, i));
                int       typero = getTileType(check);
                if (getTileType(check) == type)
                {
                    line.Add(check);
                    match++;
                }
            }

            if (match >= 2)
            {
                AddMatches(ref matches, line);
            }
        }

        for (int i = 0; i < 2; i++)
        {
            List <TileCoord> line = new List <TileCoord>();
            int         match     = 0;
            TileCoord[] check     = { TileCoord.add(pos, directions[i]), TileCoord.add(pos, directions[i + 2]) };
            foreach (TileCoord next in check)
            {
                if (getTileType(next) == type)
                {
                    line.Add(next);
                    match++;
                }
            }
            if (match > 1)
            {
                AddMatches(ref matches, line);
            }
        }

        if (initial)
        {
            for (int i = 0; i < matches.Count; i++)
            {
                AddMatches(ref matches, matchFinder(matches[i], false));
            }
        }
        return(matches);
    }