Example #1
0
        public void TestDroneMap()
        {
            var drone = new Drone(new CoordinateInt2D()
            {
                X = 1, Y = 1
            })
            {
                Name        = "Drone_1",
                Speed       = 1,
                StorageSize = 10
            };

            var droneDtoExpected = new DroneDto()
            {
                Name            = "Drone_1",
                CurrentPosition = new CoordinateInt2D()
                {
                    X = 1, Y = 1
                },
                LastInstruction = null,
                State           = DroneState.WaitingForOrders,
                Speed           = 1,
                StorageSize     = 10,
                Storage         = null
            };

            var mapper = new PlayerContextMapper();

            var droneDtoActual = mapper.Map(drone);

            droneDtoActual.Should().BeEquivalentTo(droneDtoExpected);
        }
Example #2
0
        public IPlayerContextDto GetPlayerContext(string playerName)
        {
            var repo   = GetPlayerContextRepository();
            var mapper = new PlayerContextMapper();

            try
            {
                return(mapper.Map(repo.GetPlayerContextByPlayerName(playerName)));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw e;
            }
        }
        public override IPlayerContextDto CreateNew(UserLoginDto login)
        {
            var repo   = GetPlayerContextRepository();
            var mapper = new PlayerContextMapper();

            var map      = GetMap(1);
            var payerCtx = new PlayerContext()
            {
                PlayerName = login.PlayerName,
                Pass       = login.Pass,
                Level      = 1,
                Drones     = map.InitialDrones
            };

            repo.Save(payerCtx);
            return(mapper.Map(payerCtx));
        }
        public override IPlayerContextDto ChangeLevel(int level, string playerName)
        {
            var repo   = GetPlayerContextRepository();
            var mapper = new PlayerContextMapper();

            try
            {
                var playerContext = repo.GetPlayerContextByPlayerName(playerName);
                // try load maps, throws exception if map does not exists
                var map = GetMap(level);
                playerContext.Level  = level;
                playerContext.Drones = map.InitialDrones;
                repo.Save(playerContext);
                return(mapper.Map(playerContext));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw;
            }
        }