コード例 #1
0
    void SetupGriglia()
    {
        celleGriglia.Clear();
        foreach (var pezzo in griglia)
        {
            if (pezzo != null)
            {
                Destroy(pezzo.tubo);
            }
        }
        griglia = new Tubi[DIM_X, DIM_Y];

        Vector3 dimScacchiera = g_renderer.size;

        Vector2 dimCella = new Vector2((dimScacchiera.x - 0.06f) / DIM_X, (dimScacchiera.y - 0.06f) / DIM_Y);

        this.dimCella = dimCella;

        Vector3 posStart = new Vector3((g_transform.position.x - ((dimScacchiera.x - 0.06f) / 2)) + (dimCella.x / 2), (g_transform.position.y - ((dimScacchiera.y - 0.06f) / 2)) + (dimCella.y / 2));

        for (int i = 0; i < DIM_X; i++)
        {
            for (int j = 0; j < DIM_Y; j++)
            {
                byte    orizzontale = (byte)i;
                byte    verticale   = (byte)j;
                Vector3 posCella    = new Vector3(posStart.x + (dimCella.x * i), posStart.y + (dimCella.y * j));

                InfoCelle cella = new InfoCelle(orizzontale, verticale, posCella);

                CelleGriglia.Add(cella);
            }
        }
    }
コード例 #2
0
    public static InfoCelle GetInfoCelle(byte x, byte y)
    {
        List <InfoCelle> Linea = celleGriglia.FindAll(a => a.coordinate.orizzontale == x);

        InfoCelle cella = Linea.Find(b => b.coordinate.verticale == y);

        return(cella);
    }
コード例 #3
0
    void GeneraPezzi(byte[,] disposizione)
    {
        foreach (var cella in celleGriglia)
        {
            Destroy(cella.pezzoInterno);
            cella.pezzoInterno = null;
            cella.pezzoInterno = null;
        }

        for (int x = 0; x < DIM_X; x++)
        {
            for (int y = 0; y < DIM_Y; y++)
            {
                if (disposizione[x, y] != 0)
                {
                    InfoCelle cellaDaTrovare = GetInfoCelle((byte)x, (byte)y);
                    Vector3   puntoSpawn     = cellaDaTrovare.posCella;

                    GameObject pezzo = Instantiate(pezzi[disposizione[x, y]], new Vector3(puntoSpawn.x, puntoSpawn.y, g_transform.position.z - 1), Quaternion.identity);

                    griglia[x, y] = new Tubi(x, y, 0, (tipoPezzo)disposizione[x, y], pezzo);
                    pezzo.GetComponent <Gestore_pezzo>().questo = griglia[x, y];

                    byte rotazioni = (byte)random.Next(0, 4);
                    for (int i = 0; i < rotazioni; i++)
                    {
                        pezzo.GetComponent <Gestore_pezzo>().Ruota();;
                    }

                    cellaDaTrovare.pezzoInterno = pezzo;

                    cellaDaTrovare.tipoPezzo = (tipoPezzo)disposizione[x, y];
                }
            }
        }
    }