In: Computer Science
Create a program that will take the user through an attempted dungeon escape.
The user will represent a player and the player will have a variable to represent the HP (Hit Points) which will default to 50.
Menu
The program will start with the following menu:
Welcome to dungeon escape.
1) Play the game
2) Exit the game
If option 1 is chosen, the game is played, if not the program will end.
First Set of Doors
If option 1 is chosen, the following message will display
Welcome player. You wake up in a dark hallway, and three doors appear to be your way out
. Which door will you choose? 1, 2, or 3.
prompt> You will choose one door to be a trap door. Create a constant variable to hold the value of the door that will be the trap door.
Hint
const int TRAPDOOR = 3;
If the player chooses the trap door, you will display a game over message and exit the program
Example message:
You open the door and are instantly thrown into an abyss. Better luck next time. GAME OVER.
If the player chooses the other 2 doors, the player will have their HP increased by 50 and move on to the next set of doors are displaying the following message
You pass through the door and sense of strength come over you. Your new HP is [HP value]
Second Set of Doors
You will give the player the following prompt:
You see another set of three doors.
Which door will you choose? 1, 2, or 3.
Prompt>
This time two doors will be trap doors. Create two constants to hold the value of the doors that will be trap doors
. If the player chooses the either trap door constant you will display a distinct message for each trap door and decrease the HP by 50.
Example message for Trap 1:
You open the door and are attacked by an Ogre. You escape but your HP is now [HP value].
Example message for Trap 2:
You open the door and are attached by a banshee. Your escape but your HP is now [HP value]. If the player chooses the last door, display the following message: You open the door and…. nothing happens. Lucky you!
Boss Fight
If a player makes it this far, Display the message:
You see no obstacles and your HP is now [HP value]. Press any non-space key when ready
Hint: You can use cin to read a character here. When the user presses any key, you will have to compare the user’s HP. If the user’s HP is greater than 50 display the following message: You see a dragon appear before you. It breathes fire upon you but you managed to escape with small wounds. Congratulations, you’ve escaped the dungeon! If the user’s HP is equal or less than 50 display the following message: You see a dragon appear before you. It breathes fire upon you and your weak body is engulfed immediately. Game over!
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,HP=0;
cout<<"Welcome to dungeon escape.\n1) Play the
game\n2) Exit the game"<<endl;
cin>>n;
if(n!=1)//if user want to exit
{
return 0;
}
//first set of doors
const int TRAPDOOR=3;
int door1;
cout<<"Welcome player.\nYou wake up in a dark
hallway, and three doors appear to be your way out.\nWhich door
will you choose? 1, 2, or 3."<<endl;
cin>>door1;
if(door1==TRAPDOOR)//failed at first door
{
cout<<"You open the door and
are instantly thrown into an abyss. Better luck next time. \nGAME
OVER."<<endl;
return 0;
}
//Passed first door and entered second door
HP+=50;
int door2;
const int TRAPDOOR1=2,TRAPDOOR2=1;
cout<<"You pass through the door and sense of
strength come over you. Your new HP is
"<<HP<<endl;
cout<<"You see another set of three
doors.\nWhich door will you choose? 1, 2, or 3."<<endl;
cin>>door2;
if(door2==TRAPDOOR1)
{
HP-=50;
cout<<"You open the door and
are attacked by an Ogre. You escape but your HP is now
0."<<endl;
}
else if(door2==TRAPDOOR2)
{
HP-=50;
cout<<"You open the door and
are attached by a banshee. Your escape but your HP is now
0."<<endl;
}
else //In my opinion is this part HP should increase
but its not mentioned
{
//HP+=50;
cout<<"You open the door
and…. nothing happens. Lucky you!"<<endl;
}
cout<<"\nBOSS FIGHT"<<endl;
char c;
cout<<"You see no obstacles and your HP is
now"<<HP<<".Press any non-space key when
ready"<<endl;
cin>>c;
if(HP>50)
{
cout<<"You see a dragon
appear before you. It breathes fire upon you but you managed to
escape with small wounds. \nCongratulations, you’ve escaped the
dungeon!"<<endl;
}
else
{
cout<<"You see a dragon
appear before you. It breathes fire upon you and your weak body is
engulfed immediately. \nGame over!"<<endl;
}
}
It's working fine