Exemple #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);
        }
Exemple #2
0
        public void AreAnagrams(string super, params string[] others)
        {
            var bigBag = new LetterBag(super);

            foreach (var word in others)
            {
                if (bigBag.TryGetAnagramRemainder(new LetterBag(word), out var remainder))
                {
                    bigBag = remainder;
                }
                else
                {
                    Assert.True(false, $"'{word}' not found in bag.");
                }
            }

            Assert.Equal(0, bigBag.Count);
        }
Exemple #3
0
 public RackTile(Player player, IContainer ioc) : base("#EDBD11")
 {
     Aggregator = ioc.Get <IEventAggregator>();
     Letter     = LetterBag.GetLetter();
     Player     = player;
 }