Exemplo n.º 1
0
 /// <summary>
 /// Sets puzzle state string with matching blocks
 /// </summary>
 private void SetInitialPuzzleState()
 {
     PuzzleState = new string(CurrentPhrase.Select(c => c == ' ' ? ' ' : '█').ToArray());
     SetPuzzleState('-');
     SetPuzzleState('&');
     SetPuzzleState('\'');
     SetPuzzleState('.');
 }
Exemplo n.º 2
0
        /// <summary>
        /// Counts instances of given char in current puzzle
        /// </summary>
        /// <param name="c">The char the player has guessed</param>
        /// <returns>True - if count > 0</returns>
        public bool MakeGuess(char c)
        {
            Letters[c] = false;
            int count = CurrentPhrase.ToUpper().Count(f => f == c);

            Players[CurrentPlayer].Score += CurrentPrize * count;
            if (count <= 0)
            {
                return(false);
            }
            SetPuzzleState(c);
            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Will replace any matching blocks in the puzzle state with the given char
        /// </summary>
        /// <param name="c">the char to uncover</param>
        private void SetPuzzleState(char c)
        {
            StringBuilder sb = new StringBuilder(PuzzleState);
            string        upperCurrentPhrase = CurrentPhrase.ToUpper();

            for (int i = 0; i < CurrentPhrase.Length; i++)
            {
                if (upperCurrentPhrase[i] == c)
                {
                    sb[i] = c;
                }
            }

            PuzzleState = sb.ToString();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Checks if a player's solution guess matches the current puzzle. If so - add current prize X remaining hidden letters to player's score.
        /// </summary>
        /// <param name="playerGuess">The string that the player has entered as a guess</param>
        public void GuessAnswer(string playerGuess)
        {
            if (string.Equals(CurrentPhrase, playerGuess, StringComparison.CurrentCultureIgnoreCase))
            {
                string upperCurrentPhrase = CurrentPhrase.ToUpper();
                int    remainingBlocks    = Enumerable.Range(0, CurrentPhrase.Length)
                                            .Count(i => PuzzleState[i] != upperCurrentPhrase[i]);

                Players[CurrentPlayer].Score += CurrentPrize * remainingBlocks;
                gameOver = true;
            }
            else
            {
                NextPlayer();
            }
            updateAllUsers();
        }
Exemplo n.º 5
0
 public void SavePhrase()
 {
     CurrentPhrase.Save();
     CurrentPhrase = new Models.Phrase();
 }