P7_THK
Competencies
In this project, you will demonstrate your mastery of the following competencies:
· Use basic programming constructs
· Develop a fully functional program
Scenario
Congratulations! Your flowchart and pseudocode design have been accepted! You are applying for a position as a software developer, and the company would now like you to move to the next round of code design. Remember, the company gave you three different possible programming challenges:
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.
1. Spaceship Race Game : 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.
1. Rock-Paper-Scissors Game : 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.
You will now write a Coral program to demonstrate your programming skills. Use the flowchart and pseudocode you designed in Project One as a basis for the code you will create. This will reflect the logic you will implement in your program.
Directions
For this project, you will write code in Coral for the programming game you have selected by accessing the activity in the zyBook. Note that links for each are provided in the Scenario section. The work you complete will be based on your flowchart and pseudocode designs from Project One. Be sure to refer to any feedback you received for Project One prior to beginning coding in Coral.
1. Determine the variables and relevant data types of each variable. Consider the necessary variables required to implement the logic of your game, as well as the relevant data type (i.e., integer or float) of each variable.
1. Initialize the variables using appropriate data values. Where necessary, assign an initial value to each variable. Note that variables that obtain an initial value from user input do not require initializing. For example, before you start simulating any of the games, there should be zero wins and losses.
1. Set branches that use conditionals to define the logic of the game. This must meet the requirements of the program. You may use the following types of statements to accomplish this:
· IF
· IF-ELSE
· IF-ELSE-IF
Statements must also use the appropriate relational operators, which are as follows:
· == (equals)
· != (not equal)
· < (less than)
· > (greater than)
· <= (less than or equal)
· >= (greater than or equal)
1. Create loops to define the logic, flow, and sequence of the game. This must meet the requirements of the program. Reference the Brief Tutorial on Coral, linked in the Supporting Materials section, for a reminder of how to create loops in Coral. Use WHILE or FOR loops along with the appropriate relational operators (==, !=, <, >, <=, and >=). Avoid infinite loops by ensuring the loop has an exit condition using the appropriate relational operator.
· Cracked Egg Game: This game will include looping 12 times. Determine what loop to use, then execute it based on program requirements.
· Spaceship Race: This will require an unspecified number of loops in order to lead a spaceship to the finish line. The looping will continue until the condition is met.
· Rock-Paper-Scissors: This game will include looping 10 times. Determine what loop to use, then execute it based on program requirements.
1. Apply necessary arithmetic operations. Note that mathematical operators include +, -, *, /, and % (modulo). These must meet the requirements of the program. See specific examples below for reference:
· Cracked Egg Game: Keep track of the number of hard-boiled eggs and raw eggs for the Cracked Egg game.
· Spaceship Race: Keep track of the distance traveled by a spaceship in the Spaceship Race game.
· Rock-Paper-Scissors: Keep track of the number of times the player has won in the Rock-Paper-Scissors game.
1. Ensure there are no syntax errors in your code. Use the Coral simulator to make sure there are no syntax errors that prevent your code from running. Fix any syntax errors that may arise so that your code can execute.
1. Determine whether your code functions correctly. Check for logic errors using the Coral simulator by testing it with several different input values to ensure it executes correctly. The Coral simulator will automatically check your code as you enter it, so now you are checking for things it might not pick up on. Also recall that you have already created a flowchart in Project One. Now the Coral simulator will automatically create a flowchart for the code you have built. Be sure to toggle to the flowchart and check it against what you have already created to ensure the design matches your intention. Fix any issues that arise during this testing process. Your updates should result in a functioning program with proper outputs based on the logic of the game.
1. Write code using best practices including appropriate syntax and commenting. This includes the following:
· Using descriptive names for your variables
· Using the correct formatting structure with appropriate indentations
· Using appropriate comments relating to your code
What to Submit
To complete this project, you must submit the following:
Coral Game Code Once complete, copy your code into a plain text file; this will include the TXT tag at the end of its file name. This will help ensure that none of your code’s formatting gets shifted during the copying process. Once you have completed the TXT file, submit it for grading.
Supporting Materials
The following resource(s) may help support your work on the project:
Brief Tutorial on Coral - https://corallanguage.org/tutorial/
Use this brief tutorial to get up to speed on creating loops in Coral. Scroll to the “WHILE loops” and “FOR loops” sections.
Ref https://www.wired.com/2013/12/googles-doodle-honors-grace-hopper-and-entomology/