Java石头剪刀布

石头剪刀布
package cn.qqq.cq;
import java.util.Scanner;
public class youxi {
teng computer;
youhu user;
String name="";
int Score =0;
public void initial(){//游戏开始界面
System.out.println("----------欢迎进入游戏世界-----------");
System.out.println(“");
System.out.println("
猜拳,开始 ");
System.out.println("
”);
System.out.println(“出拳规则:1.剪刀 2.石头 3.布”);
System.out.println(“请选择对方角色(1:刘备 2:孙权 3:曹操):”);
//选择对战角色
Scanner in = new Scanner(System.in);
int b = in.nextInt();
switch (b) {
case 1:
System.out.println(“你选择刘备”);
break;
case 2:
System.out.println(“你选择孙权”);
break;
case 3:
System.out.println(“你选择曹操”);
break;
//选择石头剪刀布
}
System.out.println(“请出拳1剪刀2石头3布”);
computer=new teng();
user=new youhu();
} //判断是否还要不要继续玩
public void startGame(){
System.out.println(“要开始吗?y:是 n:否”);
Scanner input = new Scanner(System.in);
//输入出拳序号
int per;
int com;
String con=“y”;
while (“y”.equals(con)){
Score++;
per = user.showFist();
com = computer.showFist();
if ((per == 1 && com == 1) || (per == 2 && com == 2)
|| (per == 3 && com == 3)) {//两次平手显示平局
System.out.println(“电脑选择”+computer.chu+",结果:和局,真衰!");
} else if ((per == 1 && com == 3) || (per == 2 && com == 1)
|| (per == 3 && com == 2)) {//如果我方比电脑多出一分显示你赢了
System.out.println(“电脑选择”+computer.chu+",结果:恭喜,你赢了!");
//如果我方比电脑多出一分显示你赢了
} else {//结果
System.out.println(“电脑选择”+computer.chu+",结果说:_,你输了,真笨!");
} //计算次数
System.out.println(“是否进行下一轮.y:是 n:否”);
con = input.next();
}
System.out.println(“次数是”+Score);

	}
}		

package cn.qqq.cq;
import java.util.Scanner;
public class youhu {
public String name ;
public int Score ;
public String chu;//电脑
public int showFist(){
System.out.println(“请出拳1剪刀2石头3布”);
Scanner in = new Scanner(System.in);
int cheng = in.nextInt();//选择石头剪刀布
switch (cheng) {
case 1:
System.out.println(“你出剪刀”);//序号1出剪刀
chu =“剪刀”;
break;
case 2:
System.out.println(“你出石头”);//序号2出石头
chu =“石头”;
break;
case 3:
System.out.println(“你出布”);//序号3出布
chu =“布”;
break;
}
return cheng;
}
}

package cn.qqq.cq;
import java.util.Scanner;
public class teng {
//电脑类
public String name ;
public int Score ;
public String chu;
public int showFist(){
//显示对战结果
int wan=(int)(Math.random()*3+1);
switch (wan) {
case 1:
chu=“剪刀”;
//System.out.println(“电脑选择剪刀”);
break;
case 2:
chu=“石头”;
//System.out.println(“电脑选择石头”);
break;
case 3:
chu=“布”;
//System.out.println(“电脑选择布”);
break;
}
return wan;

		//System.out.println(+"VS"+);
		//System.out.peintln("对战次数:"+);
   //return wan;         		  

}
}

你可能感兴趣的:(Java)