Question
PROGRAM DESCRIPTION Lets play paintball, our version!!! Your opponent has entered your territory and you need to find him and shoot him with paint. You
PROGRAM DESCRIPTION Lets play paintball, our version!!! Your opponent has entered your territory and you need to find him and shoot him with paint. You have a partner, but you lost her in the territory. Your objective is to choose a location (i.e. a set of x and y coordinates) in the territory and find your opponent. Choosing a location will mean you are shooting paint at that location. Just make sure you dont accidentally shoot your partner. If you do so, you lose. You have three tries to choose a location. You may also choose to find your partner first. If you can find her, your remaining tries double. But if you find your opponent by accident, youve alerted your opponent, and you lose. If you neither find your partner nor your opponent, you lose a try. You can retry, as long as you have tries remaining. If you are out of tries, you lose. Make sure you look at the sample output and go over the various scenarios of your game.
PROGRAM REQUIREMENTS As with all projects in this course, your programs output will display your name, your EUID, your e-mail address, the department name, and course number. This means that your program will print this information to the terminal (see the sample output).
Your territory is a square of size 10X10. Youll need to declare and initialize a constant named SIZE and initialize it with 10. Use this constant whenever you need to use the size of the square.
Place your opponent on a random location in the square. The permitted value in the horizontal as well as the vertical axis is 0 through 9. HINT: To implement this, you need to generate two random numbers-- one for the horizontal and the other for the vertical co-ordinate locations of your opponent.
Place your partner on a random location in the square. The permitted value in the horizontal as well as the vertical axis is 0 through 9. Make sure the locations of your partner and your opponent are not the same. HINT: To implement this, you need to place your partner in a random location in a loop and terminate the loop, only if the randomly selected location does not match the location of your opponent. Note: While playing the game, you cannot assume that you know where your opponent or the partner is located.
Using a suitable message, prompt the user (i.e. the sniper) for a location to shoot. If the user enters, a location outside the range of the square, inform the user of the error and prompt the user for the location again. (See SAMPLE OUTPUT 3) HINT: To implement this feature you can ask the user for the location in a loop and terminate the loop only when the entered values are within the range.
Ask the user whether, the user wants to attack your opponent or find the partner. To implement this feature, you must declare an enumeration constant with values OPPONENT and PARTNER. The user enters O to choose your opponent, P to choose the partner. The user may enter the choice in uppercase or lowercase.
Inside a switch-case block, implement the following features. If the user chose to attack the opponent Check if the user chose the correct location of the opponent by comparing the users selected location with the opponents actual location. If the user found the opponent, inform the user that the opponent has been struck with paint and the game has been won. (See SAMPLE OUTPUT 5) Check if the user chose the location of the partner. If the user found the partner, inform the user that the partner has accidentally been shot and the game is lost. (See SAMPLE OUTPUT 3) If the user neither found the opponent nor the partner, the user loses a try. Inform the user about the remaining number of tries. If all tries are over, inform the user that the game has been lost. (See SAMPLE OUTPUT 1)
If the user chose to find the partner Check if the user chose the correct location of the partner by comparing the users selected location with the partners actual location. If the user found the partner, inform the user that the partner has been found Double the number of remaining tries (See SAMPLE OUTPUT 5) Check if the user chose the location of your opponent. If the user found the opponent, inform the user that the opponent has been accidentally alerted and the game is lost. (See SAMPLE OUTPUT 4) If the user neither found the opponent nor the partner, the user loses a try. Inform the user about the remaining number of tries. Make sure the user cannot cheat by repeatedly finding the same partner. If the user tries to cheat this way, the user loses a try. Provide a suitable message and reduce the number of tries by 1 in this scenario. (See SAMPLE OUTPUT 5) HINT: To implement this feature, you can use a Boolean variable to track whether the partner has been found or not. If all tries are over, inform the user that the game has been lost. (See SAMPLE OUTPUT 2)
If the user enters any other option Inform the user of the wrong choice Your program must keep on asking the user for the choice, until the entered choice is either an opponent or a partner.
Your code should be well documented in terms of comments. For example, good comments in general consist of a header (with your name, course section, date, and brief description), comments for each variable, and commented blocks of code. This means, that in addition to the program printing your information to the terminal, it will also appear in the code in the comments as well.
Your program source code should be named euidHW2.cpp, without the quotes. where euid should be replaced by your EUID.
Your program will be graded based largely on whether it works correctly on the CSE machines (e.g., cse01, cse02, , cse06), so you should make sure that your program compiles and runs on a CSE machine.
DESIGN (ALGORITHM): On a piece of paper (or word processor), write down the algorithm, or sequence of steps, that you will use to solve the problem. You may think of this as a recipe for someone else to follow. Continue to refine your recipe until it is clear and deterministically solves the problem. Be sure to include the steps for prompting for input, performing calculations, and displaying output. You should attempt to solve the problem by hand first (using a calculator as needed) to work out what the answer should be for a few sets of inputs. Type these steps and calculations into a document (i.e., Word, text, or PDF) that will be submitted along with your source code. Note that if you do any work by hand, images (such as pictures) may be used, but they must be clear and easily readable. This document shall contain both the algorithm and any supporting hand-calculations you used in verifying your results.
SAMPLE OUTPUT 1
$ ./a.out Enter your guess:3 3 Do you want to attack your Opponent or find your Partner:O You missed your opponent. You have 2 tries remaining. Enter your guess:2 5 Do you want to attack your Opponent or find your Partner:O You missed your opponent. You have 1 tries remaining. Enter your guess:4 5 Do you want to attack your Opponent or find your Partner:O You missed your opponent. You have 0 tries remaining. You've finished all tries. Game over.
SAMPLE OUTPUT 2 $ ./a.out Enter your guess:3 9 Do you want to attack your Opponent or find your Partner:P You missed your partner. You have 2 tries remaining. Enter your guess:2 6 Do you want to attack your Opponent or find your Partner:O You missed your opponent. You have 1 tries remaining. Enter your guess:6 4 Do you want to attack your Opponent or find your Partner:P You missed your partner. You have 0 tries remaining. You've finished all tries. Game over. SAMPLE OUTPUT 3
$ ./a.out Enter your guess:10 12 Invalid Guess. Enter again Enter your guess:10 9 Invalid Guess. Enter again Enter your guess:2 4 Do you want to attack your Opponent or find your Partner:O You missed your opponent. You have 2 tries remaining. Enter your guess:7 3 Do you want to attack your Opponent or find your Partner:O Oops, you shot your partner. Game over!!!
SAMPLE OUTPUT 4
$ ./a.out Enter your guess:6 5 Do you want to attack your Opponent or find your Partner:P You missed your partner. You have 2 tries remaining. Enter your guess:2 5 Do you want to attack your Opponent or find your Partner:P Oops, you alerted your opponent. You lose. Game over. SAMPLE OUTPUT 5
$ ./a.out Enter your guess:2 7 Do you want to attack your Opponent or find your Partner:P You found your partner. You have 6 tries remaining. Enter your guess:2 5 Do you want to attack your Opponent or find your Partner:P You've already found your partner, don't cheat. You lose a try. You have 5 tries remaining. Enter your guess:4 4 Do you want to attack your Opponent or find your Partner:P You've already found your partner, don't cheat. You lose a try. You have 4 tries remaining. Enter your guess:8 8 Do you want to attack your Opponent or find your Partner:O You missed your opponent. You have 3 tries remaining. Enter your guess:7 3 Do you want to attack your Opponent or find your Partner:O You shot your opponent. You won. TESTING: Test your program to check that it operates as desired with a variety of inputs. Then, compare the answers your code gives with the ones you get from hand calculations.
SUBMISSION: Your program will be graded based largely upon whether it works correctly on the CSE machines, so you should make sure your program compiles and runs on the CSE machines.
Your program will also be graded based upon your program style. This means that you should use comments (as directed), meaningful variable names, and a consistent indentation style as recommended in the textbook and in class.
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