import java.util.Scanner;

public class Person {
     
    public int showFist() {
        Scanner input = new Scanner(System.in);
            System.out.println("请出拳:1.剪刀2.石头3.布(输入相应的数字)");
            int x = input.nextInt();
            switch (x) {
            case 1:
                System.out.println("你出拳:剪刀");
                break;
            case 2:
                System.out.println("你出拳:石头");
                break;
            case 3:
                System.out.println("你出拳:布");
                break;
            default:
                System.out.println("输入错误");
                break;
            }
             return x;

        }


}

 

public class Computer{
    public int showFist(){
        int s=(int)(Math.random()*10%3+1);
        switch(s){
        case 1:
        System.out.println("电脑出拳:剪刀");
        break;
        case 2:
        System.out.println("电脑出拳:石头");
        break;
        case 3:
        System.out.println("电脑出拳:布");
        berak;
        default:
        System.out.println("输入错误");
        break;        
        }
        return s;
    }
}

 

import java.util.Scanner;

public class Caiquan {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        Person o = new Person();
        Computer on = new Computer();
        int count = 0;
        int wo = 0;
        int computer = 0;
        System.out.println("------------------欢迎进入游戏世界---------------------");
        System.out.println("\n");
        System.out.println("\t\t***************\t\t");
        System.out.println("\t\t*** 猜拳,开始   ***\t\t");
        System.out.println("\t\t***************\t\t");
        System.out.println("出拳规则:1.剪刀2.石头3.布");
        System.out.print("请选择对方角色(1:刘备2:孙权3:曹操):");
        int x = input.nextInt();
        String name1 = "";
            switch (x) {
                case 1:
                    name1 = "刘备";
                    System.out.println("你选择了刘备对战");
                    break;
                case 2:
                    name1 = "孙权";
                    System.out.println("你选择了孙权对战");
                    break;
                case 3:
                    name1 = "曹操";
                    System.out.println("你选择了曹操对战");
                    break;
            }
            System.out.print("请输入你的姓名:");
            String name = input.next();
            System.out.println(name + "VS" + name1);
            String con = "";
            System.out.print("\n要开始码?(y/n):");
            con = input.next();

            while (con.equals("y")) {
            int perFist;
            int compFist;
            perFist = o.showFist();
            compFist = on.showFist();
                if ((perFist==1 && compFist==1)    || (perFist==2 && compFist==2) || (perFist==3 && compFist==3)) {
                    System.out.println("结果:平局\n");

                } else if ((perFist==1 && compFist==3) || (perFist==2 && compFist==1) || (perFist==3 && compFist==2)) {
                    System.out.println("结果:你赢了");
                    wo++;
                } else {
                    System.out.println("结果说:你输了\n");
                    computer++;
                }
                count++;
                System.out.print("\n是否开始下一轮(y/n):");
                con = input.next();
            }
            System.out.println("------------------------------------------");
            System.out.println(name + "VS" + name1);
            System.out.println("对战次数:" + count);
            System.out.println("姓名\t\t得分");
            System.out.println(name + "\t\t" + wo);
            System.out.println(name1 + "\t\t" + computer);
            if (computer < wo) {
                System.out.println("结果:你赢了");
            } else if (computer == wo) {
                System.out.println("结果:平局");
            } else if (computer > wo) {
                System.out.println("结果:你输了");
            }
                System.out.println("------------------------------------------");
        
        }

}

 

posted on 2017-08-14 16:46  ↑↑↓↓←→←→  阅读(208)  评论(0编辑  收藏  举报