Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN C++ PLEASE. PROGRAM DESCRIPTION Lets play paintball, our version!!! Your opponent has entered your territory and you need to find him and shoot him

IN C++ PLEASE.

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

1. 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).

2. 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.

3. 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.

4. 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.

5. 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.

6. 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.

7. Inside a switch-case block, implement the following features.

a.

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.

o

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.

o

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)

b. 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.

o

If the user found the partner, inform the user that the partner has been

found

o

Double the number of remaining tries (See SAMPLE OUTPUT 5)

Check if the user chose the location of your opponent.

o

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)

c.

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.

8. 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.

9. Your program source code should be named

euidHW2.cpp

, without the quotes.

where euid should be replaced by your EUID.

10. 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.

We will be using an electronic homework submission on Canvas to make sure that all

students hand their programming projects on time. You will submit both (1) the program

source code file and (2) the algorithm design document to the

Homework 2

dropbox on

Canvas by the due date and time.

Homework are meant to be problem-solving exercises and are designed to help you practice

your coding on larger projects with various pieces of functionality. While the coding should

be primarily your sole work, you are allowed to get assistance from classmates when

working on these assignments. However, each student is required to report the name(s) of

the students they worked with on the assignment. All students who are part of a group

working on the assignment will receive the same grade. Cheating for these assignments is

now defined as copying from a fellow student without reporting it or copying from the

web. You should not copy someone elses code or let a classmate examine your code if

you have not identified as working in a group for your homework.

As a safety precaution, do not edit your program (using vim or nano) after you have submitted

your program where you might accidentally re-save the program, causing the timestamp on your

file to be later than the due date. If you want to look (or work on it) after submitting, make a copy

of your submission and work on that copy. Should there be any issues with your submission, this

timestamp on your code on the CSE machines will be used to validate when the program was

complete

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions

Question

to encourage a drive for change by developing new ideas;

Answered: 1 week ago

Question

4 What are the alternatives to the competences approach?

Answered: 1 week ago