My First Text-Based C++ Game!
My first C++ code! And guess what? I bet you can’t guess this! I didn’t get to finish it! Hahaha.
I do like it though. It’s about a giraffe named Geoffrey and how he’s the meanest, fiercest giraffe that ever lived.
Since I still have a lot to learn about execution in C++ and having spent more time than I should have (as usual) on Scratch, I just have a simple text-based RPG-type game. It has a very narrow story though because the constraints. I also was a little distraught at the fact that I was putting everything inside of Switch statements, so the whole thing became very cluttered very fast, and I resorted (since it still worked) to ask for help with it the next day.
I do like it though! PLAY IT >:O
// Geoffrey the Giraffe’s Magical Adventure
// Kaela Smith
// ITGM315: Intro to C++ Programming : FA12
// Professor Jose Rueda#include <iostream>
#include <string>
#include <vector>using namespace std;
int main()
{
int choiceConflictHyena;
vector<string> inventory;
inventory.push_back(“1. teeth”);
inventory.push_back(“2. clothes hanger”);
inventory.push_back(“3. spit wad”);
inventory.push_back(“4. your uncle Jeff”);cout << “You’re a crazy bloodthirsty girrafe just trying to eat his dinner and live his \nlife! Too bad everyone knows how badass you are and wants to kill you. \nEven when it’s dinner time!”;
cout << “\n\nYou have ” << inventory.size() << ” things around you to defend yourself.\n”;cout << “\nYour items:\n”;
for (unsigned int i = 0; i < inventory.size(); ++i)
{
cout << inventory[i] << endl;
}cout << “\nA wild hyena appears! What do you do?”;
cout << “\n(1) Gallop away \n(2) Gouge his eyes out \n(3) Stand there and eat\n\n”;
cin >> choiceConflictHyena;switch (choiceConflictHyena) //switch means change depending on what you’ve entered; equivalent to a sequence of “ifs”
{
case 1:
cout << “You gallop away and forever live the rest of your life in shame. Your heroic \nbloodthirsty actions quickly fade away and you become known as Sissy Sassafrass. YOU LOSE.\n”;
break;case 2:
cout << “You want to fight! The hyena snarls- it looks like he wants to rip out your \nstill-beating heart and serve it on a platter with some fried Jeff on the side.\n”;cout << “\n\nHe’s ferocious! He’s going to beat your face in! TIME TO ACT AND PUNCH HIM IN \nTHE GUT WITH THAT LONG NECK! What do you use?”;
cout << “\n\nYou currently have:\n”;for (unsigned int i = 0; i < inventory.size(); ++i)
{
cout << inventory[i] << endl;
}int useFightHyena;
cin >> useFightHyena;switch (useFightHyena)
{
case 1:
cout << “\n\nYour teeth are carnivirous vessels of destruction and chaos! Too bad his are \nbetter. He looks at you puzzled, unsure if he just got nipped by you or the wind. \nHe cackles like an asshole, because he’s making fun of you, and walks off. HOW DARE HE! YOU BETTER SHOW HIM WHAT YOU’RE MADE OF AND KICK HIS SPOTTED ASS!!!\n”;
cout << “Oops! Too late. He’s gone. WELL BACK TO EATING LIKE A CHAMPION! You won!”;
break;
case 2:
cout << “\n\nYou have no idea where it came from, but you take the clothes hanger in your \nmouth and start trying to gouge out the hyena’s eyes! But wait! He’s too fast! \nHe dodges!\n”;
cout << “\n\nI would normally put more actions for you, but alas, I do not have time. YOU LOSE.”;
break;
case 3:
cout << “\n\nYou spit in his face! Take that evil foe! The hyena wimpers and tries to compose himself, but instead falls over like the little wuss that he is. Now time to \nindulge yourself in the juicy, artery-covered spoils of victory! YOU WIN!\n”;
break;
case 4:
cout << “\n\nUncle Jeff is a shield! His skinny body makes him not very effective…\n”;
cout << “The hyena pounces and attaches itself to your neck, ripping off the flesh as \nyour screams pierce through the wings in the black covered sky. YOU LOSE.”;
break;
default:
cout << “\n\nYou either mispelled something or you weren’t meant to choose this answer. QUIT IT. YOU LOST.”;
break;
}break;
case 3:
cout << “You just stand there and eat. Are you brave? Or just fucking nuts? Well either \nway, the hyena ‘ain’t standin’ for that shit. HE BITES YOU!\n”;char attack1;
cout << “\n\nOuch! That hurt! Time to beat his brains in!”;
cout << “\nAre you up for the challenge? \n\n(y)YEAH I AM BRING IT ON/ (n) No, I’m a wuss “;
cin >> attack1;if (attack1 == ‘y’)
{
cout << “\n\nHe’s ferocious! He’s going to beat your face in! TIME TO ACT AND PUNCH HIM IN \nTHE GUT WITH THAT LONG NECK! What do you use?”;
cout << “\n\nYou currently have:\n”;for (unsigned int i = 0; i < inventory.size(); ++i)
{
cout << inventory[i] << endl;
}int useFightHyena;
cin >> useFightHyena;switch (useFightHyena)
{
case 1:
cout << “Your teeth are carnivirous vessels of destruction and chaos! Too bad his are \nbetter. He looks at you puzzled, unsure if he just got nipped by you or the wind. \nHe cackles like an asshole, because he’s making fun of you, and walks off. HOW DARE HE! YOU BETTER SHOW HIM WHAT YOU’RE MADE OF AND KICK HIS SPOTTED ASS!!!\n”;
cout << “Oops! Too late. He’s gone. WELL BACK TO EATING LIKE A CHAMPION! You won!”;
break;
case 2:
cout << “You have no idea where it came from, but you take the clothes hanger in your mouth and start trying to gouge out the hyena’s eyes! But wait! He’s too fast! He dodges!\n”;
cout << “I would normally put more actions for you, but alas, I do not have time. YOU LOSE.”;
break;
case 3:
cout << “You spit in his face! Take that evil foe! The hyena wimpers and tries to compose himself, but instead falls over like the little wuss that he is. Now time to \nindulge yourself in the juicy, artery-covered spoils of victory! YOU WIN!\n”;
break;
case 4:
cout << “Uncle Jeff is a shield! His skinny body makes him not very effective…\n”;
cout << “The hyena pounces and attaches itself to your neck, ripping off the flesh as \nyour screams pierce through the air in the black covered sky. YOU LOSE.”;
break;
default:
cout << “You either mispelled something or you weren’t meant to choose this answer. QUIT IT. YOU LOST.”;
break;
}
}if (attack1 == ‘n’)
{
cout << “\nDeath has come on swift wings. Or claws. Actually yeah I think it was claws. \nYour death is so insignificant, even the narrator can’t remember how you died! \nThat is definitely saying something.”;
break;
}break;
default:
cout << “Don’t even try it bro. Giraffes don’t know \nwhat to do without specific instructions, silly billy. Try again.\n”;
cin >> choiceConflictHyena;
break;
}return 0;
}

