Ich arbeite an einem Projekt für die Schule, das ein Konsolenwürfelspiel ist. Ein Problem, das ich habe, ist, dass, wenn ich versuche, die Würfel zu bekommen, um die Punktezahl variabel zu erhalten, immer auf Null zurückkehrt, anstatt, was es sein sollte. Ich werde vielleicht einfach etwas Einfaches übersehen, da ich neu in C++ bin, aber vielleicht könnt ihr mir helfen.Ich kann nicht herausfinden, warum meine Variable immer wieder auf Null zurückgeht
Hier ist mein Code für die Scoring-Methode:
void FindScoreNumbers()
{
int scoreDie[6];
int score = 0;
bool isScoring = false;
int flushCounter1 = 0;
int flushCounter2 = 0;
int flushCounter3 = 0;
int flushCounter4 = 0;
int flushCounter5 = 0;
int flushCounter6 = 0;
scoreDie[0] = castDie[0];
scoreDie[1] = castDie[1];
scoreDie[2] = castDie[2];
scoreDie[3] = castDie[3];
scoreDie[4] = castDie[4];
scoreDie[5] = castDie[5];
for (unsigned int i = 0; i < 6; ++i)
{
if (scoreDie[i] == 1)
{
score + 100;
flushCounter1++;
isScoring = true;
if (flushCounter1 >= 3)
{
score + 800;
isScoring = true;
}
}
if (scoreDie[i] == 2)
{
flushCounter2++;
if (flushCounter2 >= 3)
{
score + 200;
isScoring = true;
}
}
if (scoreDie[i] == 3)
{
flushCounter3++;
if (flushCounter3 >= 3)
{
score + 300;
isScoring = true;
}
}
if (scoreDie[i] == 4)
{
flushCounter4++;
if (flushCounter4 >= 3)
{
score + 300;
isScoring = true;
}
}
if (scoreDie[i] == 5)
{
score + 50;
flushCounter5++;
isScoring = true;
if (flushCounter5 >= 3)
{
score + 400;
isScoring = true;
}
}
if (scoreDie[i] == 6)
{
flushCounter6++;
if (flushCounter6 >= 3)
{
score + 600;
isScoring = true;
}
}
}
if (isScoring = true)
{
std::cout << score << std::endl;
}
else
{
std::cout << "FARKLE! You didn't roll any scoring die." << std::endl;
}
}
Es tut mir leid, wenn dies nicht richtig formatiert ist das hier meine erste Frage ist. By the way, castDie[6]
ist das Array von gewürfelten Würfel aus einem anderen Bit Code. Ich weiß auch, dass es die Punktzahl
Unrelated, aber Sie können implementieren 'flushCounter #' als Array und nur das erhöhen. Sie können auch eine Partitur auf die gleiche Weise hinzufügen. Ein besseres Design würde Ihre Fehler beheben. – Mikhail