Reputation: 15
I'm writing a card game and I have a specific boolean which i have set to false, citizenLimiter. I want to set this boolean to true when the citizen card within my game is played a total of 4 times. This should allow it to stop you from playing the card and play a different card instead. My issue is that cardLimiter, the variable I am using to count the number of times the game is won, automatically sets citizenLimiter to true after the first use of the card. What do I need to do to fix this issue?
I've tried using a nested loop and have also tried setting the variable needed to change the value of the boolean to a different number.
public static void emperorsTurn() {
if (cardLimiter <= 4){
citizenLimiter = true;
}
Random cards = new Random();
int computerinput = 0;
int numberx = 5;
for (int counter = 1; counter <= 3; counter++) {
computerinput = 1 + cards.nextInt(2);
}
Scanner sc = new Scanner(System.in);
System.out.println("Please pick the card you are playing. \n if you are playing the Emperor press 1, if you are playing the citizen press 2 ");
int userinput = sc.nextInt();
if (userinput == 1 && computerinput == 1 && emperorLimiter == false) {
System.out.println("you have played the emperor! \n the emperor is defeated by the slave");
emperorLimiter =true;
System.out.println("you can no longer use the emperor");
} else if ((userinput == 1 && computerinput == 1 && emperorLimiter == true)) {
System.out.println("you cannot play the emperor this turn \n you have played the citizen instead. The citizen is defeated by the slave");
//make it so that the win/ lose is shown here
} else if (userinput == 1 && computerinput == 2 && emperorLimiter == false) {
System.out.println("you have played the emperor the emperor defeats the citizen");
winOrLose();
numberx--;
} else if (userinput == 2 ) { //when the user input is 2
if (computerinput == 1 && citizenLimiter == false) {
System.out.println("you have played the citizen, this defeats the slave");
cardLimiter++;
} else if (computerinput == 2 && citizenLimiter == false) {
System.out.println("you have played the citizen, this ties with the citizen");
cardLimiter++;
}
if (computerinput==1 && citizenLimiter == true) {
System.out.println("you are out of citizen cards, you play the emperor instead, this is defeated by the slave");
//i need to make it so that once you are out of a certain type of card it plays the emperor instead
}
else if (computerinput == 2 && citizenLimiter == true ){
System.out.println("you are out of citizen cards, you play the emperor instead, this defeats the citizen");
}
}
}
Upvotes: 1
Views: 50
Reputation: 2981
Shouldn't it just be the other way?
if (cardLimiter > 4){
citizenLimiter = true;
}
Upvotes: 1