标签:错误 name while amp dom 选择 ext and rgs
人机猜拳
public class bdqn1 { /** * @param args */ public static void main(String[] args) { Scanner input = new Scanner(System.in); String m = ""; int juese = 1; bdqn2 c = new bdqn2(); bdqn3 b = new bdqn3(); do { System.out.println("******************欢迎进入游戏世界******************"); System.out.println(); System.out.println("\t **************************"); System.out.println("\t ** 猜拳 ,开始 **"); System.out.println("\t **************************"); System.out.println("\n"); System.out.println("出拳规则:1 剪刀2石头3布"); System.out.println("请输入姓名:"); String name = input.next(); b.showw(); System.out.println("开始吗"); String o = input.next(); if (o.equals("y")) { c.show(); if (juese == 1) { System.out.println("刘备" + "vs" + name); } if (juese == 2) { System.out.println("孙权" + "vs" + name); } if (juese == 3) { System.out.println("曹操" + "vs" + name); } c.show2(); System.out.println("下回加油"); } else { System.out.println("还继续吗"); m = input.next(); } } while (m.equals("y")); System.out.println("拜拜"); } }
public class bdqn2 { Scanner input=new Scanner(System.in); String y = ""; int count=0; int a=0; int b=0; public void show(){ do{ int random=(int)(Math.random()*3+1); System.out.println("请出拳: 1 剪刀 2石头 3布"); System.out.println("你出拳"); int number = input.nextInt(); if(number<=3){ switch (number) { case 1: System.out.println("你的出拳是 剪刀"); break; case 2: System.out.println("你的出拳是 石头"); break; case 3: System.out.println("你的出拳是 布"); break; default: System.out.println("错误请重新输入"); } if(random==1){ System.out.println("电脑出: 剪刀"); }if(random==2){ System.out.println("电脑出: 石头"); }if(random==3){ System.out.println("电脑出: 布"); } if ((number == 1 && random == 1) || (number == 2 && random == 2) || (number == 3 && random == 3)) { System.out.println("结果:和局真衰"); } else if ((number == 1 && random == 3) || (number == 2 && random == 1) || (number == 3 && random == 2)) { System.out.println("恭喜你赢了"); a++; } else { System.out.println("结果说:你输了真笨"); b++; } }else{ System.out.println("错误 请重新输入"); } System.out.println("继续吗"); y=input.next(); count++; }while(y.equals("y")); System.out.println("************************************"); System.out.println("对战次数"+count); } public void show2(){ System.out.println("你得"+a+"分"+"电脑得"+b+"分"); } }
public class bdqn3 { public void showw() { int juese =0; Scanner input = new Scanner(System.in); do{ System.out.println("请选择对方角色 :1:刘备2:孙权3:曹操"); juese = input.nextInt(); if(juese==1){ System.out.println("你选择了刘备对战"); break; } if(juese==2){ System.out.println("你选择了孙权对战"); break; }if(juese==3){ System.out.println("你选择了曹操"); break; }else{ System.out.println("错误 请重新选择"); } }while(juese!=1&&juese!=2&&juese!=3); } }
标签:错误 name while amp dom 选择 ext and rgs
原文地址:http://www.cnblogs.com/wh1520577322/p/7359819.html