Exemplo n.º 1
0
 public Game()
 {
     Tried.Add(Word[0]);
     if (Word[0] != Word[Word.Length - 1])
     {
         Tried.Add(Word[Word.Length - 1]);
     }
     UpdateCurrentState();
     Errors = 0;
 }
Exemplo n.º 2
0
        public int LettersLeft()
        {
            var left = 0;

            for (var i = 1; i < Word.Length - 1; ++i)
            {
                if (!Tried.Contains(Word[i]))
                {
                    ++left;
                }
            }
            return(left);
        }
Exemplo n.º 3
0
        public int LettersAndSpacesLeft()
        {
            int left   = 0;
            int spaces = Word.Count(Char.IsWhiteSpace);

            for (int i = 0; i < Word.Length; ++i)
            {
                if (!Tried.Contains(Word[i]))
                {
                    left++;
                }
            }
            return(left - spaces);
        }
Exemplo n.º 4
0
 public bool Try(char letter)
 {
     letter = Char.ToUpper(letter);
     Tried.Add(letter);
     if (Word.Contains(letter))
     {
         UpdateCurrentState();
         return(true);
     }
     else
     {
         ++Errors;
         return(false);
     }
 }
Exemplo n.º 5
0
        public void UpdateCurrentState()
        {
            var currentState = new StringBuilder();

            for (var i = 0; i <= Word.Length - 1; i++)
            {
                if (Tried.Contains(Word[i]))
                {
                    currentState.Append($" {Word[i]} ");
                }
                else
                {
                    currentState.Append(" _ ");
                }
            }
            CurrentState = currentState.ToString();
        }
Exemplo n.º 6
0
 public bool Try(char letter)
 {
     letter = Char.ToUpper(letter);
     if (this.Tried.Contains(letter))
     {
         throw new Exception();
     }
     Tried.Add(letter);
     if (this.Word.Contains(letter))
     {
         UpdateCurrentState();
         return(true);
     }
     else
     {
         ++Errors;
         return(false);
     }
 }
Exemplo n.º 7
0
        public void UpdateCurrentState()
        {
            var currentState = new StringBuilder();

            currentState.Append($"{Word[0]} ");
            for (var i = 1; i < Word.Length - 1; ++i)
            {
                if (Tried.Contains(Word[i]))
                {
                    currentState.Append($"{Word[i]} ");
                }
                else
                {
                    currentState.Append("_ ");
                }
            }
            currentState.Append(Word[Word.Length - 1]);
            this.CurrentState = currentState.ToString();
        }