Пример #1
0
        public void Initialize(TankPuzzle puzzle)
        {
            if (puzzle == null)
            {
                throw new ArgumentNullException(nameof(puzzle));
            }

            if (casillas == null)
            {
                casillas = new Casilla[puzzle.rows, puzzle.columns];

                transform.localScale = new Vector3(SCALE_FACTOR_C * casillas.GetLength(1),
                                                   transform.localScale.y, SCALE_FACTOR_R * casillas.GetLength(0));
            }
            else if (casillas.GetLength(0) != puzzle.rows || casillas.GetLength(1) != puzzle.columns)
            {
                DestroyCasillas();
                casillas = new Casilla[puzzle.rows, puzzle.columns];

                transform.localScale = new Vector3(SCALE_FACTOR_C * casillas.GetLength(1),
                                                   transform.localScale.y, SCALE_FACTOR_R * casillas.GetLength(0));
            }

            GenerateCasillas(puzzle);
        }
Пример #2
0
 /* Genera un archivo con los datos del tablero de la partida que es serializable
  * a partir de un tablero no serializable.
  */
 private static void generarTableroSerializable(Casilla[,] tablero, ref CasillaSerializable[,] tableroSerializable)
 {
     tableroSerializable = new CasillaSerializable[tablero.GetLength(0), tablero.GetLength(1)];
     for (int i = 0; i < tablero.GetLength(0); i++)
     {
         for (int j = 0; j < tablero.GetLength(1); j++)
         {
             CasillaSerializable temp = new CasillaSerializable();
             temp.coordsTexX  = tablero[i, j].coordsTex.x;
             temp.coordsTexY  = tablero[i, j].coordsTex.y;
             temp.coordsVertX = tablero[i, j].coordsVert.x;
             temp.coordsVertY = tablero[i, j].coordsVert.y;
             temp.coordsVertZ = tablero[i, j].coordsVert.z;
             temp.elementos   = tablero[i, j].elementos;
             temp.habitat     = tablero[i, j].habitat;
             if (tablero[i, j].pinceladas != null)
             {
                 temp.pinceladas = new float[tablero[i, j].pinceladas.Length * 2];
                 for (int k = 0; k < tablero[i, j].pinceladas.Length; k++)
                 {
                     temp.pinceladas[k * 2]     = tablero[i, j].pinceladas[k].x;
                     temp.pinceladas[k * 2 + 1] = tablero[i, j].pinceladas[k].y;
                 }
             }
             tableroSerializable[i, j] = temp;
         }
     }
 }
Пример #3
0
 public void EstablecerTablero()
 {
     tablero = new Casilla[width, height];
     for (int y = 0; y < tablero.GetLength(0); y++)
     {
         for (int x = 0; x < tablero.GetLength(1); x++)
         {
             tablero[x, y] = new Casilla(new Casilla.Coords(x, y));
         }
     }
 }
Пример #4
0
 public void eliminaMuroFantasmas()
 {
     for (int i = 0; i < cas.GetLength(0); i++)
     {
         for (int j = 0; j < cas.GetLength(1); j++)
         {
             if (cas[i, j] == Casilla.MuroCelda)
             {
                 cas[i, j] = Casilla.Blanco;
             }
         }
     }
 }
Пример #5
0
        // ----------------------------Public------------------------

        public void Init(GameManager gm, Map m)
        {
            if (gm == null)
            {
                throw new ArgumentNullException(nameof(gm));
            }
            if (m == null)
            {
                throw new ArgumentNullException(nameof(m));
            }

            gm_ = gm;

            // Inicializamos el vector de casillas
            casillas_            = new Casilla[m.rows, m.cols];
            transform.localScale = new Vector3(SCALE_FACTOR_C * casillas_.GetLength(1), transform.localScale.y, SCALE_FACTOR_R * casillas_.GetLength(0));


            rows_ = checked ((int)m.rows);
            cols_ = checked ((int)m.cols);

            GenerateCasillas(m);

            InitTank();
        }
Пример #6
0
        public void Reset(GameManager gm, Map m)
        {
            if (gm == null)
            {
                throw new ArgumentNullException(nameof(gm));
            }
            if (m == null)
            {
                throw new ArgumentNullException(nameof(m));
            }

            gm_ = gm;



            DestroyCasillas();
            path.setWorking(false);
            destroyFlechas();
            path_ = null;

            casillas_            = new Casilla[m.rows, m.cols];
            transform.localScale = new Vector3(SCALE_FACTOR_C * casillas_.GetLength(1), transform.localScale.y, SCALE_FACTOR_R * casillas_.GetLength(0));

            rows_ = checked ((int)m.rows);
            cols_ = checked ((int)m.cols);

            GenerateCasillas(m);

            ResetTank();
        }
Пример #7
0
    //genera el tablero y le asigna el tipo correspondiente a cada casilla
    void GenerateBoard()
    {
        tablero = new Casilla[rows * rows, cols *cols];

        for (int i = 0; i < tablero.GetLength(0); i++)
        {
            for (int j = 0; j < tablero.GetLength(1); j++)
            {
                Casilla cas = Instantiate(casillaPrefab, new Vector3(j * casillaPrefab.gameObject.transform.localScale.x * 1.1f, 0, -i * casillaPrefab.gameObject.transform.localScale.z * 1.1f), Quaternion.identity);
                tablero [i, j] = cas;
                cas.Initialize(this, new Position(i, j));
                cas.setOcupada(false);
                cas.setType(matriz[i / matriz.getRows(), j / matriz.getCols()]);
            }
        }
    }
Пример #8
0
        public void Initialize(CluedoPuzzle puzzle)
        {
            gm = GameManager.instance;

            if (casillas == null)
            {
                casillas = new Casilla[puzzle.rows, puzzle.columns];

                transform.localScale = new Vector3(SCALE_FACTOR_C * casillas.GetLength(1),
                                                   transform.localScale.y, SCALE_FACTOR_R * casillas.GetLength(0));
            }
            else if (casillas.GetLength(0) != puzzle.rows || casillas.GetLength(1) != puzzle.columns)
            {
                DestroyCasillas();
                casillas = new Casilla[puzzle.rows, puzzle.columns];

                transform.localScale = new Vector3(SCALE_FACTOR_C * casillas.GetLength(1),
                                                   transform.localScale.y, SCALE_FACTOR_R * casillas.GetLength(0));
            }

            GenerateCasillas(puzzle);
        }
Пример #9
0
        private bool PonerBarco(Barco.Tipo tipo_barco, Barco.Orientacion orientacion, int x, int y)
        {
            bool puesto = false;

            // Console.WriteLine("Tipo: {0} | Orientación: {1} | x: {2} | y: {3}", tipo_barco, orientacion, x, y);

            // Comprobamos que no excede los límites
            if ((orientacion.Equals(Barco.Orientacion.HORIZONTAL) &&
                 x + GetBarcoTablero(tipo_barco).GetTamano() <= tablero.GetLength(0)) ||
                (orientacion.Equals(Barco.Orientacion.VERTICAL) &&
                 y + GetBarcoTablero(tipo_barco).GetTamano() <= tablero.GetLength(1)))
            {
                int p = orientacion.Equals(Barco.Orientacion.HORIZONTAL) ? x : y;

                // Comprobamos que todas las posiciones para el nuevo barco son de tipo agua
                puesto = true;
                for (int i = p; i < GetBarcoTablero(tipo_barco).GetTamano() + p; i++)
                {
                    if ((orientacion.Equals(Barco.Orientacion.HORIZONTAL) && !tablero[i, y].GetEstado().Equals(Casilla.Estados.AGUA)) ||
                        orientacion.Equals(Barco.Orientacion.VERTICAL) && !tablero[x, i].GetEstado().Equals(Casilla.Estados.AGUA))
                    {
                        puesto = false;
                        break;
                    }
                }

                // Si no excede límites y todas son de tipo agua, establecemos el tipo de barco en el tablero
                if (puesto)
                {
                    int     array_pos = 0;
                    Casilla casilla   = null;
                    for (int i = p; i < GetBarcoTablero(tipo_barco).GetTamano() + p; i++)
                    {
                        if (orientacion.Equals(Barco.Orientacion.HORIZONTAL))
                        {
                            casilla = tablero[i, y];
                        }
                        else if (orientacion.Equals(Barco.Orientacion.VERTICAL))
                        {
                            casilla = tablero[x, i];
                        }

                        casilla.SetEstado(Casilla.Estados.BARCO);
                        GetBarcoTablero(tipo_barco).SetCasillas(array_pos, casilla);
                        array_pos++;
                    }
                }
            }

            return(puesto);
        }
Пример #10
0
    //devuelve una casilla libre
    Casilla getNoOcupCasilla()
    {
        int k1 = 0;
        int k2 = 0;

        do
        {
            k1 = rnd.Next(0, tablero.GetLength(0));
            k2 = rnd.Next(0, tablero.GetLength(1));
        }while(tablero[k1, k2].getOcupada());

        Casilla cas = tablero [k1, k2];

        return(cas);
    }
Пример #11
0
        /** Constructores*/
        public Tablero(ContentManager content)
        {
            //Se inicializa la posicion del tablero
            posicion = new Vector2(70, 20);

            //Se le asignan las posiciones a cada casilla
            for (int i = 0; i < casillas.GetLength(0); i++)
            {
                for (int j = 0; j < casillas.GetLength(1); j++)
                {
                    int posicionXPantalla = 70 + (i) * 80;
                    int posicionYPantalla = 20 + (j) * 80;
                    casillas[i, j] = new Casilla()
                    {
                        Posicion = new Vector2(posicionXPantalla, posicionYPantalla)
                    };
                }
            }
            //Se le asignan los colores a las casillas
            setColorCasillas(content);
        }
Пример #12
0
        public Tablero(string file) //Constructor
        {
            char[] c = LecturaDeFichero(file);

            int columnas = Columnas(c);

            int filas = Filas(c);


            //Creación del tablero
            cas = new Tablero.Casilla[filas, columnas];

            //Creacion del array de personajes
            pers = new Tablero.Personaje[5];

            for (int j = 0; j < pers.Length; j++)
            {
                pers[j].dir = new Coor();
                pers[j].pos = new Coor();
                pers[j].ini = new Coor();
            }

            //Direccion inicial de pac-man
            pers[0].dir.fil = 1;
            pers[0].dir.col = 0;

            //Este bucle recorre el array "Tablero" y lo rellena dependiendo del número del array auxiliar "c"
            //Si encuentra ";" disminuye "col" para hacer como si no existiera
            int i         = 0;
            int fantasmas = 1;

            for (int row = 0; row < cas.GetLength(0); row++)
            {
                for (int col = 0; col < cas.GetLength(1); col++)
                {                                                               //Pasarlo a un método
                    if (c[i] == ';')
                    {
                        i++; col--;
                    }
                    else if (c[i] == '0')
                    {
                        cas[row, col] = (Casilla)0; i++;
                    }
                    else if (c[i] == '1')
                    {
                        cas[row, col] = (Casilla)1; i++;
                    }
                    else if (c[i] == '2')
                    {
                        cas[row, col] = (Casilla)2; i++;
                    }
                    else if (c[i] == '3')
                    {
                        cas[row, col] = (Casilla)3; i++;
                    }
                    else if (c[i] == '4')
                    {
                        cas[row, col] = (Casilla)4; i++;
                    }
                    else if (c[i] == '5' || c[i] == '6' || c[i] == '7' || c[i] == '8')
                    {
                        cas[row, col]           = (Casilla)0;
                        pers[fantasmas].ini.fil = row;
                        pers[fantasmas].ini.col = col;
                        pers[fantasmas].pos.fil = pers[fantasmas].ini.fil;
                        pers[fantasmas].pos.col = pers[fantasmas].ini.col;
                        fantasmas++;
                        i++;
                    }
                    else if (c[i] == '9')
                    {
                        cas[row, col]   = (Casilla)0;
                        pers[0].pos.fil = row;
                        pers[0].pos.col = col;
                        i++;
                    }
                }
            }

            //Inicialización del timer
            lapFantasmas = lapCarcelFantasmas;

            //Inicialización del random
            rnd = new Random(100);
        }
Пример #13
0
        //Seleccionar una casilla con Candy (Solo se usa en el init de game manager para colocar la primera casilla)
        public void GiveCandy(uint r, uint c)
        {
            Casilla cell = casillas_[r, c];

            if (cell != null)
            {
                cell = null;
                Destroy(casillas_[r, c].gameObject);
            }
            cell = Instantiate(candyPrefab,
                               new Vector3(-((casillas_.GetLength(1) / 2.0f) * POSITION_FACTOR_C - (POSITION_FACTOR_C / 2.0f)) + c * POSITION_FACTOR_C,
                                           0,
                                           (casillas_.GetLength(0) / 2.0f) * POSITION_FACTOR_R - (POSITION_FACTOR_R / 2.0f) - r * POSITION_FACTOR_R),
                               Quaternion.identity);
            cell.candy_ = true;

            Position pos = new Position(r, c);

            cell.pos = pos;

            cell.Init(this, 4);
            setCandy(cell);
            casillas_[r, c] = cell;
        }
Пример #14
0
 public bool DentroDelLimite(int x, int y)
 {
     return((x >= 0 && x < tablero.GetLength(0)) && (y >= 0 && y < tablero.GetLength(0)));
 }