Bu slot makinesini programlama sınıfım için yapıyorum, ancak programın tekrar oynamak isteyip istemediklerini sormasını ve böylece sonsuz bir döngüye neden olmadan tekrar çalışmasını nasıl bilmiyorum. Herhangi bir yardım takdir edilecektir.Slot Makine kullanılarak
public static void main(String[] args)
{
boolean playAgain = true;
Scanner input = new Scanner(System.in);
System.out.println("Welcome, you have 10 credits! Play (Y/N)");
String choice;
choice = input.nextLine();
int credits = 10;
if ("y".equals(choice))
{
playAgain = true;
} else {
playAgain = false;
}
while (playAgain = true)
{
int sp0 = spin();
int sp1 = spin();
int sp2 = spin();
System.out.println(sp0 +"\t"+ sp1 +"\t"+ sp2);
int answer = evaluate(sp0,sp1,sp2);
int newCred = answer + credits - 1;
System.out.println("Your now have "+ newCred + " credits");
System.out.println("Press y to play again");
String newC = input.nextLine();
}
// TODO code application logic here
}
public static int spin()
{
int num1;
Random rand = new Random();
num1 = rand.nextInt(8);
return num1;
}
public static int evaluate(int e1, int e2, int e3)
{
int num;
if(e1==0 && e2==0 && e3==0)
{
num= 7;
System.out.println("You Win");
}else if (e1==e2 && e2 == e3){
num = 5;
System.out.println("You Win");
}else if (e1== 0 && e2==0 && e3 != 0){
num= 3;
System.out.println("You win");
} else if (e1==e2 && e2==e1 && e3 != e1){
num= 2;
System.out.println("You win");
} else if (e1==0 && e2 !=0 && e3 != 0){
num= 1;
System.out.println("You win");
} else {
num =0;
System.out.println("You Lose");
}
return num;
}
değişken 'playAgain' _inside_ değiştirir emin olmak gerek olabilir döngü de mi? – mustaccio