public void SerializeGameEmpty()
        {
            GameData game = new GameData();

            GameData.Save(game, SaveFileName);

            game = GameData.Load(SaveFileName);

            Assert.IsNotNull(game);
            Assert.IsNull(game.Player);
            Assert.IsNull(game.World);
            Assert.IsNull(game.Configuration);
        }
        public void SerializeGameWithEmptyPlayer()
        {
            GameData game = new GameData();
            game.Player = new Player();

            Assert.AreSame(game, game.Player.GameData);

            GameData.Save(game, SaveFileName);

            game = GameData.Load(SaveFileName);

            Assert.IsNotNull(game);
            Assert.IsNotNull(game.Player);
            Assert.IsNull(game.World);
            Assert.IsNull(game.Configuration);
            Assert.AreSame(game, game.Player.GameData);
        }
예제 #3
0
        public void CreateTerrainInstance()
        {
            const string terrainName = "empty";
            const string scriptName = "new";
            const string propertyName = "testProperty";
            const string propertyValue = "testValue";
            const string isPassable = "isPassable";
            const string returnTrue = "return true";
            const string scriptFormat = "instance.setStringProperty(\"{0}\",\"{1}\")\r\ninstance.setScript(\"{2}\",\"{3}\")";

            GameData game = new GameData();
            game.Configuration = new Configuration();
            game.Configuration.SetTerrain(terrainName, new Terrain());
            game.Configuration.GetTerrain(terrainName).SetScript(scriptName, string.Format(scriptFormat,propertyName,propertyValue,isPassable,returnTrue));
            TerrainInstance instance = game.Configuration.CreateTerrainInstance(null, terrainName);

            Assert.IsNotNull(instance);
            Assert.IsNull(instance.MapCell);
            Assert.AreEqual(instance.GetStringProperty(propertyName), propertyValue);
            Assert.AreEqual(instance.GetScript(isPassable), returnTrue);
        }
