Question

In: Computer Science

Write a short text based game using C++ were you can chose the gender of the...

Write a short text based game using C++ were you can chose the gender of the character, than choose between two location, desert or forest. If either location is chosen than you can choose to either stay at your spot or travel to find help. If player chose desert, than choosing either to stay or travel can be led to death by heat exhaustion or saved randomized, or if forest is chosen, than it can be either death of starvation or saved also randomized. Winner lives, loser dies.

Solutions

Expert Solution

I tried to create a game that fulfills all the requirements written above and make the game as much interactive. below is the code of the game. If you have any problem let me know in a comment.

Code:-

//including header files

#include <iostream>

using namespace std;

//Main function

int main()

{

//variable to keep track weather you want to play game again or not

char game='1';

do

{

    //Welcome message

    cout<<"Welcome to Game 'Winner lives Loser dies'\n";

   

    //Select Gender

    string Gender;

    cout<<"Select Gender of Player:- \n1.Male\n2.Female\n";

   

    //loop so that value enterd is valid or not

    while(1)

    {

        cout<<"Enter Gender : ";

        cin>>Gender;

        if(Gender=="1")

        {

            cout<<"Male Gender is selected\n";

            Gender="Male";

            break;

        }

        else if(Gender=="2")

        {

            cout<<"Female Gender is selected\n";

            Gender="Female";

            break;

        }

        else

        {

            cout<<"Invalid Entry! Try again\n";

        }

    }

   

    //location selction

    string location;

    cout<<"\nSelect location where you want to go :- \n1.Desert\n2.Forest\n";

   

    //to check weather value enterd valid or not

    while(1)

    {

        cout<<"Enter location : ";

        cin>>location;

        if(location=="1")

        {

            cout<<"Desert is selected\n";

            location="Desert";

            break;

        }

        else if(location=="2")

        {

            cout<<"Forest is selected\n";

            location="Forest";

            break;

        }

        else

        {

            cout<<"Invalid Entry! Try again\n";

        }

    }

   

   

    //Decision to stay or travel

    string decision;

    cout<<"\nSelect either to stay or travel :- \n1.Stay\n2.Travel\n";

   

    //to check enterd value is valid or not

    while(1)

    {

        cout<<"Enter your decision : ";

        cin>>decision;

        if(decision=="1")

        {

            cout<<"Player selected to stay\n";

            decision="Stay";

            break;

        }

        else if(decision=="2")

        {

            cout<<"Player selected to travel\n";

            decision="Travel";

            break;

        }

        else

        {

            cout<<"Invalid Entry! Try again\n";

        }

    }

   

    //to seed random value with current time

    srand(time(NULL));

    //finding random value o or 1

    int random=rand()%2;

    cout<<"\n";

   

    //showing result according to random value

    if(random==1)

    {

        cout<<Gender<<" Player is dead while "<<decision<<"ing in the "<<location;

        if(location=="Desert")

        {

            cout<<" due to heat exhaustion";

        }

        else

        {

            cout<<" due to starvation";

        }

       

        cout<<"\nSorry! you Lose the game \n";

    }

    else

    {

     cout<<Gender<<" Player is able to survive while "<<decision<<"ing in the "<<location;

     cout<<"\nYou won the game\n";

    }

   

    //asking weather to play again or not

    cout<<"\nWant to play again? \nEnter 1 to play or any key for no\n";

    cout<<"Enter decision : ";

    cin>>game;

    cout<<"\n\n";

}

while(game=='1');

   

    return 0;

}

Output:-

Welcome to Game 'Winner lives Loser dies' Select Gender of Player:- 1.Male 2.Female Enter Gender : 1 Male Gender is selected Select location where you want to go :- 1.Desert 2.Forest Enter location : 1 Desert is selected Select either to stay or travel :- 1.Stay 2. Travel Enter your decision : 1 Player selected to stay Male Player is able to survive while staying in the Desert You won the game Want to play again? Enter 1 to play or any key for no Enter decision : 0

Welcome to Game 'Winner lives Loser dies' Select Gender of Player:- 1.Male 2.Female Enter Gender : 1 Male Gender is selected Select location where you want to go :- 1.Desert 2.Forest Enter location : 1 Desert is selected Select either to stay or travel :- 1.Stay 2. Travel Enter your decision : 1 Player selected to stay Male Player is able to survive while staying in the Desert You won the game Want to play again? Enter 1 to play or any key for no Enter decision : 0


Related Solutions

JAVA 1) You are provided an implementation of a text-based adventure game. Currently the game responds...
JAVA 1) You are provided an implementation of a text-based adventure game. Currently the game responds to directional movements that allow you to move your adventurer around a maze (that is read from a text file). Add the ability to save (and load) the game using object serialization. Write the serialization of the file out to a default filename SavedGame.dat. Make sure that you take care of any exceptions that may occur when reading or writing to a file (for...
Using C++, write a code that this program always stores text file output into a text...
Using C++, write a code that this program always stores text file output into a text file named "clean.txt". -The program should read one character at a time from "someNumbers.txt", and do the following. -If it is a letter, print that letter to the screen, AND also store it in the text file. All letters should be converted to lowercase beforehand. -If it is a number, print that number to screen, but do NOT store it in the text file....
Can you show me a UML example for the game mastermind. Using C++
Can you show me a UML example for the game mastermind. Using C++
You are given a text file containing a short text. Write a program that 1. Reads...
You are given a text file containing a short text. Write a program that 1. Reads a given text file : shortText.txt 2. Display the text as it is 3. Prints the number of lines 4. Prints the occurences of each letter that appears in the text. [uppercase and lowercase letter is treated the same]. 5. Prints the total number of special characters appear in the text. 6. Thedisplayofstep3,4and5aboveshouldbesaveinanoutputfile:occurencesText.txt write it in C++ programing Language
Language: c++ using visual basic Write a program to open a text file that you created,...
Language: c++ using visual basic Write a program to open a text file that you created, read the file into arrays, sort the data by price (low to high), by box number (low to high), search for a price of a specific box number and create a reorder report. The reorder report should alert purchasing to order boxes whose inventory falls below 100. Sort the reorder report from high to low. Inventory data to input. Box number Number boxes in...
Write a code for simple racing game (using dots) on c coding.
Write a code for simple racing game (using dots) on c coding.
Write a code for simple racing game (using dots) on c program.
Write a code for simple racing game (using dots) on c program.
Write a C program that can search for a string within a text file, replace it...
Write a C program that can search for a string within a text file, replace it with another string and put results in a new file.
Question 2 A text-based adventure game has several types of player. The code for the game...
Question 2 A text-based adventure game has several types of player. The code for the game uses the following class, Character to define all the shared elements for different types of player characters (Warrior, Wizard etc). 1. public class Character { 2. private String name; 3. private int life; 4. protected int hitPoints; 5. public Character(String name, int life, int hitPoints) { 6. this.name = name; 7. this.life = life; 8. this.hitPoints = hitPoints; 9. } 10. public void setHitPoints(int...
Can you solve this C program by using Function? Q1. Write a C program to ring...
Can you solve this C program by using Function? Q1. Write a C program to ring the computer bell at any number of times you specify. Use the system clock as a delay, you need to include the time header file.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT