Now that you have had experience tackling a larger coding project, it is time to expand your newly curated expertise to other scenarios. For this assignment, you will consider different strategies and approaches that you might have used if you selected one of the other two scenarios when working on your project. While there will be some differences, you will also notice areas where you could use similar tactics to those you already applied in your chosen project work. Highlighting these areas will be important in showing ways that the skills you have gained will continue to translate to other situations as you continue down your educational and professional pathway.
As a reminder, the scenarios you may choose from are as follows:
1. Cracked Egg Game: There are a dozen eggs in a basket; some are hard boiled and some are raw. The object of this game is for the user to guess the number of hard-boiled eggs prior to playing the game. The computer then simulates cracking all 12 eggs, using a random number 0 or 1 to simulate raw or hard boiled. The number 0 should represent raw eggs and the number 1 should represent hard boiled. The computer must keep track of the number of hard-boiled eggs. At the conclusion of cracking all 12 eggs, the actual number of hard boiled is compared to the user’s guess, and whether the user won or lost is given as output.
2. Spaceship Race: There are two spaceships racing across the galaxies toward a distant star. The spaceships make progress by getting a “boost,” or a value between 0 and 10. The first spaceship to reach the distant star wins. The distance of the star the spaceships are racing toward is provided as input by the user (a value between 25 and 100). The boost value is determined from the computer generating a random number between 0 and 10. The object is to have the spaceships race, and then as soon as one spaceship reaches the destination, which spaceship won or if there was a tie is provided as output.
3. Rock-Paper-Scissors: This is a game of chance normally played between two people. Similar to flipping a coin or drawing straws, it can be used as a method for determining a random winner. The rules of the game require that each player forms one of three shapes with their hand at the same time. The shapes are as follows:
· Rock, which is represented by a closed fist, will beat scissors because rock can crush scissors.
· Paper, which is represented by a flat hand, will beat rock because paper can cover rocks.
· Scissors, which are represented by the index and middle fingers forming a V, will beat paper because scissors can cut through paper.
In the computer version of this game, the user will play against the computer. The human user will choose rock, paper, or scissors, and the computer will also randomly choose rock, paper, or scissors. Use the integer value 1 to represent rock, 2 to represent paper, and 3 to represent scissors. The human user will input 1, 2, or 3. The computer will then choose a random number between 1 and 3. Based on the rules of the game, the computer will give output to show whether the user or the computer wins the game, or if it is a tie. The user will play 10 games and, at the conclusion of those 10 games, the computer will output the number of times the user won, the computer won, as well as the number of tied games.
To begin working on this assignment, first select one of the project scenarios that you did not already design a flowchart, pseudocode, and code for. Then begin thinking about how you would design one loop for the game you have selected.
Specifically, you must address the following rubric criteria:
· Explain how you would write code for one loop in the selected game. Be sure to mention any strategies you would need to use in your design. Remember that your loop will need to meet the requirements of the program. You should use a WHILE or a FOR loop along with the appropriate relational operators (==, !=, <, >, <=, and >=). Using the appropriate relational operators will also be important in ensuring there is an exit condition, so no infinite loops are created. As you work, you may wish to try sketching out a flowchart or drafting pseudocode to support your ideas. You do not need to create any code for this assignment, but you can also try out some practice code in the zyBook, which you can access in the links below. Doing this will help you analyze your thought process and check whether you are on the right track, if you choose. Focus on one of the following loops: