注册 登录
编程论坛 JAVA论坛

已经试了无数遍,这个就是加不起来

mark191919 发布于 2015-12-12 11:41, 2983 次点击
声明:本人中文退化。

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啊。。。。。。。。。。。。。。
而且胜局也加不起来啊。。。。。。。。。。。。。
求解!!!!!!!!
5 回复
#2
mark1919192015-12-12 11:56
为啥一个人也没有
#3
mark1919192015-12-12 12:06
。。。。。。。。。。。。。
#4
逆水寒刘2015-12-12 16:16
int a,c,b;
        a=0;
//这里你把b作为比赛局数,这应该是个全局变量。现在将b的声明提到第一个do的前面就可以了。
#5
S_dawn2016-01-06 21:53
c=(int) (Math.random()*2+1);是在[1,3)区间抽取整数
所以 c抽取的数不是1就是2  没有3的存在
#6
wh8145748752016-01-11 12:37
java的命名要规范些 这样大家看着也方便的
1