/// <summary>
        /// Accept the word that was previously set
        /// </summary>
        public async Task <WordGameStateInfo> AcceptWord()
        {
            var result = _wordGame.Solve(_activeWord);
            await BoardViewModel.AcceptWord(result);

            if (_wordGame.State.State == WordGameState.Won)
            {
                _audioPlaybackEngine.PlaySound(_winSound);
                if (_wordGame.ActiveTeamIndex == 0)
                {
                    _state.Team1.Score += 25;
                }
                else
                {
                    _state.Team2.Score += 25;
                }
            }
            else if (_wordGame.State.State == WordGameState.SwitchTeam)
            {
                _state.SwitchActiveTeam();
                if (_wordGame.State.Flags == SwitchTeamFlags.Normal)
                {
                    // attempt made by opposing team is not valid. back to original team.
                    await BoardViewModel.StartNextAttempt(_wordGame.KnownLetters);
                }
            }
            else if (_wordGame.State.State == WordGameState.Ongoing)
            {
                await BoardViewModel.StartNextAttempt(_wordGame.KnownLetters);
            }



            return(_wordGame.State);
        }
Exemple #2
0
        public void Timeout_NoCorrectGuess_StateSetToSwitchTeamAndAddBonusLetter()
        {
            var puzzleEntry = new WordPuzzleEntry(new[]
            {
                new WordPuzzleLetterEntry('a', LetterState.CorrectLocation),
                new WordPuzzleLetterEntry('a', LetterState.CorrectLocation),
                new WordPuzzleLetterEntry('a', LetterState.CorrectLocation),
                new WordPuzzleLetterEntry('b', LetterState.IncorrectLocation),
                new WordPuzzleLetterEntry('b', LetterState.IncorrectLocation),
            });

            var wordPuzzleMock = new Mock <WordPuzzle>("aaaaa");

            wordPuzzleMock.Setup(x => x.Solve(It.IsAny <string>())).Returns(puzzleEntry);


            WordGame wordGame = new WordGame(wordPuzzleMock.Object, 0);

            wordGame.Solve("aaabb");
            wordGame.TimeOut();

            Assert.AreEqual(1, wordGame.ActiveTeamIndex);
            Assert.AreEqual(1, wordGame.AttemptIndex);
            Assert.AreEqual(WordGameState.SwitchTeam, wordGame.State.State);
            Assert.IsTrue((wordGame.State.Flags & SwitchTeamFlags.AddRow) != SwitchTeamFlags.AddRow);
            Assert.IsTrue((wordGame.State.Flags & SwitchTeamFlags.AddBonusLetter) == SwitchTeamFlags.AddBonusLetter);
        }
Exemple #3
0
        public void Timeout_WordAlmostGuessed_StateSetToSwitchTeam()
        {
            var puzzleEntry = new WordPuzzleEntry(new[]
            {
                new WordPuzzleLetterEntry('a', LetterState.CorrectLocation),
                new WordPuzzleLetterEntry('a', LetterState.CorrectLocation),
                new WordPuzzleLetterEntry('a', LetterState.CorrectLocation),
                new WordPuzzleLetterEntry('a', LetterState.CorrectLocation),
                new WordPuzzleLetterEntry('b', LetterState.IncorrectLocation),
            });

            var wordPuzzleMock = new Mock <WordPuzzle>("aaaaa");

            wordPuzzleMock.Setup(x => x.Solve(It.IsAny <string>())).Returns(puzzleEntry);


            WordGame wordGame = new WordGame(wordPuzzleMock.Object, 0);

            wordGame.Solve("aaaab");
            wordGame.TimeOut();

            Assert.AreEqual(1, wordGame.ActiveTeamIndex);
            Assert.AreEqual(1, wordGame.AttemptIndex);
            Assert.AreEqual(WordGameState.SwitchTeam, wordGame.State.State);
            Assert.AreEqual(SwitchTeamFlags.ClearRow, wordGame.State.Flags);
        }
Exemple #4
0
        public void Solve_5IncorrectAnswers_SwitchesTeam()
        {
            var puzzleEntry = new WordPuzzleEntry(Enumerable.Repeat(new WordPuzzleLetterEntry('a', LetterState.IncorrectLocation), 5).ToArray());


            var wordPuzzleMock = new Mock <WordPuzzle>("aaaa");

            wordPuzzleMock.Setup(x => x.Solve(It.IsAny <string>())).Returns(puzzleEntry);


            WordGame wordGame = new WordGame(wordPuzzleMock.Object, 0);

            wordGame.Solve("aaaaa");
            wordGame.Solve("aaaaa");
            wordGame.Solve("aaaaa");
            wordGame.Solve("aaaaa");
            wordGame.Solve("aaaaa");

            Assert.AreEqual(1, wordGame.ActiveTeamIndex);
            Assert.AreEqual(5, wordGame.AttemptIndex);
            Assert.AreEqual(WordGameState.SwitchTeam, wordGame.State.State);
            Assert.IsTrue((wordGame.State.Flags & SwitchTeamFlags.AddRow) == SwitchTeamFlags.AddRow);
            Assert.IsTrue((wordGame.State.Flags & SwitchTeamFlags.AddBonusLetter) == SwitchTeamFlags.AddBonusLetter);
        }
Exemple #5
0
        public void Solve_InCorrectAnswer_StateIsSetToOnGoing()
        {
            var puzzleEntry = new WordPuzzleEntry(Enumerable.Repeat(new WordPuzzleLetterEntry('a', LetterState.IncorrectLocation), 5).ToArray());


            var wordPuzzleMock = new Mock <WordPuzzle>("aaaaa");

            wordPuzzleMock.Setup(x => x.Solve(It.IsAny <string>())).Returns(puzzleEntry);


            WordGame wordGame = new WordGame(wordPuzzleMock.Object, 0);

            wordGame.Solve("bbbbb");

            Assert.AreEqual(0, wordGame.ActiveTeamIndex);
            Assert.AreEqual(1, wordGame.AttemptIndex);
            Assert.AreEqual(WordGameState.Ongoing, wordGame.State.State);
        }
Exemple #6
0
        public void Solve_6IncorrectAnswers_GameIsLostAndOtherTeamIsStillActive()
        {
            var puzzleEntry = new WordPuzzleEntry(Enumerable.Repeat(new WordPuzzleLetterEntry('a', LetterState.IncorrectLocation), 5).ToArray());


            var wordPuzzleMock = new Mock <WordPuzzle>("aaaa");

            wordPuzzleMock.Setup(x => x.Solve(It.IsAny <string>())).Returns(puzzleEntry);


            WordGame wordGame = new WordGame(wordPuzzleMock.Object, 0);

            wordGame.Solve("aaaaa");
            wordGame.Solve("aaaaa");
            wordGame.Solve("aaaaa");
            wordGame.Solve("aaaaa");
            wordGame.Solve("aaaaa");
            wordGame.Solve("aaaaa");

            Assert.AreEqual(1, wordGame.ActiveTeamIndex);
            Assert.AreEqual(6, wordGame.AttemptIndex);
            Assert.AreEqual(WordGameState.Lost, wordGame.State.State);
        }