Ejemplo n.º 1
0
        public async Task MoveOnTrap()
        {
            var game         = new Game();
            var communicator = new DirectCommunicator();
            var gameProxy    = new Library.Level2.Game(communicator);
            var decoder      = new Messaging.Level2.Actions.ActionDecoder();

            game.Seed = 0;
            game.Initialize();
            game.State.PlayerPosition = (0, 0);

            var responseTask    = gameProxy.MoveAsync(Direction.South);
            var decodedResponse = await ExecuteRequestedAction(decoder, communicator, game, responseTask);

            decodedResponse.Perceptions.Should().Contain(Library.Level2.Enums.Perception.Death);
            decodedResponse.Perceptions.Should().NotContain(Library.Level2.Enums.Perception.Win);
            decodedResponse.GameState.MovesLeft.Should().Be(99);
            game.GameState.Should().Be(GameState.Lose);
        }
Ejemplo n.º 2
0
        public async Task MoveIntoWind()
        {
            var game         = new Game();
            var communicator = new DirectCommunicator();
            var gameProxy    = new Library.Level2.Game(communicator);
            var decoder      = new Messaging.Level2.Actions.ActionDecoder();

            game.Seed = 0;
            game.Initialize();
            game.State.PlayerPosition = (1, 0);

            var responseTask  = gameProxy.MoveAsync(Direction.West);
            var decodedAction = decoder.Decode(await communicator.ReceiveFromContestantAsync());
            var sentResponse  = game.Execute(decodedAction);

            sentResponse.As <Result>().GameState.PlayerPosition.Should().Be((0, 0));
            responseTask.IsCompleted.Should().BeFalse();
            communicator.SendToContestant(sentResponse);
            var decodedResponse = await responseTask;

            decodedResponse.Perceptions.Should().BeEquivalentTo(Perception.Wind);
            decodedResponse.GameState.MovesLeft.Should().Be(99);
            game.GameState.Should().Be(GameState.Running);
        }