public void SetUp()
        {
            testgame = new Game.Game(new GameStartOptions {
                Height = 2, Width = 2, StartingArmiesPerPlayer = 5
            });
            testgame.StartJoining();
            player1Token = Guid.NewGuid().ToString();
            player2Token = Guid.NewGuid().ToString();
            testgame.AddPlayer(new ApiPlayer("player1", player1Token, null));
            testgame.AddPlayer(new ApiPlayer("player2", player2Token, null));

            testgame.StartGame();

            //place 5 armies
            testgame.TryPlaceArmy(player1Token, territory1.Location);
            testgame.TryPlaceArmy(player1Token, territory1.Location);
            testgame.TryPlaceArmy(player1Token, territory1.Location);
            testgame.TryPlaceArmy(player1Token, territory1.Location);
            testgame.TryPlaceArmy(player1Token, territory1.Location);

            //player2 places 5 armies
            testgame.TryPlaceArmy(player2Token, territory2.Location);
            testgame.TryPlaceArmy(player2Token, territory2.Location);
            testgame.TryPlaceArmy(player2Token, territory2.Location);
            testgame.TryPlaceArmy(player2Token, territory2.Location);
            testgame.TryPlaceArmy(player2Token, territory2.Location);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
 public void SetUp()
 {
     players = new List <ApiPlayer>();
     game    = new Game.Game(new GameStartOptions {
         Height = 2, Width = 2, StartingArmiesPerPlayer = 5
     });
     game.StartJoining();
     game.AddPlayer(new ApiPlayer("player1", "", null));
     game.AddPlayer(new ApiPlayer("player2", "", null));
 }
        public void GetGameStatusReturnsAllPlayersWhoveJoined()
        {
            var player1 = new ApiPlayer("player1", "token", null);

            game.AddPlayer(player1);

            var gameStatus = game.GetGameStatus();

            Assert.IsTrue(gameStatus.Players.Count() == 1);
        }
        public void SetUp()
        {
            game = new Game.Game(new GameStartOptions {
                Height = 2, Width = 2, StartingArmiesPerPlayer = 5
            });
            game.StartJoining();

            player1Token = Guid.NewGuid().ToString();
            player2Token = Guid.NewGuid().ToString();

            game.AddPlayer(new ApiPlayer("player1", player1Token, null));
            game.AddPlayer(new ApiPlayer("player2", player2Token, null));
            game.StartGame();
        }
Ejemplo n.º 6
0
        public void SetUp()
        {
            var httpClientMock = new Mock <HttpClient>();
            //httpClientMock.Setup()

            var loggerMock = new Mock <ILogger <GameRunner> >();

            game = new Game.Game(new GameStartOptions {
                Height = 2, Width = 2, StartingArmiesPerPlayer = 1
            });
            game.StartJoining();

            player1Token = Guid.NewGuid().ToString();
            player2Token = Guid.NewGuid().ToString();

            game.AddPlayer(new ApiPlayer("player1", player1Token, null));
            game.AddPlayer(new ApiPlayer("player2", player2Token, null));

            game.StartGame();
            gameRunner = new GameRunner(game, loggerMock.Object);
        }
        public void MakeAPlayer()
        {
            var game = new Game.Game(new GameStartOptions {
                Height = 2, Width = 2
            });

            game.StartJoining();
            var playerToken = Guid.NewGuid().ToString();

            game.AddPlayer(new ApiPlayer("player 1", playerToken, null));
            game.Players.Count().Should().Be(1);
        }
        public async Task AddPlayerAfterGameStarts()
        {
            var game = new Game.Game(new GameStartOptions {
                Height = 2, Width = 2
            });

            game.StartJoining();

            var playerToken = Guid.NewGuid().ToString();

            game.AddPlayer(new ApiPlayer("player 1", playerToken, null));
            Guid.TryParse(playerToken, out var _).Should().BeTrue();
            game.StartGame();

            var gameController = new GameController(game, null, null, null, logger);

            var response = await gameController.Join(new JoinRequest { Name = "Player2", CallbackBaseAddress = "" });

            Assert.IsInstanceOf <BadRequestObjectResult>(response);
        }
Ejemplo n.º 9
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"));
            }
        }