Created
December 2, 2013 01:45
-
-
Save friej715/7743708 to your computer and use it in GitHub Desktop.
My example of an uber-simple RPG-style game for beginner Code Liberation students.
This file contains 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
#include <iostream> | |
#include <string> | |
#include <stdlib.h> | |
using namespace std; | |
int main () | |
{ | |
int playerHealth = 100; | |
int playerStrength = 10; | |
int monsterHealth = 100; | |
while (playerHealth > 0 && monsterHealth > 0) { | |
int monsterStrength = rand() % 15 + 1; | |
string playerChoice; | |
cout << "You have " << playerHealth << " health. The monster has " << monsterHealth << " health." << endl; | |
cout << "Choices:\n1 to Attack\n2 to Defend" << endl; | |
cin >> playerChoice; | |
if (playerChoice == "1") { | |
cout << "You chose to fight!" << endl; | |
monsterHealth-=playerStrength; | |
cout << "You did " << playerStrength << " damage. The monster currently has " << monsterHealth << " health." << endl; | |
} | |
if (playerChoice == "2") { | |
cout << "You chose to defend!" << endl; | |
} | |
if (monsterHealth > 0) { | |
cout << "Now the monster makes his move! He deals " << monsterStrength << " damage!" << endl; | |
// now the monster does his ish | |
// right now, he always attacks | |
if (playerChoice == "1") { | |
playerHealth-=monsterStrength; | |
cout << "You got hit! Your health is currently " << playerHealth << "." << endl; | |
} else if (playerChoice == "2") { | |
cout << "You defended the attack! Your health is currently " << playerHealth << "." << endl; | |
} | |
} | |
cout << "--------------------" << endl; | |
} | |
if (playerHealth <= 0) { | |
// yuo loose!1 | |
cout << "Uh oh, you lost!" << endl; | |
} else if (monsterHealth <= 0) { | |
// yuo win~ | |
cout << "Yeah, you won!" << endl; | |
} else { | |
// a bug happened | |
cout << "This shouldn't happen..." << endl; | |
} | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment