示例#1
0
    public void Save()
    {
        _path = $"{Application.persistentDataPath}/{filename}";
        if (!File.Exists(_path))
        {
            File.WriteAllText(_path, "");
        }

        var bf   = new BinaryFormatter();
        var file = File.Create(_path);
        var json = JSONSerializer.Serialize(typeof(SaveData), _save);

        try
        {
            bf.Serialize(file, json);
            Debug.Log("Saved game data to : " + _path);
            GameSaved?.Invoke(_save);
        }
        catch (SerializationException e)
        {
            Debug.LogError($"Failed to serialize. Reason: {e.Message}");
            throw;
        }
        finally
        {
            file.Close();
        }
    }
示例#2
0
    public void StartHistoryGame()
    {
        SavedData data = GameSaved.GetData();

        _curScene = data.curScene;

        _player = new Player();
        _player.CreateHistory(data);

        _lastStoryId = data.lastStoryId;

        _curDay = data.day;
        MyLog.LogError("ReqHistoryData=> _curDay:" + _curDay + ", _curScene:" + _curScene + ", _lastStoryId:" + _lastStoryId);
        MyLog.LogError("player attr: healthy:" + _player.Healthy + ", energy:" + _player.Energy + ", energyMax:"
                       + _player.EnergyMax + ", hungry:" + _player.Hungry + ", hungryMax:" + _player.HungryMax
                       + ", Hp:" + _player.Hp + ", HpMax:" + _player.HpMax + ", Atk:" + _player.Atk + ", Def:" + _player.Def
                       + ", Power:" + _player.Power + ", Agile:" + _player.Agile + ", Physic:" + _player.Physic
                       + ", Charm:" + _player.Charm + ", Perception:" + _player.Perception);
        MyLog.LogError("player item: gold:" + _player.Gold + ", itemCount:" + _player.Items.Count + ", equipmentCount:" + _player.EquipmentList.Count);
        MyLog.LogError("player buff: id:" + _player.BuffID + ", duration:" + _player.BuffDuration);

        ConfigScene scene = ConfigManager.Instance.ReqSceneData(_curScene);

        if (scene != null)
        {
            _curSceneEvents   = ConfigManager.Instance.ReqEventList(_curScene);
            _curSceneMonsters = ConfigManager.Instance.ReqMonsterList(_curScene);
            _curSceneDrops    = ConfigManager.Instance.ReqDropList(_curScene);
        }
        else
        {
            MyLog.LogError("Scene[" + _curScene + "] not exist.");
            GameOver();
        }
    }
示例#3
0
 private void Start()
 {
     EventManager.Instance.AddListener(EVENT_TYPE.CREATE_ENEMY, AddEnemyToList);
     enemies      = new List <Enemy>();
     _targetX     = -CameraControl.CamWidth() / 2 + GameManager.OffsetCamWidth;
     gameSaved    = GameObject.Find("GameManager").GetComponent <GameManager>().gameSaved;
     enemyAtLevel = new Enemy[gameSaved.countLevelsOpen];
 }
示例#4
0
 private void Start()
 {
     gameSaved = GameObject.Find("GameManager").GetComponent <GameManager>().gameSaved;
     _offsetZ  = transform.position.z;
     _offsetX  = transform.position.x;
     _offsetY  = transform.position.y;
     _maxY     = gameSaved.countLevelsOpen * 7.4f; // change later
 }
示例#5
0
 public override void OnAwake()
 {
     mBtnNew = mWindowObj.GetChild("btnNewGame").asButton;
     mBtnNew.onClick.Add(OnClickNew);
     mBtnContinue         = mWindowObj.GetChild("btnLoadGame").asButton;
     mBtnContinue.visible = GameSaved.HasHistory();
     mBtnContinue.onClick.Add(OnClickContinue);
 }
示例#6
0
 void Start()
 {
     EventManager.Instance.AddListener(EVENT_TYPE.CREATE_LVLS, SetLevelList);
     gameSaved = GameObject.Find("GameManager").GetComponent <GameManager>().gameSaved;
     if (gameSaved.Equals(null))
     {
         print("Don't find GameManager");
     }
     enemiesAtLevel = new List <Enemy>();
     time           = new List <float>();
 }
