1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | package 上机练习; import java.util.Scanner; public class A01class { String name1; String name2; String A = "" , B = "" ; int count1 = 0 , count2 = 0 , count3 = 0 ; public String A() { return "\t**************************" + "\n\t**** 猜拳 , 开始 ****" + "\n\t**************************" ; } public void B() { System.out.println( "ˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉ" ); Scanner input = new Scanner(System.in); System.out.println( "出拳规则:1.剪刀 2.石头 3.布" ); System.out.print( "请选择对方角色(1.刘备 2.孙权 3.曹操):" ); int choice = input.nextInt(); System.out.println( "请输入您的名字:" ); name2 = input.next(); switch (choice) { case 1 : name1 = "刘备" ; break ; case 2 : name1 = "孙权" ; break ; case 3 : name1 = "曹操" ; break ; default : System.out.println( "输入错误!请重新选择:" ); B(); break ; } } public void C() { Scanner input = new Scanner(System.in); System.out.print( "\n要开始吗?(y/n):" ); char choice = input.next().charAt( 0 ); switch (choice) { case 'y' : D(); break ; case 'n' : System.out.println( "欢迎下次使用!" ); break ; default : System.out.println( "输入错误!请重新选择:" ); A01 TestA01 = new A01(); TestA01.main( null ); break ; } } public void D() { System.out.println( "ˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉ" ); Scanner input = new Scanner(System.in); int random = ( int ) (Math.random() * 10 ) % 3 + 1 ; System.out.println( "请出拳:1.剪刀 2.石头 3.布 (输入相应的数字:)" ); int choice = input.nextInt(); switch (choice) { case 1 : A = "剪刀" ; break ; case 2 : A = "石头" ; break ; case 3 : A = "布" ; break ; default : System.out.println( "输入有误!\n" ); D(); break ; } switch (random) { case 1 : B = "剪刀" ; break ; case 2 : B = "石头" ; break ; case 3 : B = "布" ; break ; default : System.out.println( "输入有误!\n" ); D(); break ; } System.out.println( "您出拳:" + A); System.out.println(name1 + "出拳:" + B); if (random == 1 && choice == 1 || random == 2 && choice == 2 || random == 3 && choice == 3 ) { System.out.println( "结果:→_←和局,真衰!" ); } else if (random == 1 && choice == 2 || random == 2 && choice == 3 || random == 3 && choice == 1 ) { System.out.println( "结果:△_△,您赢了,有点不服,再来啊 !" ); count1++; } else { System.out.println( "结果:^_^,你输了,真笨!呵呵!" ); count2++; } count3++; System.out.print( "是否进入下一轮(y/n):" ); char choice1 = input.next().charAt( 0 ); switch (choice1) { case 'y' : D(); break ; case 'n' : E(); break ; default : System.out.println( "输入错误!" ); break ; } System.out.println( "ˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉ" ); } public void E() { System.out.println( "ˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉ" ); System.out.println(name2 + " vs " + name1 + " 对战" ); System.out.println( "对战次数:" + count3); System.out.println( "\n姓名\t得分" ); System.out.println(name2 + "\t" + count1 + "\n" + name1 + "\t" + count2); if (count1 < count2) { System.out.println( "\n结果:^_^呵呵,笨笨,下次加油哦" ); } else if (count1 > count2) { System.out.println( "结果:→_←,您赢了,有点不服,再来啊 !" ); } else { System.out.println( "打成平手,下次在分搞下!" ); } } } package 上机练习; import java.util.Scanner; public class A01 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input = new Scanner (System.in); A01class A01 = new A01class(); System.out.println(A01.A()); A01.B(); System.out.println(A01.name2+ " vs " +A01.name1+ " 对战" ); A01.C(); } } |