public BoardChangeCommand(Board destinationBoard, Coordinate playerCoordinate)
        {
            destinationBoard.ThrowIfNull("destinationBoard");

            _destinationBoard = destinationBoard;
            _playerCoordinate = playerCoordinate;
        }
        public ActorInstanceCreateCommand(Board board, ActorInstance actorInstance)
        {
            board.ThrowIfNull("board");
            actorInstance.ThrowIfNull("actorInstance");

            _board = board;
            _actorInstance = actorInstance;
        }
        public BoardEnteredEvent(Board oldBoard, Board newBoard)
        {
            newBoard.ThrowIfNull("NewBoard");
            oldBoard.ThrowIfNull("oldBoard");

            _newBoard = newBoard;
            _oldBoard = oldBoard;
        }
        public BoardExitedEvent(Board oldBoard, Board newBoard)
        {
            oldBoard.ThrowIfNull("OldBoard");
            newBoard.ThrowIfNull("newBoard");

            _oldBoard = oldBoard;
            _newBoard = newBoard;
        }
Example #5
0
        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();
        }
Example #8
0
        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;
        }