Exemplo n.º 1
0
    void AddToListSaveFigures(ChessFigure temp, SaveInfo saveAsset)
    {
        SaveFigure tempSave = new SaveFigure();

        tempSave.positionX    = temp.transform.position.x;
        tempSave.positionY    = temp.transform.position.y;
        tempSave.positionZ    = temp.transform.position.z;
        tempSave.posX         = temp.pos.x;
        tempSave.posY         = temp.pos.y;
        tempSave.startPosX    = temp.startPos.x;
        tempSave.startPosY    = temp.startPos.y;
        tempSave.team         = temp.team;
        tempSave.type         = temp.type;
        tempSave.id           = temp.id;
        tempSave.turnCounter  = temp.turnCounter;
        tempSave.enable       = temp.enable;
        tempSave.beforeFigure = temp.beforeFigure;

        if (!saveAsset.figures.Contains(tempSave))
        {
            saveAsset.figures.Add(tempSave);
        }
        else
        {
            Debug.Log("Error! save figure was created");
        }
    }
Exemplo n.º 2
0
    bool LoadGame()
    {
        if (!File.Exists(Application.persistentDataPath + "/GameInfo.dat"))
        {
            return(false);
        }

        BinaryFormatter bf       = new BinaryFormatter();
        FileStream      file     = File.Open(Application.persistentDataPath + "/GameInfo.dat", FileMode.Open);
        SaveInfo        saveData = (SaveInfo)bf.Deserialize(file);

        file.Close();

        figures       = new ChessFigure[height, width];
        figuresParent = new GameObject("Figures");

        defeatedWhiteFiguresParent = new GameObject("Defeated white figures");
        float x = ((width + 1) / 2f) * startSize * scale / 100f;
        float y = ((height - 1) / 2f) * startSize * scale / 100f;

        defeatedWhiteFiguresParent.transform.position = new Vector3(x, y, 0);

        defeatedBlackFiguresParent = new GameObject("Defeated black figures");
        x = ((-width - 1) / 2f) * startSize * scale / 100f;
        y = ((height - 1) / 2f) * startSize * scale / 100f;
        defeatedBlackFiguresParent.transform.position = new Vector3(x, y, 0);

        for (int i = 0; i < saveData.figures.Count; i++)
        {
            SaveFigure temp = saveData.figures[i];
            if (temp.enable)
            {
                figures[temp.posX, temp.posY] = GetFromListSaveFifures(temp, figuresParent.transform);
            }
            else if (temp.team == TypeTeam.white)
            {
                defeatedWhiteFigures.Add(GetFromListSaveFifures(temp, defeatedWhiteFiguresParent.transform));
            }
            else
            {
                defeatedBlackFigures.Add(GetFromListSaveFifures(temp, defeatedBlackFiguresParent.transform));
            }
        }

        presentTeam      = saveData.presentTeam;
        becomeKingFigure = FindFigure(saveData.idBecomeKingFigure);
        for (int i = saveData.states.Count - 1; i >= 0; i--)
        {
            stateManager.AddState(saveData.states[i]);
        }

        return(true);
    }
Exemplo n.º 3
0
    ChessFigure GetFromListSaveFifures(SaveFigure temp, Transform parent)
    {
        GameObject figure      = temp.team == TypeTeam.white ? chessTypeOne[(int)temp.type] : chessTypeTwo[(int)temp.type];
        GameObject chessFigure = Instantiate(figure, parent);

        chessFigure.transform.position   = new Vector3(temp.positionX, temp.positionY, temp.positionZ);
        chessFigure.transform.localScale = new Vector3(scale * .8f, scale * .8f, 1);
        ChessFigure tempChess = chessFigure.GetComponent <ChessFigure>();

        tempChess.Init(new Vector2Int(temp.posX, temp.posY), temp.team, temp.beforeFigure);
        tempChess.startPos     = new Vector2Int(temp.startPosX, temp.startPosY);
        tempChess.id           = temp.id;
        tempChess.turnCounter  = temp.turnCounter;
        tempChess.enable       = temp.enable;
        tempChess.beforeFigure = temp.beforeFigure;
        tempChess.OnClick     += ChooseTurn;
        return(tempChess);
    }