Reference no: EM132840712
VBA Project
Write the code to play a number guessing game in Excel. The game is the old favorite that starts with a prompt like "I am thinking of a number between 0 and 20". And then you define how many guesses the guesser gets - they guess and you respond with answers like: "too high", "too low", "correct!". But, if the guesses uses up his/her guesses - they lose.
Create a "form-like" input area on a Worksheet on which the user will input the game parameters and see the game results. Consider these elements:
• Allow the user to enter the range of numbers for the guessing game: lower and upper numbers from which the secret number will be selected (the portion to handle the "I'm thinking of a number between").
• Let the user input the number of guesses they think they need to guess the secret number.
• These inputs should be entered directly on the worksheet by the person playing the game. You can prepopulate those cells with default values - like Low = 0, High = 20, Number of Guesses = 5 as that may save the game player some keystrokes! But, do not use an Inputbox to capture this input!
• Add a properly labeled button to the worksheet that will start the game play.
• Consider the best way to provide the response to each guess. Things you may want to include are:
o Guess count, for example Guess 3 of 5
o The value guesses by the user
o The response to the guess: "too high", "too low", "correct!"
• If the User runs out of guesses tell him/her. Provide some message to communicate that the game is over and that they are out of guesses.
• If the User guesses the secret number - output some congratulatory remark. (Better solutions could provide a few different remarks randomly - but this would be extra credit to figure that out - so don't make yourself crazy in that attempt.)
Your form needs to have a good UI and provide a great UX! It must be intuitive and easy to play! As much as is possible, elect to use the Excel worksheet for most inputs and outputs - to save the user from having to answer a lot of message boxes (and in case they can't remember their guesses and it's response).
In terms of operation - play the game with someone - just using paper. Make note of the interactions and the order of them.
In your solution, the user will enter their inputs on your Excel "form" and click the button to start the game. Your VBA code will need to generate a Random Number between the span of values provided by the user. A new random number should be generated each time the user plays the game - otherwise your game is only fun to play one time. Use the WorksheetFunction object to access the Excel RandBetween() function to generate your random number. Do not show the generated number to the user.
Use a loop that will provide the correct number of iterations, based upon the user's requested number of guesses. Inside the loop, use an input box to prompt the user to enter his/her guess. Evaluate the guess and provide an appropriate message in response to the guess in a designated output area so users can see what they have guessed and the program's response.
If the user guesses the number within the allotted guesses - stop the game and tell the user how many guesses it took to guess the correct answer. If the user fails to guess the number because they run out of attempts, provide an appropriate response to that as well.
The user may want to play the game more than once, thus, your VBA code should clear the game output area at the start of each new game.
Create a variation in which you will play the game with words. (This will definitely take a new worksheet - with a different user interface. Explain the rules and provide for any inputs needed to play the game).
Since you can't randomly create a word, manually create a word bank by adding a hidden worksheet that lists 10 - 20 words in Column A, make up a hint about the Word in Column B, provide a synonym (a word that means the same thing) in Column C and an antonym (something that means the opposite) in Column D. Use column E to place a value in the row to track if the word has been used in the round.
Ask the user how many words they want to guess (where each word is a round) - and tell them they have up to 3 guesses for each word.
Attachment:- VBA Project.rar