Hi there! I posted about this project a few weeks ago and solved that round of problems, so thank you all for help with that! After tinkering and adding a few more segments to the game project I'm working on, I've run into a problem with a while statement towards the end of my code, listed here:
int done = 1;
while (done > 0){
okToPrint == true;
while (okToPrint == true) {
Serial.println(F("Roll the dice by typing 'y'!"));
okToPrint = false;
}
while(Serial.available()){
Serial.read();
}
while (Serial.available() == 0) {}
char begg = Serial.read();
if(begg == 'y'){
yourRoll = random(1,7);
if(yourRoll >= diceVal) {
Serial.print(F("You rolled a "));
Serial.print(yourRoll);
Serial.print(F(". You did "));
Serial.print(atP);
Serial.println(F(" damage to the illness!"));
Serial.print(F("It has "));
Serial.print(defenseVal - atP);
Serial.println(F(" health left"));
if ((defenseVal - atP) <= 0) {
Serial.print(F("Good Job! You've defeated "));
Serial.print(monster);
Serial.println(F("! That's the end of this fighting round!"));
Serial.println("");
done = 0;
}
else if ((defenseVal - atP) != 0){
Serial.println(F("You did not kill the illness yet."));
if ((defP - attackVal) <= 0){
Serial.println(F("I'm sorry. You were defeated. You may try again next turn, but for now, your turn is over. Good try."));
Serial.println("");
done = 0;
}
else if ((defP - attackVal) > 0){
Serial.println(F("You didn't defeat it yet, but you still have a chance! Keep going! Remember your health and the illness's health!"));
Serial.println("");
done = 1;
}
}
}
else if(yourRoll < diceVal) {
Serial.println("");
Serial.print(F("You rolled a "));
Serial.print(yourRoll);
Serial.print(F(". You did not do any damage! You have "));
Serial.print(defP - attackVal);
Serial.println(F(" health left!"));
if ((defenseVal - atP) <= 0) {
Serial.print(F("Good Job! You've defeated "));
Serial.print(monster);
Serial.println(F("! That's the end of this fighting round!"));
Serial.println("");
done = 0;
}
else if ((defenseVal - atP) != 0){
Serial.println(F("You did not kill the illness yet."));
if ((defP - attackVal) <= 0){
Serial.println(F("I'm sorry. You were defeated. You may try again next turn, but for now, your turn is over. Good try."));
Serial.println("");
done = 0;
}
else if ((defP - attackVal) > 0){
Serial.println(F("You didn't defeat it yet, but you still have a chance! Keep going! Remember your health and the illness's health!"));
Serial.println("");
done = 1;
}
}
}
}
}
I'm unsure if the rest of my code is necessary for any aid, but upon request I can definitely post it. (It's a little long, though, so I figured I'd just post this part for now and see.) I've been stumped on this loop, which is supposed to loop the attack of a monster until the monster is dead (it has no more defense points). I'm sure I'm making a stupid mistake somewhere, but I'm pretty new to all this.
Any help at all is appreciated!
*Edit, to clarify, it does go through the process once, but upon the need to loop if neither the user nor the monster are dead, it just stops the code, or gets stuck somewhere
test2.ino (23.5 KB)