Immer wenn ich versuche, dieses Spiel zu starten, wird automatisch 0 zurückgegeben. Das Spiel ist ein textbasiertes Überlebensspiel, das ich auf Code :: Blocks programmiert habe. Der Compiler ist MinGW. Ich bin ein halbkundiger Programmierer. Es gibt keinen Fehler beim Kompilieren.C++ Spiel gibt automatisch 0 zurück
// This game automatically returns 0 and ends for some reason...
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;
int hunger;
int warmth;
int thirst;
int choice;
// Declares variables for hunger, warmth, thirst, and the users choice
int start()
{
cout<< "You are stuck in a forest, all alone"<< endl;
cout<< "You must maintain your hunger, thirst, and warmth." << endl;
int mainPage();
}
int hunt()
{
srand(time(0));
cout<< "You have chosen hunt!"<< endl;
if ((rand() % 2) == 2){
cout<< "You caught a deer!"<< endl;
hunger = hunger + 1;
}
else{
cout<< "You could not find anything..."<< endl;
}
int mainPage();
}
// The previous function is used for the hunting choice
int wood()
{
cout<< "You have chosen find firewood!"<< endl;
if ((rand() % 2) == 2){
cout<< "You found firewood!"<<endl;
warmth = warmth + 1;
}
else{
cout<< "You could not find any firewood"<< endl;
}
int mainPage();
}
// Wood choice
int water()
{
cout<< "You have chosen find water!"<< endl;
if ((rand() % 2) == 2){
cout<< "You have found a river!"<< endl;
thirst = thirst + 1;
}
else{
cout<< "You could not find anything..."<< endl;
}
int mainPage();
}
// Water choice
int mainPage()
{
warmth = warmth - 1;
hunger = hunger - 1;
thirst = thirst - 1;
// Subtracts one from each variable per turn
if (hunger == 0){
cout<< "You starved!"<< endl;
cout<< "Game over!"<< endl;
return 0;
}
if (thirst == 0){
cout<< "You became dehydrated!"<< endl;
cout<< "Game over!"<< endl;
return 0;
}
if (warmth == 0){
cout<< "You froze!"<< endl;
cout<< "Game over!"<< endl;
return 0;
}
// You die if any of the variables reach zero
cout<< "Your hunger is"<< hunger<< endl;
cout<< "Your warmth is"<< warmth<< endl;
cout<< "Your thirst is"<< thirst<< endl;
cout<< "What would you like to do?"<< endl;
cout<< "1 = hunt, 2 = find firewood, 3 = find water"<< endl;
cin>> choice;
if (choice = 1){
int hunt();
}
if (choice = 2){
int wood();
}
if (choice = 3){
int water();
}
// The main page that takes the users choice as input and also tells you the amount of each variable
}
int main()
{
hunger = 5;
thirst = 5;
warmth = 5;
int start();
}
// the main function
_ "Diese Website sagte, dass meine Frage hauptsächlich Code ist, also werde ich kopieren und einfügen" _ Betrachten Sie, es gab einen Grund, dass Sie diese Nachricht erhalten haben. Es mit unsinnigen Fülltext zu füllen, ist nicht angebracht! –
Ich habe meine Stimme abgegeben. Bitte lesen Sie [Wie Sie fragen] (http://stackoverflow.com/help/asking) das nächste Mal, bevor Sie eine Frage stellen. –
Ich entschuldige mich, ich hätte das nicht tun sollen. –