Example #1
0
    /// <summary>
    /// Helper method: Creates view pieces depending on player with information form a saved data file
    /// </summary>
    /// <param name="players">A list of active players</param>
    /// <param name="prefab">A prefab reference</param>
    /// <param name="data">A data file reference</param>
    private static void CreatePieces(List <UserModel> players, PieceObject prefab, SaveData data)
    {
        //This method is an overload of the original CreatePieces method.
        //It uses data info to create pieces with their positions and teams intact.
        Transform parent = new GameObject("Piece List").transform;

        globalPieceList = new List <BoardPiece>();
        for (int i = 0; i < players.Count; i++)
        {
            players[i].OwnedViewPieces = new List <PieceObject>();
            foreach (var item in data.savedBoard)
            {
                if (item.belongsTo == players[i].currentTeam)
                {
                    BoardNode foundNode = new BoardNode(new Vector2Int(item.boardPos.x, item.boardPos.y), new Vector2(item.worldPos.x, item.worldPos.y), item.belongsTo);
                    globalPieceList.Add(new BoardPiece(foundNode));
                    PieceObject piece = PieceObject.CreatePieceObject(prefab, foundNode.worldPos, (PieceColor)foundNode.belongsTo, parent, foundNode.pos);
                    players[i].OwnedViewPieces.Add(piece);
                }
            }
        }
    }
Example #2
0
    /// <summary>
    /// Helper method: Creates view pieces depending on player.
    /// </summary>
    /// <param name="players">A list of active players</param>
    /// <param name="prefab">A prefab reference.</param>
    private static void CreatePieces(List <UserModel> players, PieceObject prefab)
    {
        Transform parent = new GameObject("Piece List").transform;

        globalPieceList = new List <BoardPiece>();

        for (int i = 0; i < players.Count; i++)
        {
            players[i].OwnedViewPieces = new List <PieceObject>();
            for (int x = 0; x < test_OriginalBoard.GetLength(0); x++)
            {
                for (int y = 0; y < test_OriginalBoard.GetLength(1); y++)
                {
                    BoardNode foundNode = test_OriginalBoard[x, y];
                    if (players[i].currentTeam == foundNode.belongsTo)
                    {
                        globalPieceList.Add(new BoardPiece(foundNode));
                        PieceObject piece = PieceObject.CreatePieceObject(prefab, foundNode.worldPos, (PieceColor)foundNode.belongsTo, parent, foundNode.pos);
                        players[i].OwnedViewPieces.Add(piece);
                    }
                }
            }
        }
    }