Ejemplo n.º 1
0
        public void Setup()
        {
            int width  = 2;
            int height = 2;


            IPlayer player  = new ApiPlayer("Rusty", "bazookaJoe", null);
            IPlayer player2 = new ApiPlayer("Emmanuel", "Macaco", null);

            game = new Game.Game(new GameStartOptions {
                Height = height, Width = width, StartingArmiesPerPlayer = 3
            });
            game.AddPlayer(new ApiPlayer("Rusty", "bazookaJoe", null));
            game.AddPlayer(new ApiPlayer("Emmanuel", "Macaco", null));
            Location attacker  = new Location(1, 1);
            Location attacker2 = new Location(0, 1);
            Location defender  = new Location(0, 0);
            Location defender2 = new Location(1, 0);

            game.StartGame();

            game.TryPlaceArmy(player.Token, attacker);
            game.TryPlaceArmy(player.Token, attacker);
            game.TryPlaceArmy(player.Token, attacker2);

            game.TryPlaceArmy(player2.Token, defender);
            game.TryPlaceArmy(player2.Token, defender);
            game.TryPlaceArmy(player2.Token, defender2);
        }
        public void GetGameStatusReturnsAllPlayersWhoveJoined()
        {
            var player1 = new ApiPlayer("player1", "token", null);

            game.AddPlayer(player1);

            var gameStatus = game.GetGameStatus();

            Assert.IsTrue(gameStatus.Players.Count() == 1);
        }
Ejemplo n.º 3
0
        public void Setup()
        {
            int width  = 2;
            int height = 2;

            game = new Game.Game(new GameStartOptions {
                Height = height, Width = width
            });
            IPlayer  player   = new ApiPlayer("Rusty", "kc7wzl", null);
            Location attacker = new Location(1, 1);

            territory       = new Territory(attacker);
            territory.Owner = player;
        }
        public void GetGameStatusHasPlayersWithArmyAndTerritoryCount()
        {
            var player1 = new ApiPlayer("player1", "token", null);

            game.AddPlayer(player1);

            game.StartGame();

            game.TryPlaceArmy(player1.Token, new Location(0, 0));

            var gameStatus = game.GetGameStatus();

            Assert.That(gameStatus.Board.Count() == 4);
            Assert.That(gameStatus.Board.Single(t => t.Location == new Location(0, 0)).Armies == 1);
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Join(JoinRequest joinRequest)
        {
            if (game.GameState == GameState.Joining && await ClientIsRepsonsive(joinRequest.CallbackBaseAddress))
            {
                var newPlayer = new ApiPlayer(
                    name: joinRequest.Name,
                    token: Guid.NewGuid().ToString(),
                    httpClient: clientFactory.CreateClient()
                    );
                newPlayer.HttpClient.BaseAddress = new Uri(joinRequest.CallbackBaseAddress);

                game.AddPlayer(newPlayer);

                return(Ok(new JoinResponse {
                    Token = newPlayer.Token
                }));
            }
            else
            {
                return(BadRequest("Unable to join game"));
            }
        }