public BoardChangeCommand(Board destinationBoard, Coordinate playerCoordinate) { destinationBoard.ThrowIfNull("destinationBoard"); _destinationBoard = destinationBoard; _playerCoordinate = playerCoordinate; }
public BoardEnteredEvent(Board oldBoard, Board newBoard) { newBoard.ThrowIfNull("NewBoard"); oldBoard.ThrowIfNull("oldBoard"); _newBoard = newBoard; _oldBoard = oldBoard; }
public ActorInstanceCreateCommand(Board board, ActorInstance actorInstance) { board.ThrowIfNull("board"); actorInstance.ThrowIfNull("actorInstance"); _board = board; _actorInstance = actorInstance; }
public BoardExitedEvent(Board oldBoard, Board newBoard) { oldBoard.ThrowIfNull("OldBoard"); newBoard.ThrowIfNull("newBoard"); _oldBoard = oldBoard; _newBoard = newBoard; }
protected internal bool ChangeLocation(Board board, Coordinate newCoordinate) { board.ThrowIfNull("board"); Sprite foregroundSprite = board.ForegroundLayer[newCoordinate]; ActorInstance actorInstance = board.ActorInstanceLayer[newCoordinate]; if (foregroundSprite != null || actorInstance != null) { return false; } BoardId = board.Id; Coordinate = newCoordinate; return true; }
public XElement Serialize(Board board, string elementName = "board") { board.ThrowIfNull("board"); elementName.ThrowIfNull("elementName"); return new XElement( elementName, SpriteLayerSerializer.Instance.Serialize(board.BackgroundLayer, "backgroundLayer"), SpriteLayerSerializer.Instance.Serialize(board.ForegroundLayer, "foregroundLayer"), ActorInstanceLayerSerializer.Instance.Serialize(board.ActorInstanceLayer), board.Exits.Select(arg => BoardExitSerializer.Instance.Serialize(arg)), board.Timers.Select(arg => TimerSerializer.Instance.Serialize(arg)), EventHandlerCollectionSerializer.Instance.Serialize(board.EventHandlerCollection), new XAttribute("id", board.Id), new XAttribute("name", board.Name), new XAttribute("description", board.Description), new XAttribute("size", SizeSerializer.Instance.Serialize(board.Size))); }
public byte[] Serializer(Board board) { board.ThrowIfNull("board"); var serializer = new CompactSerializer(); serializer[0] = board.Id.ToByteArray(); serializer[1] = Encoding.UTF8.GetBytes(board.Name); serializer[2] = Encoding.UTF8.GetBytes(board.Description); serializer[3] = SizeSerializer.Instance.Seralize(board.Size); serializer[4] = SpriteLayerSerializer.Instance.Serialize(board.BackgroundLayer); serializer[5] = SpriteLayerSerializer.Instance.Serialize(board.ForegroundLayer); serializer[6] = ActorInstanceLayerSerializer.Instance.Serialize(board.ActorInstanceLayer); var boardExitSerializer = new CompactSerializer(); int index = 0; foreach (BoardExit boardExit in board.Exits) { boardExitSerializer[index++] = BoardExitSerializer.Instance.Serialize(boardExit); } var timerSerializer = new CompactSerializer(); index = 0; foreach (Timer timer in board.Timers) { timerSerializer[index++] = TimerSerializer.Instance.Serialize(timer); } serializer[7] = boardExitSerializer.Serialize(); serializer[8] = timerSerializer.Serialize(); serializer[9] = EventHandlerCollectionSerializer.Instance.Serialize(board.EventHandlerCollection); return serializer.Serialize(); }
protected internal bool ChangeCoordinate(Board board, Player player, Coordinate destinationCoordinate) { board.ThrowIfNull("board"); player.ThrowIfNull("player"); if (board.ActorInstanceLayer[Coordinate] != this) { throw new ArgumentException("Board's actor instance layer does not contain this actor instance.", "board"); } ActorInstance destinationActorInstance = board.ActorInstanceLayer[destinationCoordinate]; Sprite foregroundSprite = board.ForegroundLayer[destinationCoordinate]; if (destinationActorInstance != null || foregroundSprite != null || player.Coordinate == destinationCoordinate) { return destinationActorInstance == this; } board.ActorInstanceLayer.MoveTile(Coordinate, destinationCoordinate); Coordinate = destinationCoordinate; return true; }
public static BoardChangeCommand BoardChange(Board board, Coordinate newPlayerCoordinate) { return new BoardChangeCommand(board, newPlayerCoordinate); }
public static ActorInstanceCreateCommand ActorInstanceCreate(Board board, ActorInstance actorInstance) { return new ActorInstanceCreateCommand(board, actorInstance); }
private CommandResult ProcessDestinationCoordinate(Context context, Board board, Coordinate destinationCoordinate) { Coordinate currentCoordinate = context.Player.Coordinate; BoardExitDirection boardExitDirection = GetBoardExitDirection(currentCoordinate, destinationCoordinate); BoardExit boardExit = board.Exits.SingleOrDefault(arg => arg.Coordinate == currentCoordinate && arg.Direction == boardExitDirection); if (boardExit != null) { Board destinationBoard = context.GetBoardById(boardExit.DestinationBoardId); context.EnqueueCommand(new BoardChangeCommand(destinationBoard, boardExit.DestinationCoordinate)); return CommandResult.Succeeded; } if (!board.CoordinateIntersects(destinationCoordinate)) { return CommandResult.Failed; } ActorInstance targetActorInstance = board.ActorInstanceLayer[destinationCoordinate]; if (targetActorInstance != null) { TouchDirection? touchDirection = GetTouchDirection(currentCoordinate, destinationCoordinate); if (touchDirection != null) { context.RaiseEvent(targetActorInstance.OnTouchedByPlayer, new PlayerTouchedActorInstanceEvent(targetActorInstance, touchDirection.Value)); } } return context.Player.ChangeLocation(context.CurrentBoard, destinationCoordinate) ? CommandResult.Succeeded : CommandResult.Failed; }
private static void GetDrawingParameters( Board board, Player player, out Point topLeftPoint, out Coordinate topLeftCoordinate, out Coordinate bottomRightCoordinate) { int drawableTilesToLeft = Math.Min(Constants.GameWindow.TilesToLeftInclusive, player.Coordinate.X); int drawableTilesToTop = Math.Min(Constants.GameWindow.TilesToTopInclusive, player.Coordinate.Y); int drawableTilesToRight = Math.Min(Constants.GameWindow.TilesToRightExclusive, board.Size.Width - player.Coordinate.X - 1); int drawableTilesToBottom = Math.Min(Constants.GameWindow.TilesToBottomExclusive, board.Size.Height - player.Coordinate.Y - 1); topLeftPoint = new Point( Constants.PlayerRenderer.DestinationRectangle.X - (drawableTilesToLeft * TextAdventure.Xna.Constants.Tile.TileWidth), Constants.PlayerRenderer.DestinationRectangle.Y - (drawableTilesToTop * TextAdventure.Xna.Constants.Tile.TileHeight)); topLeftCoordinate = new Coordinate(player.Coordinate.X - drawableTilesToLeft, player.Coordinate.Y - drawableTilesToTop); bottomRightCoordinate = new Coordinate(player.Coordinate.X + drawableTilesToRight, player.Coordinate.Y + drawableTilesToBottom); }