Created
January 10, 2021 19:00
-
-
Save jherr/c10ada5f83c7425022cadd4a4eb58049 to your computer and use it in GitHub Desktop.
CS101 | C++ | Mario game
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Make a simple text game that has: | |
[X] Has a design using a flowchart | |
[X] Uses deeply nested conditionals | |
[X] Handles edge cases | |
[X] Uses variables with a variety of the basic data types (string, bool, int, long, float, double) | |
[X] Uses random | |
[X] Uses a mathematical operator | |
[X] No gotos or globals | |
*/ | |
#include <iostream> | |
#include <string> | |
#include <random> | |
using namespace std; | |
int main () { | |
srand(time(0)); // Initialize the random number generator | |
cout << "What's your name playa? "; | |
string name; | |
cin >> name; | |
if (name == "") { | |
name = "Bob"; | |
cout << endl << "You clearly don't care, so, it's " << name << "." << endl; | |
} | |
cout << "Your name is: " << name << endl; | |
cout << "You see Mario in the courtyard searching for Daisy.\n\n"; | |
cout << "How many gold pieces do you give to Mario? "; | |
int gold = 0; | |
cin >> gold; | |
if (gold > 10) { | |
cout << name << " and Mario journey to Bowser's castle\n"; | |
int rando = rand() % 20; | |
if (rando < gold) { | |
cout << "You win! Game over!\n"; | |
} else { | |
cout << "You lose! Game over!\n"; | |
} | |
} else { | |
cout << "Mario couldn't complete journey. Game over!\n"; | |
} | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Make a simple text game that has: | |
[ ] Has a design using a flowchart | |
[ ] Uses deeply nested conditionals | |
[ ] Handles edge cases | |
[ ] Uses variables with a variety of the basic data types (string, bool, int, long, float, double) | |
[ ] Uses random | |
[ ] Uses a mathematical operator | |
[ ] No gotos or globals | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment