Exemplo n.º 1
0
        public async Task NewGameAsync()
        {
            await LoadAsync();

            _myGamePlayer  = null;
            _doCheck       = false;
            _qrCodeContent = null;

            Settings.CurrentScoreIx = 0;
            Game          = new NewGameDto();
            SelectedVenue = null;
            GameType      = Settings.LastGameType;
            TeeCount      = Settings.LastTeeCount;
            StartTee      = 1;

            InvitationNumber = GenerateInvitationNumber();
            QrCodeContent    = $"{Properties.Resources.QrCodeUrl}{InvitationNumber}";

            PlayersCount = Settings.LastPlayersCount;
            Players.Clear();
            Players.Add(MyPlayer);

            CurrentPage          = CreateGamePage.VenueSelection;
            CurrentPageIndex     = (int)CurrentPage;
            StartButtonIsVisible = true;
            StartingIsBusy       = false;
            _doCheck             = true;
            CheckNextPage();
        }
Exemplo n.º 2
0
        public async Task <IActionResult> NewGame([FromBody] NewGameDto newGame)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            await _playerService.AddAsync(_mapper.Map <PlayerDto, Domain.Models.Player>(new PlayerDto
            {
                PlayerName   = newGame.Player1,
                PlayerNumber = 1
            }));

            await _playerService.AddAsync(_mapper.Map <PlayerDto, Domain.Models.Player>(new PlayerDto
            {
                PlayerName   = newGame.Player2,
                PlayerNumber = 2
            }));

            var game = await _gameService.AddAsync(_mapper.Map <GameDto, Domain.Models.Game>(new GameDto
            {
                EndGame = false,
                PlayerGameWinnerName = ""
            }));

            return(Ok(_mapper.Map <Domain.Models.Game, GameDto>(game)));
        }
Exemplo n.º 3
0
        public static CreateGamePage GetNextNewGamePage(NewGameDto game, CreateGamePage currentPage)
        {
            var nextPage = CreateGamePage.VenueSelection;

            game.Game.GameStatus = GameStatus.Creating;
            if (game.Venue == null)
            {
                return(nextPage);
            }
            nextPage = CreateGamePage.PropertySelection;
            if (game.Game.TeeCount <= 0 || game.Game.InvitedPlayersCount <= 0 || ProceedOnePage(nextPage, currentPage))
            {
                return(nextPage);
            }
            nextPage = CreateGamePage.InvitationSelection;

            game.Game.GameStatus = GameStatus.ConfirmationsReceiving;

            if (game.Players.Count < game.Game.InvitedPlayersCount || ProceedOnePage(nextPage, currentPage))
            {
                return(nextPage);
            }

            game.Game.GameStatus = GameStatus.ConfirmationsComplete;
            return(CreateGamePage.Ready);
        }
        public async Task StartNewGameTest()
        {
            var gameLogic = new Mock <IGameLogic>();

            gameLogic.Setup(x => x.GenerateBoad())
            .Returns(new BoardInfo());

            var game = GameState.CreateNew(gameLogic.Object);

            game.ConnectionId = "connectionId";

            var gameService = new Mock <IGameService>();

            gameService.Setup(x => x.StartNewGameAsync(It.IsAny <string>()))
            .ReturnsAsync(game);

            var controller = new GameController(gameService.Object, _mapper, _statisticsSvcMock.Object);
            var output     = await controller.StartNewGame("connectionid");

            Assert.AreEqual(output.GetType(), typeof(OkObjectResult));
            Assert.AreEqual(((OkObjectResult)output).Value.GetType(), typeof(NewGameDto));

            NewGameDto dto = ((NewGameDto)((OkObjectResult)output).Value);

            Assert.AreEqual(game.GameId, dto.GameId);

            //gameService.VerifyAll();
        }
Exemplo n.º 5
0
        public async Task <IActionResult> StartNewGame([FromBody] string connectionId)
        {
            GameState game = await _gameSvc.StartNewGameAsync(connectionId);

            NewGameDto respDto = _mapper.Map <NewGameDto>(game);

            return(Ok(respDto));
        }
Exemplo n.º 6
0
        public async Task <NewGameDto> GetNewGame(string gameId)
        {
            var result = new NewGameDto
            {
                Game    = await GamesTable.LookupAsync(gameId).ConfigureAwait(false),
                Players = await GetPlayersForGame(gameId).ConfigureAwait(false),
            };

            result.Venue = await GetVenue(result.Game.VenueId).ConfigureAwait(false);

            return(result);
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Post([FromBody] NewGameDto newGameDto)
        {
            try
            {
                var mongodb = GetMongoCollection();
                var game    = new Game
                {
                    Id            = new ObjectId(),
                    ImageUrl      = newGameDto.ImageUrl,
                    Description   = newGameDto.Description,
                    Name          = newGameDto.Name,
                    Ratings       = new List <GameRating>(),
                    AverageRating = 0
                };

                await mongodb.InsertOneAsync(game);

                return(Ok(MapToDto(game)));
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }
        }