简单的java猜拳小游戏

简单的java猜拳小游戏

/**
 * 猜拳小游戏
 * @ author lyle
 */

import java.util.Scanner;

public class 猜拳小游戏 {

    public static void main(String[] args) {
        int jushu=0;
        int ying = 0;
    while (jushu<10){
        System.out.println("请猜拳");
        System.out.println("1为石头;2为剪刀,3为布");
        Scanner shuru=new Scanner(System.in);
        int q=shuru.nextInt();
        if(q!=1&q!=2&q!=3){
            System.out.println("不可输入其他数字");
            continue;
        }
        int w;
        w=(int)(3*Math.random()+1);
        if(q == 1){
            switch(w){
                case 1:
                    System.out.print("平局");
                    break;
                case 2:
                    System.out.println("赢了");
                    ying=ying+1;
                    break;
                case 3:
                    System.out.println("输了");
                    break;
            }
        }else if(q==2) {
            switch (w) {
                case 2:
                    System.out.print("平局");
                    break;
                case 3:
                    System.out.println("赢了");
                    ying = ying+1;
                    break;
                case 1:
                    System.out.println("输了");
                    break;
            }
        }else if(q==3){
            switch (w) {
                case 3:
                    System.out.print("平局");
                    break;
                case 1:
                    System.out.println("赢了");
                    ying = ying+1;
                    break;
                case 2:
                    System.out.println("输了");
                    break;
            }
        }
        System.out.println(w);

        jushu++;
        System.out.println();
        System.out.println();
    }
    System.out.println("一共赢了"+ying+"局");
    }
}

你可能感兴趣的:(java自学日记)