예제 #4
0
        internal static Splorr.GameData CreateGameData()
        {
            int atlas = 0;
            int atlasColumn = 0;
            int atlasRow = 0;
            int mapLayer = 0;

            int playerX = MapConstants.MinimumX + 2;
            int playerY = MapConstants.MinimumY + 2;

            int keyX = MapConstants.MaximumX - 2;
            int keyY = MapConstants.MinimumY + 2;

            Splorr.GameData game = new Splorr.GameData();
            game.ScriptTableType = typeof(GameScripts);

            game.World = new World();
            game.Player = new Player();
            game.Player.Location = new Location(atlas, atlasColumn, atlasRow, mapLayer, playerX, playerY);
            game.Configuration = new Configuration();

            game.Configuration.SetDialog(GameScripts.Notifications.TagonSpawned,
                new Dialog(
                    new DialogCommands(
                        new DialogCommand(null, "confirm", "dialog-close"),
                        new DialogCommand(null, "cancel", "dialog-close")),
                    new DialogSection(null, "silver", "ruby",
                        DialogSection.MakeLines(
                            new DialogLine(null,"Welcome to Splorr!!")),
                        DialogSection.MakeIcons()),
                    new DialogSection(null, "black", "darksilver",
                        DialogSection.MakeLines(
                            new DialogLine(null, "Controls:"),
                            new DialogLine(null, "LS = WASD"),
                            new DialogLine(null, "RS = NumPad"),
                            new DialogLine(null, "DPad = Arrows"),
                            new DialogLine(null, "A = Space"),
                            new DialogLine(null, "B = LShift"),
                            new DialogLine(null, "X = E"),
                            new DialogLine(null, "Y = X"),
                            new DialogLine(null, "Back = Tab"),
                            new DialogLine(null, "Start = Esc")),
                        DialogSection.MakeIcons()),
                    new DialogSection(null, "black", "jade",
                        DialogSection.MakeLines(
                            new DialogLine(null, "[A] - Close")),
                        DialogSection.MakeIcons())
                    ));
            game.Configuration.SetDialog(GameScripts.Notifications.TagonBumped,
                new Dialog(
                    new DialogCommands(
                        new DialogCommand(null, "confirm", "dialog-close"),
                        new DialogCommand(null, "cancel", "dialog-close")),
                    new DialogSection(null, "silver", "ruby",
                        DialogSection.MakeLines(
                            new DialogLine(null, "Blocked!")),
                        DialogSection.MakeIcons()),
                    new DialogSection(null, "black", "darksilver",
                        DialogSection.MakeLines(
                            new DialogLine(null, "Some terrain"),
                            new DialogLine(null, "is impassible.")),
                        DialogSection.MakeIcons()),
                    new DialogSection(null, "black", "jade",
                        DialogSection.MakeLines(
                            new DialogLine(null, "[A] - Close")),
                        DialogSection.MakeIcons())
                    ));
            game.Configuration.SetDialog(GameScripts.Notifications.KeyBumped,
                new Dialog(
                    new DialogCommands(
                        new DialogCommand(null, "confirm", "dialog-close"),
                        new DialogCommand(null, "cancel", "dialog-close")),
                    new DialogSection(null, "silver", "ruby",
                        DialogSection.MakeLines(
                            new DialogLine(null, "Useful Items!")),
                        DialogSection.MakeIcons()),
                    new DialogSection(null, "black", "darksilver",
                        DialogSection.MakeLines(
                            new DialogLine(null, "Pick up by moving"),
                            new DialogLine(null, "onto them.")),
                        DialogSection.MakeIcons()),
                    new DialogSection(null, "black", "jade",
                        DialogSection.MakeLines(
                            new DialogLine(null, "[A] - Close")),
                        DialogSection.MakeIcons())
                    ));
            game.Configuration.SetDialog(GameScripts.Notifications.KeyPickup,
                new Dialog(
                    new DialogCommands(
                        new DialogCommand(null, "confirm", "dialog-close"),
                        new DialogCommand(null, "cancel", "dialog-close")),
                    new DialogSection(null, "silver", "ruby",
                        DialogSection.MakeLines(
                            new DialogLine(null, "A Red Key!")),
                        DialogSection.MakeIcons()),
                    new DialogSection(null, "black", "darksilver",
                        DialogSection.MakeLines(
                            new DialogLine(null, "Usually this means"),
                            new DialogLine(null, "there is a red door.")),
                        DialogSection.MakeIcons()),
                    new DialogSection(null, "black", "jade",
                        DialogSection.MakeLines(
                            new DialogLine(null, "[A] - Close")),
                        DialogSection.MakeIcons())
                    ));

            var treeTerrain = new Terrain();
            treeTerrain.SetNewScript(
                GameScripts.Scripts.CreateTree);
            treeTerrain.SetScript(Splorr.Scripts.CanEnter, GameScripts.Scripts.CanEnterTree);
            treeTerrain.SetScript(Splorr.Scripts.OnEnter, GameScripts.Scripts.Deny);

            var grassTerrain = new Terrain();
            grassTerrain.SetNewScript(GameScripts.Scripts.CreateGrass);
            grassTerrain.SetScript(Splorr.Scripts.OnEnter, GameScripts.Scripts.Allow);

            game.Configuration.SetTerrain(Terrains.Tree, treeTerrain);
            game.Configuration.SetTerrain(Terrains.Grass, grassTerrain);

            var tagonCreature = new Creature();
            tagonCreature.SetNewScript(GameScripts.Scripts.CreateTagon);
            tagonCreature.SetOnSpawnScript(GameScripts.Scripts.SpawnTagon);
            tagonCreature.SetScript(GameScripts.Scripts.BumpTagon, GameScripts.Scripts.BumpTagon);

            game.Configuration.SetCreature(Creatures.Tagon, tagonCreature);

            var keyItem = new Item();
            keyItem.SetNewScript(GameScripts.Scripts.CreateKey);

            game.Configuration.SetItem(Items.Key, keyItem);

            var map = game.World.GetMap(atlas, atlasColumn, atlasRow, mapLayer, true);

            for (int x = MapConstants.MinimumX; x <= MapConstants.MaximumX; ++x)
            {
                for (int y = MapConstants.MinimumY; y <= MapConstants.MaximumY; ++y)
                {
                    var location = new Location(atlas, atlasColumn, atlasRow, mapLayer, x, y);
                    var mapCell = map.GetMapCell(x, y, true);

                    foreach(var direction in Directions.Items)
                    {
                        mapCell.SetNeighbor(direction, location + Directions.GetDelta(direction));
                    }
                    if (x == MapConstants.MinimumX || y == MapConstants.MinimumY || x == MapConstants.MaximumX || y == MapConstants.MaximumY)
                    {
                        game.Configuration.CreateTerrainInstance(mapCell, Terrains.Tree);
                    }
                    else
                    {
                        game.Configuration.CreateTerrainInstance(mapCell, Terrains.Grass);
                    }
                }
            }

            var keyLocation = new Location(atlas, atlasColumn, atlasRow, mapLayer, keyX, keyY);
            var key = game.Configuration.CreateItemInstance(game.World[keyLocation], Items.Key);

            var tagon = game.Configuration.CreateCreatureInstance(game.World[game.Player.Location], Creatures.Tagon);

            GameData.Save(game, "tutorial.sav");

            game = GameData.Load("tutorial.sav");

            return game;
        }
예제 #5
0
 private bool OnMainMenuCommandMessage(MainMenuCommandMessage mainMenuCommandMessage)
 {
     if(mainMenuCommandMessage== null)
     {
         throw new ArgumentNullException("mainMenuCommandMessage");
     }
     switch(mainMenuCommandMessage.Command)
     {
         case MainMenuCommand.Quit:
             return HandleMessage(new QuitMessage());
         case MainMenuCommand.New:
             _gameData = NewGame();
             HideMainMenu();
             ShowPlayScreen();
             return true;
         case MainMenuCommand.Abandon:
             _gameData = null;
             HideMainMenu();
             return true;
         default:
             HideMainMenu();
             return true;
     }
 }
예제 #6
0
 public static void Save(GameData game,string fileName)
 {
     IFormatter formatter = new BinaryFormatter();
     using (Stream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
     {
         formatter.Serialize(stream, game);
         stream.Close();
     }
 }