Esempio n. 1
0
 void Awake()
 {
     board         = GetComponent <CombatantBoard>();
     cellLibrary   = FindObjectOfType <CellLibrary>();
     cellList      = new List <CellData>();
     boardSlotList = new List <CellSlot>();
     occupiedSlots = new List <CellSlot>();
 }
Esempio n. 2
0
    public void GenerateBoard()
    {
        if (cellLibrary == null)
        {
            cellLibrary = FindObjectOfType <CellLibrary>();
        }
        if (board == null)
        {
            board = GetComponent <CombatantBoard>();
        }

        boardSlotList = board.GetSlots();
        numCellTypes  = cellLibrary.allCells.Length;
        numBoardSlots = boardSlotList.Count;

        while ((cells < cellCount) && (cellValue < numBoardSlots) && (tries < 100))
        {
            /// first row guaranteed
            for (int i = 0; i < board.boardColumnCount; i++)
            {
                CellSlot cs = boardSlotList[i];
                NewCell();
            }

            /// remaining cells randomly
            foreach (CellSlot cs in boardSlotList)
            {
                if ((cs.GetCell() == null) ||
                    ((cs.GetCell() != null) && (cs.GetCell().GetCellData() != null)))
                {
                    if ((Random.Range(0f, 1f) > 0.3f) && (cells < cellCount))
                    {
                        NewCell();
                    }
                    else
                    {
                        if (cells < cellCount)
                        {
                            cellList.Add(null);
                        }
                    }
                }
            }
            tries++;
        }

        board.LoadBoard(cellList);
    }
Esempio n. 3
0
    public virtual void LoadGame()
    {
        // 1
        if (File.Exists(Application.persistentDataPath + "/gamesave.save"))
        {
            CharacterDataPlayer player = FindObjectOfType <CharacterDataPlayer>();

            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Open(Application.persistentDataPath + "/gamesave.save", FileMode.Open);
            Save            save = (Save)bf.Deserialize(file);
            file.Close();

            playerCells = new List <CellData>();
            CellLibrary cellLibrary  = FindObjectOfType <CellLibrary>();
            int         numLiveCells = 0;
            for (int i = 0; i < save.playerCellIDs.Count; i++)
            {
                int cdID = save.playerCellIDs[i];
                if (cdID >= 0)
                {
                    CellData IDCellData = cellLibrary.allCells[cdID];
                    playerCells.Add(IDCellData);
                    numLiveCells++;
                }
                else
                {
                    playerCells.Add(null);
                }
            }

            playerBoard.LoadBoard(playerCells);

            //Debug.Log("Game Loaded");
        }
        //else
        //{
        //	Debug.Log("No game saved!");
        //}
    }
Esempio n. 4
0
 void Awake()
 {
     cellLibrary   = FindObjectOfType <CellLibrary>();
     cellValueText = GetComponentInChildren <Text>();
 }
Esempio n. 5
0
 void Start()
 {
     cellLibrary = transform.root.GetComponent <CellLibrary>();
     boardEditor = FindObjectOfType <BoardEditor>();
 }