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

Can you write a program for the card game WAR using linked lists in c++!
Can you write a program for the card game WAR using linked lists in c++!
Can you write a program for snakes and ladder board game using linked lists in c++
Can you write a program for snakes and ladder board game using linked lists in c++
C++ Code You will write a program to process the lines in a text file using...
C++ Code You will write a program to process the lines in a text file using a linked list and shared pointers. You will create a class “Node” with the following private data attributes: • Line – line from a file (string) • Next (shared pointer to a Node) Put your class definition in a header file and the implementation of the methods in a .cpp file. The header file will be included in your project. If you follow the...
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...
Can you program Exploding kittens card game in c++ using linked lists and classes! The game...
Can you program Exploding kittens card game in c++ using linked lists and classes! The game is played with between 2 and 4 players. You'll have a deck of cards containing some Exploding Kittens. You play the game by putting the deck face down and taking turns drawing cards until someone draws an Exploding Kitten. When that happens, that person explodes. They are now dead and out of the game. This process continues until there's only one player left, who...
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++
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....
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...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT