Question
I need help with my hang man game. This is what i have so far #define _CRT_SECURE_NO_WARNINGS #include #include #include #define MAXGUESSES 6 void HangmanRules();
I need help with my hang man game.
This is what i have so far
#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
#define MAXGUESSES 6
void HangmanRules();
void PlayAgain(char *again);
//this function runs one game.
//input: character from the file, void return type
//all other functions to Play one round of a game
//are called from within the PlayOneGame function
void PlayOneGame(char answer[]);
//this function changes a character array to all uppercase letters
void UpperCaseWord(char Letter[]);
//this function creates the starword array
void CreateStarword(char star[], int length);
//this function gets the users guess letter and adds it to the lettersGuessed array
//returns the letter entered by the user
char GetTheLetterGuess(char lettersGuessed[], int *numPtr);
//this function replaces any asterik in the starword with the current character enteed by the user
int ReplaceStars(char answer[], char star[], char letter);
//this function gets the guess word,
//compares the solution and the guess word
//tells the user if they have won and returns a 1
//otherwise it returns a 0
int DidYouWin(char answer[]);
int main()
{
int a;
char star[80];
char letters[80];
char guesses[80];
char answer[80];
char Letter[80];
FILE *open;
open = fopen("hangmanWords.txt","r+");
char againPtr='y';
HangmanRules();
// do while loop: start new game, close the game
do
{
fscanf(in, " %s", &answer);
PlayOneGame(answer);
printf(" %s", answer);
PlayAgain(&again);
}while (againPtr != 'N');
fclose(open);
return 0;
}
void HangmanRules()
{
printf(" !!!!!!!!!!!!!!!!!!!Welcome to the HANGMAN GAME!!!!!!!!!!!!!!!!! "); /**Brief description of the game**/
printf(" You will get 5 chances to guess the right word");
printf(" So help the Man and get...set...GO..!!");
}
void PlayAgain(char *again)
{
printf("play another game ( y or n )?");
scanf(" %c", againPtr);
*again= toupper(*again);
}
void UpperCaseWord(char Letter[])
{
int allWord = strlen(word);
for (int x = 0; x
{
Letter[i] = toupper(Letter[i]);
}
}
I could'nt get the function to change solution to capital and create starword. than replace star word with correct answer that user input.
1. Write the hangman algorithm 2. Create a project and name the source code hangmanGame.c 3. Add the function prototype and implement the function definition for the Hangman instructions function 4. Add the function call in the main function build run and test 5. Create and implement the (y or n) loop in the main function, I suggest using a do/while loop 6. Add the function prototype and implement the function definition for the function that determines if the player wants to play another round 7. Add the function call build run and test 8. Go to the assignment and save "hangmanWords.txt" into the same directory as hangmanGame.c (remember to use your Z drive on portal.eng.fau.edu) 9. Declare a file pointer variable, connect to the input file and use fscanf to read a word from the file 10. Remember to add the space in fscanf for %s 11. Use printf statements to see the word from the file print onto the screen (inside the loop) build run and test Each time you enter y a new word will be read from the file and printed on the screen GET HELP HERE IF YOU CANNOT CONNECT, READ AND PRINT THE WORDS FROM THE FILE) 12. Add the function prototype and implement the function definition for the function that changes a character array to all one case (upper or lower) Use the toupper or tolower function (from ctype.h) to change each letter in the word to upper or lowercase (Hint: you need to loop thru the array character by character) a, word[1] #toupper(word[1]); //example build run and test (use printf to test) 13. Now it is time to create the Play one round function and pass the solution word to this function, make the function prototype, prepare the definition and call the function from inside the do/while loop in main 14. Declare 2 character arrays inside the Play One Round of the game function (starword, lettersGuessed) initialize lettersGuessed to the empty string (10). 15. Add the function prototype and implement the function definition for the create starword function, pass the empty starword and the number of letters in the solution word to this function, you need to use a loop to assign*to each character in the array, do not forget to add the '0' null character build run and test 16. There will be a loop inside the Play one round function that will continue until the user has used up 6 (MAXGUESSES) or guesses correctly An entire round of the game: i. ii. iii. iv. v. vi. Present the starword Present the letters guessed so far Get a character guess Check if the character is in the word If it is in the word let the user enter a word guess (userGuess) Check if the userGuess matches the solution if yes the user wins if not go back to (i) 1. Write the hangman algorithm 2. Create a project and name the source code hangmanGame.c 3. Add the function prototype and implement the function definition for the Hangman instructions function 4. Add the function call in the main function build run and test 5. Create and implement the (y or n) loop in the main function, I suggest using a do/while loop 6. Add the function prototype and implement the function definition for the function that determines if the player wants to play another round 7. Add the function call build run and test 8. Go to the assignment and save "hangmanWords.txt" into the same directory as hangmanGame.c (remember to use your Z drive on portal.eng.fau.edu) 9. Declare a file pointer variable, connect to the input file and use fscanf to read a word from the file 10. Remember to add the space in fscanf for %s 11. Use printf statements to see the word from the file print onto the screen (inside the loop) build run and test Each time you enter y a new word will be read from the file and printed on the screen GET HELP HERE IF YOU CANNOT CONNECT, READ AND PRINT THE WORDS FROM THE FILE) 12. Add the function prototype and implement the function definition for the function that changes a character array to all one case (upper or lower) Use the toupper or tolower function (from ctype.h) to change each letter in the word to upper or lowercase (Hint: you need to loop thru the array character by character) a, word[1] #toupper(word[1]); //example build run and test (use printf to test) 13. Now it is time to create the Play one round function and pass the solution word to this function, make the function prototype, prepare the definition and call the function from inside the do/while loop in main 14. Declare 2 character arrays inside the Play One Round of the game function (starword, lettersGuessed) initialize lettersGuessed to the empty string (10). 15. Add the function prototype and implement the function definition for the create starword function, pass the empty starword and the number of letters in the solution word to this function, you need to use a loop to assign*to each character in the array, do not forget to add the '0' null character build run and test 16. There will be a loop inside the Play one round function that will continue until the user has used up 6 (MAXGUESSES) or guesses correctly An entire round of the game: i. ii. iii. iv. v. vi. Present the starword Present the letters guessed so far Get a character guess Check if the character is in the word If it is in the word let the user enter a word guess (userGuess) Check if the userGuess matches the solution if yes the user wins if not go back to (i)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started