示例#7
0
 private void Start()
 {
     EventManager.Instance.AddListener(EVENT_TYPE.CREATE_LVLS, SetLevelList);
     gameSaved = GameObject.Find("GameManager").GetComponent <GameManager>().gameSaved;
     if (gameSaved.Equals(null))
     {
         print("Don't find GameManager");
     }
     heroes           = new List <GameObject>();
     heroesTransforms = new Transform[gameSaved.countLevelsOpen];
     isStartMove      = true;
 }
示例#8
0
    public void Saved()
    {
        SavedData data = new SavedData();

        data.day = _curDay;

        data.curScene = _curScene;

        data.lastStoryId = _lastStoryId;

        data.role         = new RoleAttr();
        data.role.healthy = _player.Healthy;
        data.role.energy  = _player.Energy;
        data.role.hungry  = _player.Hungry;

        data.role.hp         = _player.Hp;
        data.role.atk        = _player.Atk;
        data.role.def        = _player.Def;
        data.role.power      = _player.Power;
        data.role.agile      = _player.Agile;
        data.role.physic     = _player.Physic;
        data.role.charm      = _player.Charm;
        data.role.perception = _player.Perception;

        data.role.buffId       = _player.BuffID;
        data.role.buffDuration = _player.BuffDuration;

        data.gold = _player.Gold;

        data.itemList = new List <SavedData.ItemCountData>();
        for (int i = 0; i < _player.Items.Count; i++)
        {
            SavedData.ItemCountData item = new SavedData.ItemCountData();
            item.id = _player.Items[i].ID;
            item.id = _player.Items[i].Count;
            data.itemList.Add(item);
        }

        data.equipmentList = new List <SavedData.ItemCountData>();
        for (int i = 0; i < _player.EquipmentList.Count; i++)
        {
            SavedData.ItemCountData item = new SavedData.ItemCountData();
            item.id = _player.EquipmentList[i].ID;
            item.id = _player.EquipmentList[i].Lev;
            data.equipmentList.Add(item);
        }

        GameSaved.SaveData(data);
    }
示例#9
0
    void Start()
    {
        gameSaved = GameObject.Find("GameManager").GetComponent <GameManager>().gameSaved;
        if (gameSaved.Equals(null))
        {
            print("Don't find GameManager");
        }

        levelsList  = new List <Transform>();
        _spawnPoint = Vector3.zero;
        for (int i = 0; i < iterator; i++)
        {
            CreatePrefabs();
        }
        OpenLevels();
        SetStartGameDataTag();
        EventManager.Instance.PostNotification(EVENT_TYPE.CREATE_LVLS, this, levelsList);
    }
示例#10
0
        public void PauseGame(string file)
        {
            XDocument doc = new XDocument(new XDeclaration("1.0", Encoding.UTF8.ToString(), "yes"),
                                          new XComment("Game Saved"),
                                          new XElement("Game",
                                                       new XElement("Player1"),
                                                       new XElement("Player2"),
                                                       new XElement("PiecesPlayer1"),
                                                       new XElement("PiecesPlayer2")));
            XElement Username1 = new XElement("Username", Game.Players[0].Username);
            XElement Username2 = new XElement("Username", Game.Players[1].Username);

            doc.Element("Game").Element("Player1").Add(Username1);
            doc.Element("Game").Element("Player2").Add(Username2);

            XElement turn1 = new XElement("Turn", Game.Players[0].IsTurn);
            XElement turn2 = new XElement("Turn", Game.Players[1].IsTurn);

            doc.Element("Game").Element("Player1").Add(turn1);
            doc.Element("Game").Element("Player2").Add(turn2);

            foreach (Piece p in Game.Players[0].Pieces)
            {
                XElement p1 = new XElement("Piece", new XAttribute("X", p.Position.X), new XAttribute("Y", p.Position.Y), new XAttribute("Queen", p.IsQueen), new XAttribute("Color", p.Color.Name));
                doc.Element("Game").Element("PiecesPlayer1").Add(p1);
            }

            foreach (Piece p in Game.Players[1].Pieces)
            {
                XElement p2 = new XElement("Piece", new XAttribute("X", p.Position.X), new XAttribute("Y", p.Position.Y), new XAttribute("Queen", p.IsQueen), new XAttribute("Color", p.Color.Name));
                doc.Element("Game").Element("PiecesPlayer2").Add(p2);
            }

            doc.Save(file);

            GameSaved?.Invoke();
        }
 public static void __OnGameSaved(int saveSlot)
 {
     GameSaved?.Invoke(null, new SaveLoadEventArgs(saveSlot));
 }