Beispiel #1
0
    //returns false if filepath is not found
    public bool InitializeWithLevel(string levelName)
    {
        this.tiles = new List <Tile>();

        string path = "Assets/Resources/" + levelName + ".json";

        if (!File.Exists(path))
        {
            Debug.LogWarning("couldn't find path " + path);
            return(false);
        }

        StreamReader reader   = new StreamReader(path);
        string       jsonText = reader.ReadToEnd();

        reader.Close();
        JSONNode node = JSON.Parse(jsonText);

        foreach (JSONNode tile in node["tiles"])
        {
            Tile t = new Tile();

            foreach (JSONNode square in tile)
            {
                Coordinate coord = new Coordinate();
                coord.row    = square["row"];
                coord.column = square["column"];
                GameCell cell = GameCell.GameCellFromJSONNode(square);
                t.squareInfo.Add(coord, cell);
            }
            this.tiles.Add(t);
        }

        return(true);
    }
Beispiel #2
0
    public static GameBoardSquare GameBoardSquareFromNode(JSONNode square)
    {
        int             row    = square["row"];
        int             column = square["column"];
        GameBoardSquare sq     = new GameBoardSquare();
        Coordinate      coord  = new Coordinate(row, column);

        sq.coordinate = coord;
        //TODO: only add GameCell if square is not "greyed out" (add something in the json for that)
        GameCell gameCell = GameCell.GameCellFromJSONNode(square);

        sq.AddGameCell(gameCell);
        return(sq);
    }