public class Computer {
String name;
int score;
public int showfist(){
int quan;
/*
do{
quan=(int)(Math.random()*10);
}while(quan>3||quan<1);
*/
quan=(int)(Math.random()*10);
if(quan<=2){
quan=1;
}else if(quan<=5){
quan=2;
}else{
quan=3;
}
switch(quan){
case 1:System.out.println(name+"出拳:剪刀");break;
case 2:System.out.println(name+"出拳:石头");break;
case 3:System.out.println(name+"出拳:布");break;
}
return quan;
}
}
import java.util.*;
public class Game {
int count=0;
int countP=0;
Person person=new Person();
Computer computer=new Computer();
Scanner input=new Scanner(System.in);
public void initial(){
System.out.print("请选择你的角色(1.刘备 2.孙权 3.曹操):");
int juese=input.nextInt();
switch(juese){
case 1:person.name="刘备";
break;
case 2:person.name="孙权";
break;
case 3:person.name="曹操";
break;
}
System.out.print("请选择对手角色(1.关羽 2.张飞 3.赵云):");
int JueSe=input.nextInt();
switch(JueSe){
case 1:computer.name="关羽";
break;
case 2:computer.name="张飞";
break;
case 3:computer.name="赵云";
break;
}
}
public void begin(){
System.out.print("
要开始吗? (y/n)");
String ans=input.next();
if(ans.equals("y")){
String answ;
do{
int a=person.showFist();
int b=computer.showfist();
if(a==1&&b==3||a==2&&b==1||a==3&&b==2){
System.out.println("结果:你赢了!");
person.score++;
}else if(a==1&&b==1||a==2&&b==2||a==3&&b==3){
System.out.println("结果:平局,真衰!嘿嘿,等着瞧吧!");
countP++;
}else{
System.out.println("结果:你输了!");
computer.score++;
}
count++;
System.out.print("
是否开始下一轮? (y/n)");
answ=input.next();
}while(answ.equals("y"));
}
}
public String calcResult(){
String a;
if(person.score>computer.score){
a="最终结果:恭喜恭喜!你赢了!";
}else if(person.score==computer.score){
a="最终结果:打成平手,下次再和你一决高下!";
}else{
a="最终结果:呵呵,你输了!笨笨,下次加油啊!";
}
return a;
}
public void showResult(){
System.out.println("---------------------------------------------------");
System.out.println("\t\t"+person.name+" VS "+computer.name+"
");
System.out.println("对战次数:"+coun