Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have a program here with 4 functions that I must implement, almost all of them are focused on strings: This is the program: #include

I have a program here with 4 functions that I must implement, almost all of them are focused on strings:

image text in transcribed

This is the program:

#include #include #include

#include "gameFunctions.h"

initializeBlankString() {}

printWithSpaces() {}

revealGuessedLetter() {}

checkGuess() {}

void startGame(char word[25]) { int won = 0; // Flag to see if the user has won yet int numBadGuesses = 0; // Counter to end the game on a lose condition int possibleBadGuesses; // Total number of bad guesses allowed int charRevealed; // Flag to see if the user guessed a good letter char guess; // The user's guess char revealedLetters[25]; // What the user has revealed so far

// Initializes the guessing array to all underscores initializeBlankString(strlen(word), revealedLetters); clearScreen();

// Gets the total number of chances printf( "Please enter the total number of incorrect guesses you would like to be " "able to make: "); scanf("%d", &possibleBadGuesses); printWithSpaces(revealedLetters);

// Runs the game loop until the number of tries are exhausted or the word is // found while (numBadGuesses

// Updates the revealed letters and checks to see if the user won charRevealed = revealGuessedLetter(word, revealedLetters, guess); won = checkGuess(word, revealedLetters);

// Increments bad guesses if the last guess was a miss if (!charRevealed) { numBadGuesses++; }

// Outputs game information to the user drawHorse(numBadGuesses, possibleBadGuesses); printWithSpaces(revealedLetters); }

if (won) printf("Congratulations! You correctly guessed the word %s ", word); else printf("You've run out of guesses. The correct word was %s ", word); }

// Draws part of the horse pending on how many guesses have been made so far // Horse grabbed from: http://www.virtualhorses.com/graphics/asciiart.htm // And no, I don't know why there's an entire site dedicated to virtualhorses =/ void drawHorse(int guessedSoFar, int allowedGuesses) { // The horse! Duh! char horsey[14][29] = {{" (\\(\\_\\\0"}, {" _.o o`\\\\\\\\\0"}, {"('_ ))))\0"}, {" '---' (((( .=,\0"}, {" ) )))___.-''-./=;\\\\\\\0"}, {" / ((( \\ ))))\0"}, {" ; | |//\0"}, {" /\\ | | ((\0"}, {" ( \\ /__.-'\\ / )\0"}, {" / /` | / \\ \\ |\0"}, {"/ / \\ ; \\ (\\ (\0"}, {"\\\\_ || || ||\0"}, {" \\_] || || ||\0"}, {" /_

clearScreen();

// Determines how much of the horse to print and prints it double ratio = (double)guessedSoFar / (double)allowedGuesses; int linesToDraw = floor(ratio * 13); linesToDraw = linesToDraw

int i; for (i = 14 - linesToDraw; i

void clearScreen() { // Some UNIX hackary to clear the terminal. Makes this not portable to some // systems, // but should work fine on CSE printf("\033[2J"); printf("\033[0;0f"); }

This is the .h file(No need to document):

//TODO: define, document, and implment this function printWithSpaces();

//TODO: define, document, and implment this function initializeBlankString();

//TODO: define, document, and implment this function revealGuessedLetter();

//TODO: define, document, and implment this function checkGuess();

//the following functions have been done for you.

/** * Sets the game up, checks for win condition, * prints relevant data */ void startGame(char *wordToGuess);

/** * Clears the unix terminal of previous input */ void clearScreen();

/** * Prints part of the horse based on the ratio between * the two numbers. */ void drawHorse(int guessedSoFar, int allowedGuesses);

o initializeBlankStringO - This function should take two arguments: an integer denoting the length of the second argument, which should be a char acter array. It should return nothing. The function should alter the passed array so that it is filled with underscores, _ and is a properly terminated string printWithSpaces) - This function will take a string as input and print the contents of the string with spaces between each character. (Hint: use the strlen function to find the size of the passed string). The function should return nothing o revealGuessedLetter) - This function will take two strings and a charac- ter as input. The function should alter the second string in the following way: For every position in the first string that contains the character passed in as the third argument to the function, change the same position in the second string to that character. For example, if the first string is "dinosaur" and the second is" should alter the second string so that it becomes".. assume that the strings are of equal length. The function should return a 1 if any letters were changed in the second string and 0 otherwise " and the character passed is a , then the function a_". You may o checkGuess() - This function should take two strings as input. If the two strings are equivalent, return a 1 from the function. If they're different, return a 0. There are at least two ways to do this you may use the strcmp() function from the string library or you can iterate over every character in the strings. You may assume that the strings are equal lengtlh

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions