In this project you will implement a very simple TTY game. In this game, the use
ID: 3757267 • Letter: I
Question
In this project you will implement a very simple TTY game. In this game, the user has a catapult that can launch projectiles. In each round of the game, the computer places a wall in front of the user. The user aims their catapult by setting the launch angle and speed. The computer then computes whether the projectile makes it over the wall and informs the user. The user gets points for clearing the wall and loses points for hitting the wall. The game continues through successive rounds until the user quits. The following graphic illustrates the game. Note however that youtwill not be implementing any graphics in this project. This is a TTY game. speed height' angle distanceExplanation / Answer
Here's the code for game in C++ :
#include <bits/stdc++.h>
using namespace std;
int main()
{
int choice,plus_points=5,minus_points=2,total_points=0;
do{
double d,h,v,theta,t,g=9.81,d1,h1,t1;
cout<<" Enter distance (in meters) from the wall: ";
cin>>d;
cout<<" Enter height (in meters) of the wall: ";
cin>>h;
cout<<" Enter speed (in meters per second) of the projectile: ";
cin>>v;
cout<<" Enter angle (in radians) of the projectile: ";
cin>>theta;
t=2*v*sin(theta)/g;
d1=v*cos(theta)*t;
t1=d/(v*cos(theta));
h1=v*sin(theta)*t1-g*t1*t1/2;
if(d>=d1&&h>=h1){
total_points+=plus_points;
cout<<" Yayy! Successfully crossed the wall!";
}
else{
total_points-=minus_points;
cout<<" Sorry! Failed to cross the wall!";
}
cout<<" Total Score is: "<<total_points<<endl;
cout<<" Press 1 to play more...Press 0 to exit...";
cin>>choice;
}while(choice);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.