Ejemplo n.º 1
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 Setup()
        {
            int width  = 2;
            int height = 2;

            players = new List <ApiPlayer>();
            game    = new Game.Game(new GameStartOptions {
                Height = height, Width = width, StartingArmiesPerPlayer = 5
            });
            game.StartJoining();
        }
        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);
        }
Ejemplo n.º 4
0
        public static Game.Game InitializeGame(int height, int width, int numOfArmies)
        {
            GameStartOptions startOptions = new GameStartOptions {
                Height = height,
                Width  = width,
                StartingArmiesPerPlayer = numOfArmies
            };

            Game.Game newGame = new Game.Game(startOptions);

            newGame.StartJoining();
            return(newGame);
        }
        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();
        }
        public void CannotPlaceArmyWhenNotInArmyDeploymentState()
        {
            game = new Game.Game(new GameStartOptions {
                Height = 2, Width = 2, StartingArmiesPerPlayer = 5
            });
            game.StartJoining();

            //game.StartGame(); don't start the game, gamestate stays 'joining'

            var location     = new Location(0, 0);
            var placeResults = game.TryPlaceArmy(player1Token, location);

            placeResults.Should().BeFalse();
        }
        public IActionResult GameStatus()
        {
            GameStatus gameStatus;

            if (!memoryCache.TryGetValue("Status", out gameStatus))
            {
                gameStatus = game.GetGameStatus();
                if (gameStatus.GameState == GameState.Restarting)
                {
                    game.StartJoining();
                }
                MemoryCacheEntryOptions cacheEntryOptions = new MemoryCacheEntryOptions();
                cacheEntryOptions.AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(1);
                memoryCache.Set("Status", gameStatus, cacheEntryOptions);
            }

            return(Ok(gameStatus));
        }
        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 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);
        }