public XElement Serialize(World world, string elementName = "world") { world.ThrowIfNull("world"); elementName.ThrowIfNull("elementName"); return new XElement( elementName, PlayerSerializer.Instance.Serialize(world.StartingPlayer, "startingPlayer"), world.Boards.Select(arg => BoardSerializer.Instance.Serialize(arg)), world.Actors.Select(arg => ActorSerializer.Instance.Serialize(arg)), world.Messages.Select(arg => MessageSerializer.Instance.Serialize(arg)), world.Timers.Select(arg => TimerSerializer.Instance.Serialize(arg)), world.SoundEffects.Select(arg => SoundEffectSerializer.Instance.Serialize(arg)), world.Songs.Select(arg => SongSerializer.Instance.Serialize(arg)), new XAttribute("id", world.Id), new XAttribute("version", world.Version), new XAttribute("title", world.Title)); }
private void CreateGame(World world) { _boardRendererState.Board = world.Boards.FirstOrDefault(); CalculateEditorView(); _game = new TextAdventureEditorGame( xnaControl.GraphicsDevice, _editorView, _boardRendererState, _pencilRendererState, _eraserRendererState); _game.Run(); xnaControl.DrawBackground = false; }
public byte[] Serialize(World world) { world.ThrowIfNull("world"); var serializer = new CompactSerializer(); serializer[0] = world.Id.ToByteArray(); serializer[1] = BitConverter.GetBytes(world.Version); serializer[2] = Encoding.UTF8.GetBytes(world.Title); serializer[3] = PlayerSerializer.Instance.Serialize(world.StartingPlayer); var boardSerializer = new CompactSerializer(); int boardIndex = 0; foreach (Board board in world.Boards) { boardSerializer[boardIndex++] = BoardSerializer.Instance.Serializer(board); } serializer[4] = boardSerializer.Serialize(); var actorSerializer = new CompactSerializer(); int actorIndex = 0; foreach (Actor actor in world.Actors) { actorSerializer[actorIndex++] = ActorSerializer.Instance.Serialize(actor); } serializer[5] = actorSerializer.Serialize(); var messageSerializer = new CompactSerializer(); int messageIndex = 0; foreach (Message message in world.Messages) { messageSerializer[messageIndex++] = MessageSerializer.Instance.Serialize(message); } serializer[6] = messageSerializer.Serialize(); var timerSerializer = new CompactSerializer(); int timerIndex = 0; foreach (Timer timer in world.Timers) { timerSerializer[timerIndex++] = TimerSerializer.Instance.Serialize(timer); } serializer[7] = timerSerializer.Serialize(); var soundEffectSerializer = new CompactSerializer(); int soundEffectIndex = 0; foreach (SoundEffect soundEffect in world.SoundEffects) { soundEffectSerializer[soundEffectIndex++] = SoundEffectSerializer.Instance.Serialize(soundEffect); } serializer[8] = soundEffectSerializer.Serialize(); var songSerializer = new CompactSerializer(); int songIndex = 0; foreach (Song song in world.Songs) { songSerializer[songIndex++] = SongSerializer.Instance.Serialize(song); } serializer[9] = songSerializer.Serialize(); return serializer.Serialize(); }