Ejemplo n.º 1
0
        private async Task <IGame> CreateGame(string language, int boardId, IUser player01, IUser player02)
        {
            var lexicon = await lexiconService.GetDictionary(language);

            if (lexicon == null)
            {
                throw new ApplicationException($"Invalid language [{language}]");
            }
            var board = await GetBoard(boardId);

            if (board == null)
            {
                throw new ApplicationException($"Invalid board [{boardId}]");
            }


            var p1Details = await userRepository.GetDetails(player01.UserName);

            var p2Details = await userRepository.GetDetails(player02.UserName);

            var letterbag = new LetterBag(language);
            var game      = new Game
            {
                Id           = Guid.NewGuid().ToString().Replace("-", "").ToUpper(),
                Language     = language,
                CreationDate = DateTime.UtcNow,
                Board        = board,
                LetterBag    = letterbag,
                PlayMoves    = new List <IPlayMove>(),
                Player01     = new GamePlayer
                {
                    UserName  = player01.UserName,
                    FirstName = p1Details.FirstName,
                    LastName  = p1Details.LastName,
                    Rack      = letterbag.TakeLetters(7),
                    Score     = 0
                },
                Player02 = new GamePlayer
                {
                    UserName  = player02.UserName,
                    FirstName = p2Details.FirstName,
                    LastName  = p2Details.LastName,
                    Rack      = letterbag.TakeLetters(7),
                    Score     = 0
                },
                CurrentPlayer    = player01.UserName,
                Status           = GameStatus.Ongoing,
                CurrentStart     = DateTime.UtcNow,
                AvailableLetters = lexicon.Language.GetLettersOnly()
            };

            return(game);
        }