Code: Select all
class Room {
Room* exits[NUM_EXITS];
};
Moderator: Coders of Rage
Code: Select all
class Room {
Room* exits[NUM_EXITS];
};
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
No.Terranova3y2 wrote:I had a look at some material for classes and I wonder if it would be overcomplicated for a text game like this?
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
I myself have been giving sideways glances at java, I might check out said book...Martyj wrote:I went the college route and learned java first. I'll be doing c++ this summer. Tbh learning java has helped me with more than just understanding java. I can read some c++ (can't write it though) can do php. Also it helps you understand the computer more. I'd recommend starting on java because it's a good language. It's not platform dependent, if you program on a mac you can use a java program on windows. I would not recommend using tutorials that just go through the language by showing you programs. Id recommend a book that goes over all of java.
What's nice about java is you get an api to use. The sun corp provides you with everything you would ever need and more.
Another thing that helps is a good IDE.
Here is the book I used for java
http://www.amazon.com/Building-Java-Pro ... 565&sr=8-1
That's my suggestion though, start with java.
Code: Select all
int playerHP = 5; // Declares starting health
Code: Select all
int checkHP()
{
if (playerHP <= 0)
{
cout << "After taking too big a beating,\n";
cout << "you drop dead on the floor...\n";
cout << "GAME OVER!";
cin.ignore();
cin.get();
exit(0);
}
Code: Select all
SecondScreen()
{
...
if (playerInput == menuArray[1])
{
--playerHP;
cout << "\nAfter searching for hours you find nothing.\n";
cout << "During the search you fell on your face and\n";
cout << "lose 1 point of health.\n";
cout << "\nPress any key to continue.\n";
cin.ignore();
cin.get();
checkHP();
SecondScreen();
}
Code: Select all
SecondScreen() {
while (playerInput == menuArray[1])
{
--playerHP;
cout << "\nAfter searching for hours you find nothing.\n";
cout << "During the search you fell on your face and\n";
cout << "lose 1 point of health.\n";
cout << "\nPress any key to continue.\n";
cin.ignore();
cin.get();
checkHP();
}
}
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
Code: Select all
int SecondScreen()
{
cout << "##########################################\n";
cout << "# #\n";
cout << "# You open your eyes, very groggy #\n";
cout << "# and you have no idea where you are. #\n";
cout << "# It is very dark, the only light source #\n";
cout << "# is coming from a window. #\n";
cout << "# #\n";
cout << "##########################################\n";
cout << "# #\n";
cout << "# Your HP: " << playerHP << " #\n";
cout << "# #\n";
cout << "##########################################\n";
cout << "\n";
cout << "1.) Look out the window?\n";
cout << "2.) Look around some more?\n\n";
cin >> playerInput;
if (playerInput == menuArray[0]) // Tests for players input
{
ThirdScreen();
}
else
if (playerInput == menuArray[1])
{
--playerHP;
cout << "\nAfter searching for hours you find nothing.\n";
cout << "During the search you fell on your face and\n";
cout << "lose 1 point of health.\n";
cin.ignore();
cin.get();
checkHP();
SecondScreen();
}
Code: Select all
void SecondScreen()
{
do { //while playerInput == menuArray[1]
cout << "##########################################\n";
cout << "# #\n";
cout << "# You open your eyes, very groggy #\n";
cout << "# and you have no idea where you are. #\n";
cout << "# It is very dark, the only light source #\n";
cout << "# is coming from a window. #\n";
cout << "# #\n";
cout << "##########################################\n";
cout << "# #\n";
cout << "# Your HP: " << playerHP << " #\n";
cout << "# #\n";
cout << "##########################################\n";
cout << "\n";
cout << "1.) Look out the window?\n";
cout << "2.) Look around some more?\n\n";
cin >> playerInput;
if (playerInput == menuArray[0]) // Tests for players input
{
ThirdScreen();
}
else if (playerInput == menuArray[1])
{
--playerHP;
cout << "\nAfter searching for hours you find nothing.\n";
cout << "During the search you fell on your face and\n";
cout << "lose 1 point of health.\n";
cin.ignore();
cin.get();
checkHP();
}
} while (playerInput == menuArray[1]); //end do-while loop.
}
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
Code: Select all
void SecondScreen()
{
do { //while playerInput == menuArray[1]
Screen2text();
if (playerInput == menuArray[0]) // Tests for players input
{
ThirdScreen();
}
else if (playerInput == menuArray[1])
{
--playerHP;
lossHP();
checkHP();
}
} while (playerInput == menuArray[1]); //end do-while loop.
}
Code: Select all
Screen2text();
while (playerInput == menuArray[0]) {
--playerHP;
lossHP();
checkHP();
Screen2text();
}
ThirdScreen();
}
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
ah crapMarauderIIC wrote:No easy way to clear the screen in C++ as far as I'm aware.
Yeah that works great too. I can't say that I really understand all of it though. I get that its looping while the condition is true but isn't it the same thing I was doing with if statement by calling the function inside itself?MarauderIIC wrote: What I don't like about our structure there is the if that matches the while condition.Does that still do the right stuff? It assumes there are only the two options in menuArray. If that's not true, add a "if (playerInput == menuArray[1])" above ThirdScreen().Code: Select all
Screen2text(); while (playerInput == menuArray[0]) { --playerHP; lossHP(); checkHP(); Screen2text(); } ThirdScreen(); }
Code: Select all
#include <iostream>
using namespace std;
void recurse() {
recurse();
cout << "pants" << endl;
recurse();
}
int main() {
recurse();
return 0;
}
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
Code: Select all
void AboutText()
{
cout << "I created this game to learn C++\n";
cout << "It is very simple and uses basic \n";
cout << "if statements and functions\n";
cout << endl;
cout << "Thanks to the Elysian Shadows\n";
cout << "forum members for all their help\n";
cout << "and motivation.\n";
cout << endl;
cout << "Press any key to return to the Main Menu";
cin.sync();
cin.get();
}
Code: Select all
void SecondScreen()
{
Screen2text();
while (playerInput == menuArray[1])
{
--playerHP;
lossHP();
checkHP();
Screen2text();
}
if (playerInput == menuArray[0])
{
ThirdScreen();
}
else
{
cout << "Invalid Selection\n";
Screen2text();
}
}
Code: Select all
while (!cin) {
cout << "Bad selection!" << endl;
cin.clear(); //unset the "bad" flag
cin.sync(); //eat all unread characters. this is a no-op if the bad bit is set, so you must .clear first
cin >> input;
}
Code: Select all
char /* or whatever */ input;
input = getUserInput();
char /* or whatever */ getUserInput() {
char /* or whatever */ retval;
cin >> retval;
while (!cin) {
/* all that stuff up there... */
}
return retval;
}
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.