Exemplo n.º 1
0
    public GameBoard(string levelName)
    {
        this.boardMap = new Dictionary <Coordinate, GameBoardSquare>();
        this.tileMap  = new Dictionary <Tile, Coordinate>();

        if (levelName == "")
        {
            for (int i = 0; i < 5; ++i)
            {
                for (int j = 0; j < 7; ++j)
                {
                    if (i == 3 || j == 3)
                    {
                        continue;
                    }
                    GameBoardSquare sq = new GameBoardSquare();
                    //GameCell cell = new GameCell();
                    //sq.AddGameCell(cell);
                    Coordinate coord = new Coordinate(i, j);
                    sq.coordinate = coord;
                    boardMap.Add(coord, sq);
                }
            }
        }
        else
        {
            string path = "Assets/Resources/" + levelName + ".json";

            //Read the text from directly from the test.txt file
            StreamReader reader   = new StreamReader(path);
            string       jsonText = reader.ReadToEnd();
            reader.Close();
            JSONNode node = JSON.Parse(jsonText);
            foreach (JSONNode square in node["squares"])
            {
                GameBoardSquare sq = GameBoardSquare.GameBoardSquareFromNode(square);
                boardMap.Add(sq.coordinate, sq);
            }
        }
    }