Also im Grunde, wenn ich kompiliere und laufe, wird es den ganzen Weg arbeiten, bis ich "Kampf beginnen !!" aber ich verstehe nicht, was mit meiner Schleife falsch ist. Dieser Code sollte für meine Augen perfekt funktionieren, aber ich brauche Hilfe, um herauszufinden, warum ich schlechte Sicht habe.Mein einfaches C++ Textspiel funktioniert nicht. Ich benutze Zufallszahlen generiert und ich bin verwirrt
#include <iostream>
#include <ctime>
#include <random>
using namespace std;
int main() {
mt19937 randGen(time(NULL));
uniform_int_distribution<int> humanatt(4, 8);
uniform_int_distribution<int> humanhp(50, 100);
uniform_int_distribution<int> skelatt(12, 17);
uniform_int_distribution<int> skelhp(70, 85);
int hAtt, hHp, sAtt, sHp;
unsigned long humans, skeletons, deadHumans = 0, deadSkeletons = 0;
cout << "*** Skeletons vs Humans ***" << endl;
cout << "Input the number of humans: ";
cin >> humans;
cout << "Input the number of skeletons: ";
cin >> skeletons;
cout << "Beginning combat!!" << endl << endl << "(combat noises)" << endl;
while ((humans > 0) && (skeletons > 0)) {
hAtt = humanatt(randGen);
hHp = humanhp(randGen);
sAtt = skelatt(randGen);
sHp = skelhp(randGen);
while ((hHp > 0) && (sHp > 0)) {
if (hAtt >= sHp) {
skeletons--;
deadHumans++;
}
if (sAtt >= hHp) {
humans--;
deadHumans++;
}
}
}
cout << endl << "Combat has ended!" << endl << endl;
if ((humans == 0) && (skeletons == 0)) {
cout << "They all died!" << endl;
cout << "This was a battle with no winner" << endl;
cout << deadHumans + deadSkeletons << " men and bone-men, gave gave there lives this day";
}
else {
if (humans == 0) {
cout << "The Skeletons Win!" << endl;
cout << "They killed all " << deadHumans << " of the humans" << endl;
cout << "However, at the cost of " << deadSkeletons << " of they're own" << endl;
cout << "Only " << skeletons << " remain";
}
else {
cout << "The Humans Win!" << endl;
cout << "They killed all " << deadSkeletons << " of the humans" << endl;
cout << "However, at the cost of " << deadHumans << " of they're own" << endl;
cout << "Only " << humans << " remain";
}
}
system("PAUSE");
return 0;
}
oh, und es tut mir leid wegen des unordentlichen Codes.
Ich denke, Sie sollten lernen, wie man einen Debugger verwendet. Dies wäre weitaus effektiver und genauer, als wenn die Community rät, wo der Code kaputt ist. –