Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C+ Program: I need to develop and implement a program that simulates an archery

ID: 3758455 • Letter: C

Question

C+ Program:

I need to develop and implement a program that simulates an archery target shooting game in C+ programming, not C++. The goal of the simulation is to shoot an arrow at a target consisting of three concentric circles as shown below: Hitting the white region (the center) is worth 5 points; hitting the green region is worth 3 points; and hitting the red region is worth 1 point. 0 points for missing all the 3 regions. Instead, the program will use a random number generator to determine where the arrows land. After each arrow is shot (that is after a random number is generated), the program displays a message describing the result. After each round (i.e., a set of 5 shootings) is completed, the total score for that round is displayed. In addition, it should ask the user if s/he wants to continue the simulation. The program continues the simulation as long as the user wants. At each round, the player shoots 5 arrows from different distances: 10, 20, 30, 40, and 50. It will need to use functions to break a problem into smaller sub-problems. This reduces program complexity. It is supposed to implement 4 distinct functions. main chance shoot play The main function will be the driver of the program. It needs to create the loop that controls the rounds in the main function. After each iteration of the loop body, it should ask the player if s/he wants to continue. Please notice that it should start every iteration by calling the predefined functions srand and time, to ensure that the simulator generates random numbers properly. However, please notice that it will generate the random number in the function chance. The header (i.e., function declaration) of the function chance should be as follows: double chance(); The function chance simply returns a random value between 0.0 and 1.0. The third function that needs to be developed is called shoot. This function takes the distance as an argument. It returns the score of the shooting by using the random value returned by the chance function and the distance based on the following table below. distance score:5 score:3 score:1 score:0 10 0.0chance<0.50 0.50chance<0.90 0.90chance<0.95 0.95chance1.0 20 0.0chance<0.40 0.40chance<0.80 0.80chance<0.90 0.90chance1.0 30 0.0chance<0.30 0.30chance<0.60 0.60chance<0.75 0.75chance1.0 40 0.0chance<0.20 0.20chance<0.40 0.40chance<0.60 0.60chance1.0 50 0.0chance<0.10 0.10chance<0.20 0.20chance<0.45 0.45chance1.0 The header (i.e., function declaration) of the function shoot should be as follows: double shoot(int distance); The last function developed is the play function. The function play calls the function shoot, and it is responsible for calculating and displaying messages (please see the output below) for a single round (i.e., a set of 5 shootings). The header (i.e., function declaration) of the function play should be as follows: void play();

An example of the output is as follows:

Welcome to Archery Shooting Simulator Round 1: Distance 10: 5 points, you are awesome! Distance 20: 1 points Distance 30: 0 points, what a shame! Distance 40: 3 points Distance 50: 5 points, you are awesome! --------------------- Total Score:14 points Enter 0 to exit, any other value to play again: 1 Round 2: Distance 10: 0 points, what a shame! Distance 20: 3 points Distance 30: 0 points, what a shame! Distance 40: 5 points, you are awesome! Distance 50: 3 points --------------------- Total Score:11 points Enter 0 to exit, any other value to play again: 0

Explanation / Answer

