using System; using System.Linq; class MainClass { publicstaticvoid Main (string[] args) { string[] words = newstring[4]{"sheep","goat","mouse","lion"}; Random rnd = new Random(); int random =...


using System;

using System.Linq;

class MainClass

{

publicstaticvoid Main (string[] args)

{

string[] words = newstring[4]{"sheep","goat","mouse","lion"};

Random rnd = new Random();

int random = rnd.Next(1, 3);

string secretWord = words[random];

bool wordTest = secretWord.All(Char.IsLetter);

while (wordTest == false || secretWord.Length == 0)

{

Console.WriteLine("A word must contain (only) letters");

Console.Write("Please enter a word: ");

secretWord = Console.ReadLine();

wordTest = secretWord.All(Char.IsLetter);

}

secretWord = secretWord.ToUpper();

MyGame(secretWord);

}

publicstaticvoid MyGame(String secretWord)

{

Console.WriteLine("\n\n");

int lives = 5;

int counter = -1;

int wordLength = secretWord.Length;

char[] secretArray = secretWord.ToCharArray();

char[] printArray = newchar[wordLength];

char[] guessedLetters = newchar[26];

int numberStore = 0;

bool victory = false;

foreach(char letter in printArray)

{

counter++;

printArray[counter] = '-';

}

while(lives > 0)

{

counter = -1;

string printProgress = String.Concat(printArray);

bool letterFound = false;

int multiples = 0;

if (printProgress == secretWord)

{

victory = true;

break;

}

if (lives > 1)

{

Console.WriteLine("You have {0} lives!", lives);

}

else

{

Console.WriteLine("You only have {0} life left!!", lives);

}

Console.WriteLine("current progress: " + printProgress);

Console.Write("\n\n\n");

Console.Write("Guess a letter: ");

string playerGuess = Console.ReadLine();

bool guessTest = playerGuess.All(Char.IsLetter);

while (guessTest == false || playerGuess.Length != 1)

{

Console.WriteLine("Please enter only a single letter!");

Console.Write("Guess a letter: ");

playerGuess = Console.ReadLine();

guessTest = playerGuess.All(Char.IsLetter);

}

playerGuess = playerGuess.ToUpper();

char playerChar = Convert.ToChar(playerGuess);

if (guessedLetters.Contains(playerChar) == false)

{

guessedLetters[numberStore] = playerChar;

numberStore++;

foreach(char letter in secretArray)

{

counter++;

if (letter == playerChar)

{

printArray[counter] = playerChar;

letterFound = true;

multiples++;

}

}

if (letterFound)

{

Console.WriteLine("Found {0} letter {1}!", multiples, playerChar);

}

else

{

Console.WriteLine("No letter {0}!", playerChar);

lives--;

}

}

else

{

Console.WriteLine("You already guessed {0}!!", playerChar);

}

}

if (victory)

{

Console.WriteLine("\n\nThe word was: {0}", secretWord);

Console.WriteLine("\n\nYOU WIN!!!!!!!!!!!");

}

else

{

Console.WriteLine("\n\nThe word was: {0}", secretWord);

Console.WriteLine("\n\nYOU LOSE!!!!!!!!!");

}

}

privatestaticstring DrawGuy(int livesLeft)

{

string drawHangman = "";

if (livesLeft <>

{

drawHangman += "--------\n";

}

if (livesLeft <>

{

drawHangman += " |\n";

}

if (livesLeft <>

{

drawHangman += " O\n";

}

if (livesLeft <>

{

drawHangman += " /|\\ \n";

}

if (livesLeft == 0)

{

drawHangman += " / \\ \n";

}

return drawHangman;

}

}


This code is not printing the hangman after every wrong guess and i'm not sure how to fix it.

Run<br>main.cs<br>Console<br>Shell<br>using System;<br>using System.Ling;<br>class MainClass<br>1<br>3<br>Guess a letter: a<br>No letter A!<br>{<br>public static void Main (string[] args)<br>You have 4 lives!<br>current progress:<br>{<br>string[] words = new string[4]{
0) { 38 Guess a letter: e 39 Found 1 letter E! 40 counter - -1; string printProgress = String.Concat (printArray); bool letterFound = false; int multiples = 0; 41 42 The word was: MOUSE 43 if (printProgress == secretword) { 44 YOU WIN!!!!!!!!!!! 45 "/>
Extracted text: Run main.cs Console Shell using System; using System.Ling; class MainClass 1 3 Guess a letter: a No letter A! { public static void Main (string[] args) You have 4 lives! current progress: { string[] words = new string[4]{"sheep","goat","mouse","lion"}; Random rnd = new Random(); 6 int random = rnd. Next(1, 3); string secretword - words[random]; bool wordTest = secretword.All(Char.IsLetter); while (wordTest == false || secretword.Length == 0) { Console.WriteLine("A word must contain (only) letters"); Console.Write("Please enter a word: "); Guess a letter: o 10 Found 1 letter o! You have 4 lives! 11 current progress: -0--- 12 13 14 15 Guess a letter: t No letter T! secretword = Console.ReadLine(); wordTest - secretword.All(Char.IsLetter); 16 You have 3 lives! 17 current progress: -o--- } secretword - secretword. ToUpper(); 18 19 MyGame (secretWord); } public static void MyGame (String secretword) { Console.Writeline("\n\n"); 20 21 Guess a letter: m Found 1 letter M! 22 You have 3 lives! 23 current progress: MO--- 24 25 int lives = 5; int counter = -1; int wordLength = secretword. Length; char[] secretArray = secretword.TocharArray (); char[] printArray = new char[wordLength]; char[] guessedLetters = new char[26]; 26 Guess a letter: u 27 Found 1 letter U! 28 You have 3 lives! 29 current progress: MOU-- 30 31 int numberstore = 0; 32 bool victory = false; foreach(char letter in printArray) { Guess a letter: s 33 Found 1 letter S! 34 You have 3 lives! 35 counter++; current progress: MOUS- printArray[counter] = '-'; 36 37 } while(lives > 0) { 38 Guess a letter: e 39 Found 1 letter E! 40 counter - -1; string printProgress = String.Concat (printArray); bool letterFound = false; int multiples = 0; 41 42 The word was: MOUSE 43 if (printProgress == secretword) { 44 YOU WIN!!!!!!!!!!! 45
Jun 09, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here