Esempio n. 1
0
        public ValidationResult<Player> Create(string name)
        {
            if (_repo.GetByName(name) != null) return ValidationResult<Player>.Failure("User already exists");

            var random = new Random();

            var player = new Player{Name = name};

            player.Id = Guid.NewGuid();
            player.IsOnline = true;
            player.LastSeen = DateTime.Now;
            player.ApiKey = string.Format("{0}{1}{2}{3}{4}",
                                     random.Next(0, 9),
                                     random.Next(0, 9),
                                     random.Next(0, 9),
                                     random.Next(0, 9),
                                     random.Next(0, 9));

            player.IsActive = true;

            _repo.Add(player);
            _repo.Save();

            return ValidationResult<Player>.Success.WithData(player);
        }
Esempio n. 2
0
 public void Init(ServerApi api, Player player, GameState game, Map map)
 {
     this.api = api;
     this.player = player;
     this.game = game;
     this.map = map;
 }
Esempio n. 3
0
        public ActionResult CreatePlayer(string name)
        {
            var player = new Player { Name = name };
            var resultPlayer = _prov.Create(player);

            return View(new { ok = true, player = resultPlayer });
        }
Esempio n. 4
0
 private static void CreateUser()
 {
     Console.Clear();
     var name = GetText("Please enter your username", s => !String.IsNullOrWhiteSpace(s));
     api.CreatePlayer(name, (data, e) => {
         if (e != null) { Error(e); return; }
         if (!data.Ok) { BadResponse(); return; }
         CurrentPlayer = data.Player;
         Welcome();
     });
 }
Esempio n. 5
0
        public GamesControllerTests()
        {
            _dummyGameState = GetDummyGameState();
            _dummyPlayer = GetDummyPlayer();

            _gameStateProvider = Substitute.For<IGameStateProvider>();
            _gameStateProvider.CreateGame(Arg.Any<string>()).ReturnsForAnyArgs(ValidationResult<GameState>.Success.WithData(_dummyGameState));
            _gameStateProvider.JoinGame(Arg.Any<Guid>(), Arg.Any<Guid>()).ReturnsForAnyArgs(ValidationResult<GameState>.Success.WithData(_dummyGameState));

            _controller = new GamesController(_gameStateProvider);
        }
Esempio n. 6
0
        public GameStateProviderTests()
        {
            _dummyPlayer = GetDummyPlayer();
            _dummyMap = GetDummyMap();

            _gameStateRepository = Substitute.For<IGameStateRepository>();
            _playersProvider = Substitute.For<IPlayersProvider>();
            _playersProvider.Get(Guid.Empty).ReturnsForAnyArgs(_dummyPlayer);
            _mapProvider = Substitute.For<IMapProvider>();
            _mapProvider.GetRandomMap().ReturnsForAnyArgs(_dummyMap);
            _gameStateProvider = new GameStateProvider(_gameStateRepository, _playersProvider, _mapProvider);
        }
            public override CommandProcessor Given()
            {
                var firstPlayer = new Player {Name = "shiftkey"};
                var secondPlayer = new Player { Name = "aeoth" };

                activeUnitId = Guid.NewGuid();
                targetUnitId = Guid.NewGuid();

                attackUnit = new Pirate { Id = activeUnitId, X = 10, Y = 4, };
                targetUnit = new Pirate { Id = targetUnitId, X = 10, Y = 5, CurrentHitPoints = expectedDamage };

                FirstPlayer.Units.Add(attackUnit);
                FirstPlayer.Player = firstPlayer;
                SecondPlayer.Units.Add(targetUnit);
                SecondPlayer.Player = secondPlayer;

                Calculator.CalculateDamage(attackUnit, targetUnit).Returns(expectedDamage);

                return new CommandProcessor(Calculator, State);
            }
Esempio n. 8
0
        public Player Create(Player player)
        {
            var random = new Random();

            var p = player;

            p.Id = Guid.NewGuid();
            p.IsOnline = true;
            p.LastSeen = DateTime.Now;
            p.ApiKey = string.Format("{0}{1}{2}{3}{4}",
                                     random.Next(0, 9),
                                     random.Next(0, 9),
                                     random.Next(0, 9),
                                     random.Next(0, 9),
                                     random.Next(0, 9));

            p.IsActive = true;

            _repo.Add(player);

            return p;
        }
Esempio n. 9
0
        private static void CreateUser()
        {
            Console.Clear();
            var name = GetText("Please enter your username", s => !String.IsNullOrWhiteSpace(s));
            api.CreatePlayer(name, (data, e) =>
            {
                if (e != null)
                {
                    Error(e);
                    return;
                }

                if (!data.Ok)
                {
                    BadResponse();
                    return;
                }

                CurrentPlayer = data.Player;
                Console.WriteLine("Your generated key: {0}", CurrentPlayer.ApiKey);
                Console.ReadKey();
                Welcome();
            });
        }
Esempio n. 10
0
 private void Login()
 {
     var status = window.GetChild<TextBlock>("status");
     if (status != null)
         status.Enabled = true;
     var name = Player.Name;
     var key = Player.ApiKey;
     Player = null;
     api.Login(name, key, new Action<PlayerResponse, Exception>(
         (p, e) =>
         {
             Thread.Sleep(1000);
             if (e == null && p.Ok)
                 Player = p.Player;
             else
             {
                 DeleteSave();
                 Guide.BeginShowMessageBox("Error", "Failed to login: "******"Ok" }, 0, MessageBoxIcon.Error, null, null);
             }
             if (status != null)
                 status.Enabled = false;
             UpdateButtons();
         }));
 }
Esempio n. 11
0
        private void LoadPlayer()
        {
            if (Player != null)
                return;

            if (Settings.Instance.CurrentPlayer != null)
                Player = Settings.Instance.CurrentPlayer;
        }
Esempio n. 12
0
        private void LoadPlayer()
        {
            if (Player != null)
                return;

            using (var iso = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (iso.FileExists("player.dat"))
                {
                    using (var file = iso.OpenFile("player.dat", FileMode.Open, FileAccess.Read))
                    using (var br = new BinaryReader(file))
                    {
                        Player = new Player();
                        Player.Id = Guid.Parse(br.ReadString());
                        Player.Name = br.ReadString();
                        Player.ApiKey = br.ReadString();
                        Login();
                    }
                }
            }
        }
Esempio n. 13
0
 public void Init(ServerApi api, Player player)
 {
     this.api = api;
     this.player = player;
 }
Esempio n. 14
0
        private static void Login()
        {
            var name = GetText("Please enter your username", s => !String.IsNullOrWhiteSpace(s));
            var key = GetText("Please enter your key", s => !String.IsNullOrWhiteSpace(s));

            api.Login(name, key, (data, e) =>
            {
                if (e != null)
                {
                    Error(e);
                    return;
                }

                if (!data.Ok)
                {
                    BadResponse();
                    return;
                }

                CurrentPlayer = data.Player;
                Welcome();
            });
        }