The below is an example of the shooting game program develped in c language:

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<stdlib.h>
#include<time.h>

   boy(int x,int y)
   {

///// x=200,y=100

/*   circle(185,95,7); //eyes
   circle(215,95,7);

   arc(200,100,210,330,20);   //mouth
   line(200,100,200,116); //nose
                   */
   line(x,y+58,x+50,y+58);       //gun
   outtextxy(x+30,y+45,"Gun Point");

   circle(x-15,y-5,7);
   circle(x+15,y-5,7);
   arc(x,y,210,330,20);
   line(x,y,x,y+16);

   setlinestyle(0,10,3);
   circle(x,y,30);
   line(x,y+30,x,y+130);

   line(x,y+60,x+30,y+30);
   line(x,y+60,x-30,y+30);

   line(x,y+130,x-30,y+160);
   line(x,y+130,x+30,y+160);

       //200,100

   rectangle(620,10,630,130);
   rectangle(620,170,630,290);
   rectangle(620,330,630,450);

   rectangle(580,70,590,210);
   rectangle(580,250,590,390);

   outtextxy(530,30,"Target 1");
   outtextxy(500,130,"Target 2");
   outtextxy(530,230,"Target 3");
   outtextxy(500,340,"Target 4");
   outtextxy(530,410,"Target 5");

   }

   boy1(int x,int y)
   {

   circle(x-15,y-5,7);
   circle(x+15,y-5,7);
   arc(x,y,210,330,20);
   line(x,y,x,y+16);

   line(x,y+58,x+50,y+58);       //gun
   outtextxy(x+30,y+45,"Gun Point");

/*   circle(185,95,7); //eyes
   circle(215,95,7);

   arc(200,100,210,330,20);   //mouth
   line(200,100,200,116); //nose */

   circle(x,y,30);
   line(x,y+30,x,y+130);

   line(x,y+60,x+30,y+90);
   line(x,y+60,x-30,y+90);

   line(x,y+130,x-30,y+160);
   line(x,y+130,x+30,y+160);

   rectangle(620,10,630,130);
   rectangle(620,170,630,290);
   rectangle(620,330,630,450);

   rectangle(580,70,590,210);
   rectangle(580,250,590,390);

   outtextxy(530,30,"Target 1");
   outtextxy(500,130,"Target 2");
   outtextxy(530,230,"Target 3");
   outtextxy(500,340,"Target 4");
   outtextxy(530,410,"Target 5");

}

   main()
   {

   int d;
   int a,b;
   char ch;
   clrscr();
   int gdriver=DETECT,gmode;
   initgraph(&gdriver,&gmode," cgi");
   setlinestyle(0,10,3);

   outtextxy(530,30,"Target 1");
   outtextxy(500,130,"Target 2");
   outtextxy(530,230,"Target 3");
   outtextxy(500,340,"Target 4");
   outtextxy(530,410,"Target 5");

   line(200,158,250,158);       //gun

   outtextxy(230,145,"Gun Point");

circle(185,95,7); //eyes

   circle(215,95,7);

   arc(200,100,210,330,20);   //mouth
   line(200,100,200,116); //nose

   circle(200,100,30);
   line(200,130,200,230);

   line(200,160,230,130);
   line(200,160,170,130);

   line(200,230,170,260);
   line(200,230,230,260);

a=200,b=100;

   rectangle(620,10,630,130);
   rectangle(620,170,630,290);
   rectangle(620,330,630,450);

   rectangle(580,70,590,210);
   rectangle(580,250,590,390);

   while(1)
   {
   ch=getch();
   int d=ch;
//   rectangle(620,100,630,200);

   if(d==77)
   {
   cleardevice();
   a=a+20;
   boy1(a,b);

   delay(200);
   cleardevice();

   boy(a,b);
   }

   if(d==75)
   {
   cleardevice();
   a=a-20;
   boy1(a,b);

   delay(200);
   cleardevice();

   boy(a,b);
   }

   if(d==72)
   {
   cleardevice();
   b=b-20;
   boy1(a,b);

   delay(200);
   cleardevice();

   boy(a,b);
   }

   if(d==80)
   {
   cleardevice();
   b=b+20;
   boy1(a,b);

   delay(200);
   cleardevice();

   boy(a,b);
   }

//////////////////////////////////////////////////////////////////
///shooting starts
//////////////////////////////////////////////////////////////////

   if(d==32)
   {

                       //x=200 y=100
       int x=a;
       int y=b;
//       printf("%d %d",x,y);

//////////////////////////////////////////////////////////////////////////

       if((y>-50)&&(y<5))
       {
           for(int i=0;i<=27;i++)
           {
           rectangle(x,y+58,x+22,y+65 );
           x=x+15;
       //   delay(0);
           sound(900);
           boy(a,b);
           nosound();
           }
       cleardevice();
       boy(a,b);
       sound(900);
       delay(200);
       sound(1600);
       delay(200);
       nosound();
       outtextxy(110,400,"Target 1 shooted !!!!!");
//       outtextxy(230,145,"Gun Point");
       boy(a,b);
       }
//////////////////////////////////////////////////////////////////////////
       if((y>5)&&(y<150))
       {
           for(int i=0;i<=24;i++)
           {
           rectangle(x,y+58,x+22,y+65 );
           x=x+15;
       //   delay(10);
           sound(900);
           boy(a,b);
           nosound();
           }
       cleardevice();
       boy(a,b);
       sound(900);
       delay(200);
       sound(1600);
       delay(200);
       nosound();
//       outtextxy(230,145,"Gun Point");
       outtextxy(110,400,"Target 2 shooted !!!!!");

       boy(a,b);
       }
//////////////////////////////////////////////////////////////////////////
       if((y>150)&&(y<190))
       {
           for(int i=0;i<=27;i++)
           {
           rectangle(x,y+58,x+22,y+65 );
           x=x+15;
       //   delay(10);
           sound(900);
           boy(a,b);
           nosound();
           }

       cleardevice();
       boy(a,b);
       sound(900);
       delay(200);
       sound(1600);
       delay(200);
       nosound();
       outtextxy(110,400,"Target 3 shooted !!!!!");
//       outtextxy(230,145,"Gun Point");
       boy(a,b);
       }
/////////////////////////////////////////////////////////////////////////
       if((y>190)&&(y<310))
       {
       for(int i=0;i<=24;i++)
           {
           rectangle(x,y+58,x+22,y+65 );
           x=x+15;
       //   delay(10);
           sound(900);
           boy(a,b);
           nosound();
           }
       cleardevice();
       boy(a,b);
       sound(900);
       delay(200);
       sound(1600);
       delay(200);
       nosound();
       outtextxy(110,150,"Target 4 shooted !!!!!");
   //   outtextxy(230,145,"Gun Point");
       boy(a,b);
       }
//////////////////////////////////////////////////////////////////////////
/
       if((y>310)&&(y<390))
       {
           for(int i=0;i<=27;i++)
           {
           rectangle(x,y+58,x+22,y+65 );
           x=x+15;
       //   delay(10);
           sound(900);
           boy(a,b);
           nosound();
           }
       cleardevice();
       boy(a,b);
       sound(900);
       delay(200);
       sound(1600);
       delay(200);
       nosound();
       outtextxy(110,200,"Target 5 shooted !!!!!");
   //   outtextxy(230,145,"Gun Point");
       boy(a,b);
       }
///////////////////////////////////////////////////

   }

if(d==27)

   break;
   }

   }