Ejemplo n.º 1
0
    private void Awake()
    {
        model = new Model();


        int      id = PlayerPrefs.GetInt("idSelectedCharacter"); // get selected chracater id
        LocalRun runData;


        characterAttributes = model.findCaharacterWithId(id); //Find character and save all attributes
        runData             = model.lastCharacetrRun(id);     //Find if selected character character has game data



        //If character has data, load
        if (runData != null)
        {
            characterObject = (GameObject)Instantiate(Resources.Load("Prefabs/Player")); //Draw selected character
            characterObject.transform.position = new Vector3(runData.X, runData.Y, 0);   //move the character in the saved coordinates
        }
        else // if hasn't data
        {
            Debug.LogWarning("Te");
            runData = new LocalRun(-42, -13, characterAttributes.Health, this.name, "00:00", characterAttributes.Id); //Crete game with default data
            model.saveGame(runData);                                                                                  //save new game
            characterObject = (GameObject)Instantiate(Resources.Load("Prefabs/Player"));                              //draw character
            characterObject.transform.position = new Vector3(runData.X, runData.Y, 0);
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Save game with attributes of the moment
    /// </summary>
    /// <param name="save">data to save</param>
    /// <returns>true if saved, false in other case</returns>
    public bool saveGame(LocalRun save)
    {
        bool res = false;

        gameDao.saveGame(save);
        return(res);
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Load game data for one character
    /// </summary>
    /// <param name="characterId">character to load</param>
    /// <returns></returns>
    public LocalRun lastCharacetrRun(int characterId)
    {
        LocalRun lastRun = null;

        lastRun = gameDao.findRun(characterId);
        return(lastRun);
    }
Ejemplo n.º 4
0
        /// <summary>
        /// Find game with chracter id
        /// </summary>
        /// <param name="characerId">id to search</param>
        /// <returns></returns>
        public LocalRun findRun(int characerId)
        {
            LocalRun localRun = null;

            foreach (LocalRun local in loadGame())
            {
                if (local.Id_character == characerId)
                {
                    localRun = local;
                }
            }

            return(localRun);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Save game
        /// </summary>
        /// <param name="save">game attributes to save</param>
        public void saveGame(LocalRun save)
        {
            SqliteConnection conn = connector.OpenConnection();

            conn.Open();

            SqliteCommand cmd = new SqliteCommand(conn);

            cmd.CommandText = "INSERT INTO local_run (x,y,health,scene,time,id_character) VALUES (@x,@y,@health,@scene,@time,@id_character)";

            cmd.Parameters.AddWithValue("@x", save.X);
            cmd.Parameters.AddWithValue("@y", save.Y);
            cmd.Parameters.AddWithValue("@health", save.Health);
            cmd.Parameters.AddWithValue("@scene", save.Scene);
            cmd.Parameters.AddWithValue("@time", save.Timer);
            cmd.Parameters.AddWithValue("@id_character", save.Id_character);
            cmd.Prepare();

            cmd.ExecuteNonQuery();
            conn.Close();
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Save game data
 /// </summary>
 /// <param name="local">game data to save</param>
 public void saveRun(LocalRun local)
 {
     model.saveGame(local);
 }