已经试了无数遍,这个就是加不起来
声明:本人中文退化。package Assignments;
public class RockPaperScissorator {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Welcome! Let’s Play Rock-Paper-Scissors!'");
System.out.println("Remember:");
System.out.println("Rock breaks Scissors, Paper covers Rock and Scissors cut Paper");
System.out.println("");System.out.println("");System.out.println("");
int p;
do{
int a,c,b;
a=0;
b=0;
c=(int) (Math.random()*2+1);
System.out.println("Ready?!");
System.out.println("1. Rock");
System.out.println("2. Paper");
System.out.println("3. Scissors");
System.out.println("Please choose your action: ");
p=TextIO.getlnInt();
do{
if(p==1){
if(c==1){System.out.println("Computer chose Rock!"); System.out.println("It’s a tie!"); a+=0;}
if(c==2){System.out.println("Computer chose Scissors!");System.out.println("You win!");a+=1;}
if(c==3){System.out.println("Computer chose Paper!");System.out.println("You lose!");a-=1;}
}
if(p==2){
if(c==1){System.out.println("Computer chose Paper!'");System.out.println("It’s a tie!");a+=0;}
if(c==2){System.out.println("Computer chose Rock!");System.out.println("You win!");a+=1;}
if(c==3){System.out.println("Computer chose Scissors!");System.out.println("You lose!");a-=1;}
}
if(p==3){
if(c==1){System.out.println("Computer chose Scissors!");System.out.println("It’s a tie!");a+=0;}
if(c==2){System.out.println("Computer chose Paper!");System.out.println("You win!");a+=1;}
if(c==3){System.out.println("Computer chose Rock!");System.out.println("You lose!");a-=1;}
}}while(p<0);
b+=1;
System.out.println("You have won "+a+" of "+b+" games.");
}while(p%1==0||p>0);
}
}
他最后呢应该是这个样子的:
Welcome! Let’s Play Rock-Paper-Scissors!
Remember:
Rock breaks Scissors, Paper covers Rock and Scissors cut Paper
Ready?!
1 – Rock
2 – Paper
3 – Scissors
0 - Exit
Please choose your action: 2
Computer chose Paper!
It’s a tie!
You have won 0 of 1 games.
Ready?!
1 – Rock
2 – Paper
3 – Scissors
0 - Exit
Please choose your action: 2
Computer chose Rock!
You win!
You have won 1 of 2 games.
Ready?!
1 – Rock
2 – Paper
3 – Scissors
0 - Exit
Please choose your action: 0
Goodbye!
You have won 1 of 2 games.
先别急,我还没加exit进去。。
我现在遇到的状况是这样的:
Welcome! Let’s Play Rock-Paper-Scissors!'
Remember:
Rock breaks Scissors, Paper covers Rock and Scissors cut Paper
Ready?!
1. Rock
2. Paper
3. Scissors
Please choose your action:
3
Computer chose Scissors!
It’s a tie!
You have won 0 of 1 games.
Ready?!
1. Rock
2. Paper
3. Scissors
Please choose your action:
1
Computer chose Rock!
It’s a tie!
You have won 0 of 1 games.
Ready?!
1. Rock
2. Paper
3. Scissors
Please choose your action:
2
Computer chose Rock!
You win!
You have won 1 of 1 games.
Ready?!
1. Rock
2. Paper
3. Scissors
Please choose your action:
2
Computer chose Rock!
You win!
You have won 1 of 1 games.
为毛一直是1啊。。。。。。。。。。。。。。
而且胜局也加不起来啊。。。。。。。。。。。。。
求解!!!!!!!!