import java.util.Scanner;
public class caiquan_1 {
yonghulie person;
jisuanjilie computer;
int count;
public void initial() {
person = new yonghulie();
computer = new jisuanjilie();
count = 0;
}
public void show() {
System.out
.println("---------------------欢迎进入游戏世界-------------------------------\n");
System.out.println("\t\t******************");
System.out.println("\t\t** 猜拳,开始 **");
System.out.println("\t\t******************\n\n");
count = 0;
}
public void Game() {
initial();
Scanner input = new Scanner(System.in);
System.out.println("出拳规则:1.剪刀2.石头3.布");
System.out.println("请选择对方角色(1.刘备2.孙权3.曹操):");
int js = input.nextInt();
switch (js) {
case 1:
computer.namej = "刘备";
break;
case 2:
computer.namej = "孙权";
break;
case 3:
computer.namej = "曹操";
break;
}
System.out.print("请输入你的姓名:");
person.name = input.next();
System.out.println(person.name + " VS " + computer.namej + " 对战\n");
System.out.println("要开始吗?(y/n)");
String kai = input.next();
int PerFist ;//你出拳
int compFist ;//人机出拳
while (kai.equals("y")) {
PerFist = person.showy();
compFist = computer.showj();
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("结果: 恭喜, 你赢了!");
person.score++;
} else {
System.out.println("结果说:^_^,你输了\n");
computer.score++;
}
count++;
System.out.print("\n是否开始下一轮(y/n): ");
kai = input.next();
}
jieguo();
fang();
}
public void jieguo(){
System.out.println("---------------------------------------------------");
System.out.println(computer.namej + " VS " + person.name);
System.out.println("对战次数:"+ count);
System.out.println("\n姓名\t得分");
System.out.println(person.name+"\t"+person.score);
System.out.println(computer.namej+"\t"+computer.score+"\n");
int result = fang();
if(result == 1){
System.out.println("结果:打成平手,下次再和你一分高下!");
}else if(result == 2){
System.out.println("结果:恭喜恭喜!");
}else{
Syst
import java.util.Scanner;
public class jisuanjilie {
String namej="电脑";
int score = 0;
public int showj(){
int cq=(int)(Math.random()*3);
switch (cq){
case 1:
System.out.println(namej+"出拳:剪刀");
break;
case 2:
System.out.println(namej+"电脑出拳:石头");
break;
case 3:
System.out.println(namej+"电脑出拳:布");
break;
}
return cq;
}
}
import java.util.Scanner;
public class yonghulie {
String name = "匿名";
int score = 0;
public int showy() {
Scanner A=new Scanner(System.in);
System.out.println("请出拳:1.剪刀2.石头3.布(输入相应数字):");
int cq=A.nextInt();
switch (cq){
case 1:
System.out.println("你出拳:剪刀");
break;
case 2:
System.out.println("你出拳:石头");
break;
case 3:
System.out.println("你出拳:布");
break;
}
return cq;
}
}
public class caiquan {
/**
* @param args
*/
public static void main(String[] args) {
caiquan_1 N= new caiquan_1();
N.Game();
}
}
em.out.println("结果:呵呵,笨笨,下次加油啊!"); } System.out.println("---------------------------------------------------"); } public int fang(){ if(person.score == computer.score){ return 1; }else if(person.score > computer.score){ return 2; }else{ return 3; } } }