package compute;
import java.util.Scanner;
public class game {
user a=new user();//人
computer b=new computer();//机器
int y = 0;// 出拳一样的次数
int s = 0;// 对战次数
//欢迎界面
public void welcome() {
System.out.println("***********************************");
System.out.println("********** 猜拳 开始 ********");
System.out.println("***********************************");}
//初始化
public void init() {
Scanner sc=new Scanner(System.in);
System.out.println("出拳规则:1.剪刀2.石头3.布");
System.out.println("请选择对方角色1.刘备2.孙权3.曹操");
switch(sc.nextInt()){
case 1:b.name="刘备";break;
case 2:b.name="孙权";break;
case 3:b.name="曹操";break;
default:System.out.println("输出错误,重新输入");
}
System.out.println("你选择的是"+b.name);
System.out.println("输入你的名字");
String in=sc.next();
System.out.println(in+"对战"+b.name);
System.out.println("是否要开始游戏(y/n)");
if(sc.next().equals("n")){
System.out.println("您选择了退出游戏");
}
}
//游戏进行
public void paly() {
Scanner sc = new Scanner(System.in);
do{
a.s1();
b.s2();
if(a.fist==b.B){
y++;
System.out.println("有两下子你和" + b.name + "达成了平手");
} else if (a.fist == 1 && b.B == 2|| a.fist == 2 && b.B == 3
|| a.fist == 3 && b.B == 1) {
a.score++;
System.out.println("太牛了你此盘战胜了" + b.name);
} else {
b.score++;
System.out.println("很遗憾你输给了" + b.name);
}
s++;
System.out.println("是否开始下一轮(y/n)");
} while (sc.next().equals("y"));
}
//游戏显示
public void print() {
System.out.println("--------------------------------");
System.out.println(b.name + "对战" + a.name);
System.out.println("对战次数" + s+"\t"+"平手次数是" + y);
System.out.println("姓名"+"\t得分");
System.out.println(a.name+"\t"+a.score);
System.out.println(b.name+"\t"+b.score);
if (a.score > b.score) {
System.out.println("结果:恭喜你 你赢了");
} else if (a.score < b.score) {
System.out.println("结果:很遗憾你输了");
}else if(a.score==b.score){
System.out.println("不分上下");
}
}
}
wm8888
相关分类