Question
The project in this assignment is to build a text-only (pseudovideo) slot machine. If you have never seen a slot machine, search Google images for
The project in this assignment is to build a text-only (pseudovideo) slot machine. If you have never seen a slot machine, search Google images for pictures of a slot machine. A slot machine has 3 wheels. Each wheel as a set of pictures painted on the outside. During play, each wheel spins independently and comes to stop with one of its pictures showing in a window. The player wins if all three images are the same. This assignment is best solved by writing several little functions, where each function performs a small task in a bigger plan. The You will simulate the spinning of the wheel your game will use a random number. Each integer value represents one of the possible images. To show the state of one wheel, your game should print the name of the image associated with that number. The show the complete state of the machine, your game should print all three wheels, one after the other on the same line. If the player wins, your game should print the three image names (all the same) followed by the words YOU WIN! Playing the game means selecting the three random numbers and displaying the three images, either as a losing game, or as a winning game. Slot machines are designed to be addictive. Your game should make it easy for the player to play the same machine over and over again. All they have to do is hit the enter key. So your main should display only one prompt, and play the game each time the user hits enter. If the user types anything other than enter, and then enter, exit the loop and stop play. The six underlined functions, as mentioned above in order, perform the following tasks: 1) random_between() or randomBetween() return a random integer between an upper and lower bound passed as arguments, 2) print_image() or printImage() print the name of an image when passed its number as an argument, 3) print_game() or printGame() call the print image function three times, once for each wheel, 4) print_winning_game() or printWinningGame() do the same thing as 3a, only in a way to represent winning (with all three images the same), 5) play_game() or playGame() play the game by getting three random values for the three images and calling either the winning or non-winning display functions, and 6) main() initialize the random number generator, prompt the user, and loop as long as the user hits nothing but enter. For this assignment, you may use rand, srand, scanf, printf, while, do/while, if, else, else if, break or continue, but not getchar, switch/case, or for. You do not need to keep score, although you may if you wish. You may define and use additional functions (e.g. printImageAllCaps() see 2 nd example below) Here are some additional details. In a real slot machines matching different images have different winnings. Here we treat any match of all three as a winner. To calculate the odds of winning, think through the probabilities. Since any image can be a winner, it doesnt matter which image appears on the first wheel. It just matters that the next two wheels display the same image. So the odds of winning at 1 * (1 / number of different images on a wheel) * (1 / number of different images on a wheel). Put another way, any image on the first, proportion of images that can match the first on the second, and proportion of images that can match the first on the third. If there are 7 possible images, the odds of wining are 1 in (7 * 7) or 49. Since you have to play a lot to show one win, I recommend that you use only 4 different images to demonstrate your game in action. On a real slot machine, common images are cherries, a lemon, a peach, a bell, the number 7, a dollar sign, a diamond, or the word bar. (Some are more lucky than others.) You can find others choices by looking at images of slot machines on Google. You may use whatever nonoffensive image names you want. But remember, you only need 4. Before starting to work on this assignment, study up on using the C version of rand(), and the special issues around using scanf to read a single character. Unlike the previous assignments, using scanf to read a character will always return 1, since anything you hit on your keyboard is valid character. Even the newline represented by the Enter key is valid character: .
an example of what should be outputted:
Hit enter for each play, or q to quit: I lemon peach cherries | bell lemon lemon | bell l peach cherries peach | | cherries| bel1 |cherries peach | cherriesl peach cherries bel1 I lemon bel lemon | l cherries bell I lemon | cherries peach lemon | l peach peach lemon BELL BELL BELL YOU WIN! | peach bell emn bell |cherries peach | lemon lemon peach | bell cherries lemon l peach emon peach | |cherries bell lemon | I lemon cherries peach | BELL BELL BELL YOU WIN! LEMONLEMONLEMON YOU WIN! lemon cherries| bell |
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