Пример #1
0
    public LogicaTablero()
    {
        _matriz = new LogicaTile[10, 10];
        Random rnd = new Random();

        //i son filas
        for (int y = 0; y < 10; y++)
        {
            for (int x = 0; x < 10; x++)
            {
                int random = rnd.Next(0, 10);
                //Mar
                if (random <= 7)
                {
                    _matriz[y, x] = new LogicaTile(Terreno.agua, new Pos(x, y));
                }

                //Mar profundo
                else if (random == 8)
                {
                    _matriz[y, x] = new LogicaTile(Terreno.aguaProfunda, new Pos(x, y));
                }

                //Muro
                else
                {
                    _matriz[y, x] = new LogicaTile(Terreno.muro, new Pos(x, y));
                }
            }
        }
    }
Пример #2
0
    //---------------CONSTRUCCIÓN TILES------------------------

    //Pasa la representación lógica del tablero (matriz) a la representación física (gameobjects)
    void colocaTablero()
    {
        GameObject GOTablero = new GameObject("Tablero");

        for (int y = 0; y < 10; y++)
        {
            for (int x = 0; x < 10; x++)
            {
                //Creamos gameObject
                GameObject GOTileAux = Instantiate(tilePrefab, new Vector3(x * Distancia, -y * Distancia, 0), Quaternion.identity, GOTablero.transform);

                LogicaTile tileAux = _logicaTablero.GetLogicaTile(x, y);

                //SpriteRenderer
                switch (tileAux.GetTerreno())
                {
                case Terreno.agua:
                    GOTileAux.GetComponent <SpriteRenderer>().sprite = spriteAgua;
                    break;

                case Terreno.aguaProfunda:
                    GOTileAux.GetComponent <SpriteRenderer>().sprite = spriteAguaProfunda;
                    break;

                case Terreno.muro:
                    GOTileAux.GetComponent <SpriteRenderer>().sprite = spriteMuro;
                    break;
                }

                //Casilla
                GOTileAux.GetComponent <Tile>().ConstruyeCasilla(tileAux);
            }
        }
    }
Пример #3
0
    public LogicaTablero(int alto, int ancho, bool predeterminado)
    {
        _matriz = new LogicaTile[alto, ancho];
        Random rnd = new Random();

        //i son filas
        if (!predeterminado)
        {
            for (int y = 0; y < alto; y++)
            {
                for (int x = 0; x < ancho; x++)
                {
                    int random = rnd.Next(0, 10);
                    //Mar
                    if (random <= 4)
                    {
                        _matriz[y, x] = new LogicaTile(Terreno.libre, new Pos(x, y));
                    }
                    else if (random <= 7 && random > 4)
                    {
                        _matriz[y, x] = new LogicaTile(Terreno.agua, new Pos(x, y));
                    }

                    //Mar profundo
                    else if (random == 8)
                    {
                        _matriz[y, x] = new LogicaTile(Terreno.cienaga, new Pos(x, y));
                    }

                    //Muro
                    else
                    {
                        _matriz[y, x] = new LogicaTile(Terreno.muro, new Pos(x, y));
                    }
                }
            }
        }
        else
        {
            for (int y = 0; y < alto; y++)
            {
                for (int x = 0; x < ancho; x++)
                {
                    _matriz[y, x] = new LogicaTile(Terreno.libre, new Pos(x, y));
                }
            }
        }
    }
Пример #4
0
 public void ConstruyeCasilla(LogicaTile logicaTile)
 {
     _logicaTile = logicaTile;
 }