Originally posted by abrege
Thats pretty neat. Suggestions:
1. Create error-checking for user input so that entering a non-integer will not crash the program.
2. When the character dies, the user should be informed.
3. "Enter the value 69 to exit the program"?! How about using system("pause"), getch(), or cin.get() to pause the program until the user hits a key?
4. A background story would be nice
Other than that, the game is pretty well done for 3 weeks of learning. I want to see more newbies create "problem solving" games like these Can we see the source code?
I haven't learned about getch(), cin.get(), or anything like that yet. And I wasn't too worried about a good storyline. But thanks, I'm kinda proud of it. Here's my source code. There are no comments:
Code:
#include <iostream.h>
class Mosadna
{
int HP;
public:
Mosadna();
~Mosadna();
int GetHP() const;
void SetHP(int x);
};
Mosadna::Mosadna()
{
HP = 200;
}
Mosadna::~Mosadna()
{
}
int Mosadna::GetHP() const
{
return HP;
}
void Mosadna::SetHP(int x)
{
HP -= x;
}
Mosadna Sebba;
int damage = Sebba.GetHP();
bool knife = false;
bool ending = false;
bool knifex()
{
knife = true;
return knife;
}
void Ending()
{
cout << "\n\nYou survived the horrible fields of Lawnmower Land, found the magical knife, and cracked the password to escape this horrible place. Congratulations!\n\nTHE END";
ending = true;
for ( ;; )
{
int end;
cout << "\nEnter the value 69 to exit the program: ";
cin >> end;
{
if (end == 69)
break;
else
continue;
}
}
}
void MenuZ()
{
cout << "\nYou see a tree. Engraved in it are the words 'Passoword'. Carve in the password with your knife, or enter the number '5' to exit: ";
for( ;; )
{
bool exit4 = false;
int password;
cin >> password;
switch (password)
{
case 5: exit4 = true;
break;
case 52: cout << "\nWhoa, you're close!";
break;
case 53: cout << "\nOh, you almost have it!!!";
break;
case 54: cout << "\nPerfect!";
Ending();
break;
case 55: cout << "\nOh, you almost have it!!!";
break;
case 56: cout << "\nWhoa, you're close!";
break;
default: cout << "\nThat wont work, try something else: ";
break;
}
if (damage < 1 || exit4 || ending)
break;
else
continue;
}
}
void MenuY()
{
cout << "\nWow, what a beautiful place! ";
for ( ;; )
{
cout << "\n";
cout << "\n1 - Go North\n2 - East\n3 - West\n4 - Go back\nCommand: ";
bool exit3 = false;
int input2;
cin >> input2;
switch (input2)
{
case 1: cout << "\nThere's nothing here at all, except a piece of paper that says '54' on it.\nYou're going to have to go back.\n";
break;
case 2: cout << "\nOn, no! You were attacked by evil goblins!\n";
damage -= 80;
{
if (damage > 1)
cout << "\nRemaining HP: " << damage;
else
break;
}
break;
case 3: cout << "\nYou're in a forest clearing.\n";
{
if (knife)
MenuZ();
else
continue;
}
break;
case 4: exit3 = true;
break;
default: cout << "\nThat wont work, try something else: ";
}
{
if (exit3 || damage < 1 || ending)
break;
else
continue;
}
}
}
void MenuX()
{
cout << "\nWhere do you want to go?";
for ( ;; )
{
cout << "\n1 - Woods\n2 - Swamp\n3 - Hut\n4 - Exit\nCommand: ";
bool exit2 = false;
int input2;
cin >> input2;
switch (input2)
{
{
case 1: MenuY();
break;
}
{
case 2: cout << "\nThe poison from the swamp's atmoshpere has hurt you!";
damage -= 75;
{
if (damage > 1)
cout << "\nRemaining HP: " << damage;
else
break;
}
break;
}
case 3:
{
if (knife)
cout << "\nThere's nothing here. You have to go back.";
else
cout << "\nThe door to the hut is locked, but there's a knife in front of the door. You\ntake the knife\n";
knifex();
}
break;
{
case 4: exit2 = true;
break;
}
default: cout << "\nThat wont work, try something else:\n ";
}
{
if ( exit2 || damage < 1 || ending)
break;
else
continue;
}
{
if (exit2)
break;
else
continue;
}
}
}
void RunStats()
{
cout << "\nYour remaining HP: " << damage;
}
void RunExploration()
{
MenuX();
}
main()
{
bool exit = false;
int hurt = damage;
cout << "Warning: Any non-intenger input values will result in a program crash\n";
cout << "You're toal HP: " << damage << "\n\n";
for ( ;; )
{
cout << "\n\n1 - Check Stats\n2 - Go Exploring\n3 - Exit\nCommand: ";
int input;
cin >> input;
switch (input)
{
case 1: RunStats();
break;
case 2: RunExploration();
break;
case 3: exit = true;
break;
default: cout << "\nThat wont work, try something else: ";
break;
}
{
if (exit || damage < 1 || ending)
break;
else
continue;
}
}
cout << "\n\n\n\nGAME OVER ";
return 0;
}