Exemple #1
0
    public DatosGuardar cargar(int indiceImagen)
    {
        FileStream file = null;

        try{
            BinaryFormatter bf = new BinaryFormatter();
            file = new FileStream(Application.persistentDataPath + "/" + this.nombreArchivoDatos, FileMode.OpenOrCreate, FileAccess.Read);
            DatosGuardar datos = (DatosGuardar)bf.Deserialize(file);

            while (datos != null)
            {
                if (indiceImagen == datos.indiceImagen)
                {
                    return(datos);
                }
                datos = (DatosGuardar)bf.Deserialize(file);
            }
        }catch (System.Runtime.Serialization.SerializationException) {
        }catch (Exception e) {
            Debug.Log("ha ocurrido un error: " + e.Message);
            Debug.Log("entro al exception: " + e.GetType());
            Debug.Log("entro al exception: " + e.Source);
        }finally{
            file.Close();
        }

        //en caso que la imagen no se haya encontrado
        return(null);
    }
Exemple #2
0
    //devuelve una lista con los datos de los records de cada imagen
    public List <DatosGuardar> cargarTodos()
    {
        FileStream          file             = null;
        List <DatosGuardar> datosRecordsList = null;

        try{
            BinaryFormatter bf = new BinaryFormatter();
            file = new FileStream(Application.persistentDataPath + "/" + this.nombreArchivoDatos, FileMode.OpenOrCreate, FileAccess.Read);

            DatosGuardar datos = (DatosGuardar)bf.Deserialize(file);
            datosRecordsList = new List <DatosGuardar>();

            while (datos != null)
            {
                datosRecordsList.Add(datos);
                datos = (DatosGuardar)bf.Deserialize(file);
            }
        }catch (System.IO.EndOfStreamException) {
        }catch (Exception e) {
            Debug.Log("ha ocurrido un error: " + e.Message);
            Debug.Log("entro al exception: " + e.GetType());
            Debug.Log("entro al exception: " + e.Source);
        }finally{
            file.Close();
        }

        //devuelve una lista con los datos de los records de cada imagen
        return(datosRecordsList);
    }
Exemple #3
0
 void Awake()
 {
     generadorNcomp = GameObject.Find("GeneradorNiveles").GetComponent <generadorniveles> ();
     animador       = GetComponent <Animator>();
     datos          = GameObject.Find("GuardadoDatos").GetComponent <DatosGuardar> ();
     scriptCamara   = Camera.main.GetComponent <Camarascript> ();
     jugable        = false;
 }
Exemple #4
0
    public void guardar()
    {
        BinaryFormatter bf = new BinaryFormatter();
        FileStream      fs = new FileStream(rutaArchivo, FileMode.Create);

        DatosGuardar datos = new DatosGuardar(puntuacionMaxima);

        bf.Serialize(fs, datos);

        fs.Close();
    }
Exemple #5
0
    public void guardar(int indiceImagen, int movimientos, int minutos, int segundos, float puntos)
    {
        FileStream file = null;

        try{
            BinaryFormatter bf = new BinaryFormatter();
            file = new FileStream(Application.persistentDataPath + "/" + this.nombreArchivoDatos, FileMode.Append, FileAccess.Write);

            DatosGuardar datos = new DatosGuardar(indiceImagen, movimientos, minutos, segundos, puntos);
            bf.Serialize(file, datos);
        }catch (Exception e) {
            Debug.Log("ha ocurrido un error: " + e.Message);
        }finally{
            file.Close();
        }
    }
Exemple #6
0
    public void cargar()
    {
        if (File.Exists(rutaArchivo))
        {
            BinaryFormatter bf = new BinaryFormatter();
            FileStream      fs = new FileStream(rutaArchivo, FileMode.Open);

            DatosGuardar datos = (DatosGuardar)bf.Deserialize(fs);

            puntuacionMaxima = datos.puntuacion;
            fs.Close();
        }
        else
        {
            puntuacionMaxima = 0;
        }
    }
Exemple #7
0
    public void actualizar(DatosGuardar nuevo)
    {
        FileStream file = null, temporal = null;
        bool       error = false;

        try{
            BinaryFormatter bf         = new BinaryFormatter();
            BinaryFormatter bfTemporal = new BinaryFormatter();
            file     = new FileStream(Application.persistentDataPath + "/" + this.nombreArchivoDatos, FileMode.OpenOrCreate, FileAccess.Read);
            temporal = new FileStream(Application.persistentDataPath + "/temporal", FileMode.Create, FileAccess.Write);

            DatosGuardar datos = (DatosGuardar)bf.Deserialize(file);

            while (datos != null)
            {
                if (nuevo.indiceImagen == datos.indiceImagen)
                {
                    bfTemporal.Serialize(temporal, nuevo);
                }
                else
                {
                    bfTemporal.Serialize(temporal, datos);
                }
                datos = (DatosGuardar)bf.Deserialize(file);
            }
        }catch (System.IO.EndOfStreamException) {
        }catch (Exception e) {
            Debug.Log("ha ocurrido un error: " + e.Message);
            Debug.Log("entro al exception: " + e.GetType());
            Debug.Log("entro al exception: " + e.Source);

            error = true;
        }finally{
            file.Close();
            temporal.Close();

            if (!error)
            {
                //eliminando el archivo con informacion desactualiada, luego se renombra el acrhivo que tiene la
                //informacion actualizada
                File.Delete(Application.persistentDataPath + "/" + this.nombreArchivoDatos);
                File.Move(Application.persistentDataPath + "/temporal", Application.persistentDataPath + "/" + this.nombreArchivoDatos);
            }
        }
    }
Exemple #8
0
    void Start()
    {
        //actualizamos el nombre del archivo, segun el archivo que necesitemos acceder
        //para ello usamos los tags de un componente padre para identificar que archivo se debe acceder
        string tag = gameObject.GetComponentInParent <Image>().tag;

        if (tag.Equals("panelFacil"))
        {
            this.cargarDatos.nombreArchivoDatos = this.cargarDatos.FacilArchivo;
        }
        else if (tag.Equals("panelModerado"))
        {
            this.cargarDatos.nombreArchivoDatos = this.cargarDatos.ModeradoArchivo;
        }
        else if (tag.Equals("panelDificil"))
        {
            this.cargarDatos.nombreArchivoDatos = this.cargarDatos.DificilArchivo;
        }

        DatosGuardar datosGuardar = cargarDatos.cargar(indice);

        if (datosGuardar != null)
        {
            this.txtIndice.text      = "#" + (datosGuardar.indiceImagen + 1).ToString();
            this.txtMovimientos.text = datosGuardar.movimientos.ToString();

            string segundosCad = ((datosGuardar.segundos > 9)?datosGuardar.segundos.ToString():"0" + datosGuardar.segundos);
            string minutosCad  = ((datosGuardar.minutos > 9)?datosGuardar.minutos.ToString():"0" + datosGuardar.minutos);

            this.txtTiempo.text  = minutosCad + ":" + segundosCad;
            this.txtPuntaje.text = datosGuardar.puntos.ToString();
        }
        else
        {
            this.txtIndice.text      = "#" + (this.indice + 1).ToString();
            this.txtTiempo.text      = "--:--";
            this.txtMovimientos.text = "--:--";
            this.txtPuntaje.text     = "--:--";
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (!this.finJuego)
        {
            //obteniendo tiempo en la partida
            this.finTiempo = DateTime.Now;
            dif            = this.finTiempo - this.inicialTiempo;
            this.segundos  = (int)dif.Seconds;
            this.minutos   = (int)dif.TotalMinutes;

            //actualizando y dandole formato al texto que muestra el tiempo
            this.segundosCad = ((this.segundos > 9)?this.segundos.ToString():"0" + this.segundos);
            this.minutosCad  = ((this.minutos > 9)?this.minutos.ToString():"0" + this.minutos);
            this.tiempo.text = this.minutosCad + ":" + this.segundosCad;
        }

        if (this.verificarClick && !this.finJuego)
        {
            //Debug.Log(this.posxBlank+" : "+this.posyBlank);
            //Debug.Log(this.row+" : "+this.col);
            if (this.posxBlank != this.row || this.posyBlank != this.col)             //verificamos que no fue clickeado la casilla blank


            //Debug.Log("entro");

            {
                if (this.posxBlank != this.row && this.posyBlank == this.col)
                {
                    if (Mathf.Abs(this.posxBlank - this.row) == 1f)                    //nos aseguramos que mueva la casilla contigua
                    //movemos en vertical
                    {
                        this.moverSprites();
                    }
                }
                else if (this.posxBlank == this.row && this.posyBlank != this.col)
                {
                    if (Mathf.Abs(this.posyBlank - this.col) == 1f)
                    {
                        //movemos en horizontal
                        this.moverSprites();
                    }
                }

                //verificamos si el rompecabezas esta completado
                if (this.posxBlankFinal == this.posxBlank && this.posyBlank == this.posyBlankFinal)
                {
                    int contCorrectas = this.verificarCantidadCorrectas();

                    if (!(contCorrectas == (this.sizeCol * this.sizeRow)))
                    {
                        //TO DO: eliminar este if
                        contCorrectas = this.correctasAux;
                    }
                    //si todas las fichas estan correctas el nivel está completado
                    if (contCorrectas == (this.sizeCol * this.sizeRow))
                    {
                        this.finJuego = true;                         //activamos la variable que finaliza el juego(armado del puzzle)

                        //aqui calculamos los puntos obtenidos
                        float maxTiempo = 180f;                         //minutos = 3 horas
                        float maxMovimientos = 5000f;
                        float porcTiempo = 0.65f, porcMovimientos = 0.35f;
                        float tiempoFormato = (int)this.dif.TotalMinutes + (this.dif.Seconds / 100f);                     //tiempo en formato decimal ej: 4.3 minutos = 4:30
                        //float puntuacionPerfecta = 1864.2f;

                        float puntos = (maxMovimientos - (float)this.cantMovimientos) * porcMovimientos + (maxTiempo - tiempoFormato) * porcTiempo;
                        bool  record = false;
                        //guardando datos sencillos
                        PlayerPrefs.SetInt("mins", (int)this.dif.TotalMinutes);
                        PlayerPrefs.SetInt("segs", (int)this.dif.Seconds);
                        PlayerPrefs.SetInt("movimientos", this.cantMovimientos);
                        PlayerPrefs.SetFloat("puntos", puntos);

                        Debug.Log("Felicidades has Ganado");
                        Debug.Log("puntos: " + puntos);

                        //aqui llamaremos al metodo que guardara la informacion en el archivo y verificaremos si se
                        //ha fijado un nuevo record
                        DatosGuardar datos = this.guardarCargarDatos.cargar(this.indice);

                        if (datos == null)
                        {
                            //cuando no se encuentre datos de la imagen, entonces se fijará un nuevo record, ya que debe ser la primera vez que se juega con dicha imagen
                            this.guardarCargarDatos.guardar(this.indice, this.cantMovimientos, (int)this.dif.TotalMinutes, this.dif.Seconds, puntos);
                            Debug.Log("nuevo record: " + puntos);
                            record = true;
                            //this.txtRecordGO.SetActive(true);
                        }
                        else
                        {
                            if (puntos > datos.puntos)
                            {
                                //fijamos un nuevo record
                                this.guardarCargarDatos.actualizar(new DatosGuardar(this.indice, this.cantMovimientos, (int)this.dif.TotalMinutes, this.dif.Seconds, puntos));
                                Debug.Log("record anterior: " + datos.puntos);
                                Debug.Log("nuevo record: " + puntos);
                                record = true;
                                //this.txtRecordGO.SetActive(true);
                            }
                            Debug.Log("record anterior: " + datos.puntos);
                        }

                        int estado = PlayerPrefs.GetInt("sonido");
                        Debug.Log("estado audio completado: " + estado);
                        if (estado == 1)
                        {
                            //!this.desactivarSonido
                            //reproduciendo sonido de puzzle completado
                            int indSonidoGanar = 1;
                            this.movimientoSonido.PlayOneShot(this.sonidos[indSonidoGanar]);
                            //this.StartCoroutine("reproducirAplausos");
                        }
                        this.StartCoroutine("irAFelicitaciones", record);
                    }
                    //Debug.Log(contCorrectas+" : "+this.sizeCol);
                    //Debug.Log("fin: "+this.finJuego);
                }
            }
            this.verificarClick = false;
        }
    }
Exemple #10
0
 void Awake()
 {
     datos = GameObject.Find("GuardadoDatos").GetComponent <DatosGuardar> ();
 }