示例#1
0
        public void LevelLoaderShouldReturnLevelModelWithBricks()
        {
            const int levelNumber = 1;
            var levelData = new LevelData(levelNumber);
            levelData.AddBrickData(1, 1, 10);
            levelData.AddBrickData(1, 2, 10);
            _levelDeserializer.Setup(ld => ld.LoadFromFile(levelNumber)).Returns(levelData);

            var levelModel = _levelLoader.LoadLevel(levelNumber);

            Assert.That(levelModel.GetBricks().Count, Is.EqualTo(2));
        }
        public void SerializeLevelIntoJSONFile()
        {
            var levelData = new LevelData(1);
            const int value = 10;
            for (int row = 2; row < 7;row++ )
                for (int col = 0; col < 13; col++)
                {
                    levelData.AddBrickData(row, col, value);
                }

            _serializer.SaveToFile(levelData);
        }
示例#3
0
        public void LevelLoaderShouldReturnLevelModelWithBricksWithXYPositions()
        {
            const int levelNumber = 1;
            var levelData = new LevelData(levelNumber);
            levelData.AddBrickData(1, 0, 10);
            levelData.AddBrickData(1, 1, 10);
            _levelDeserializer.Setup(ld => ld.LoadFromFile(levelNumber)).Returns(levelData);

            var levelModel = _levelLoader.LoadLevel(levelNumber);

            Assert.That(levelModel.GetBricks().First().Boundary.Location.X, Is.EqualTo(FrameWidth));
            Assert.That(levelModel.GetBricks().First().Boundary.Location.Y, Is.EqualTo(40));
        }
示例#4
0
        public LevelData LoadFromFile(int levelNumber)
        {
            var levelData = new LevelData(levelNumber);
            try
            {
                Stream stream = TitleContainer.OpenStream("Content/Levels/" + levelNumber + ".json");
                var sreader = new StreamReader(stream);

                levelData = DeserializeFromReader(sreader);

                stream.Close();
            }
            catch (FileNotFoundException)
            {
                // this will be thrown by OpenStream if gamedata.txt
                // doesn't exist in the title storage location
            }

            return levelData;
        }
示例#5
0
 public void SaveToFile(LevelData levelData)
 {
     TextWriter tw = new StreamWriter(levelData.LevelNumber + ".json");
     JsonSerializer.SerializeToWriter(levelData, tw);
     tw.Close();
 }