package Demo2;
import java.util.Scanner;
public class Demoaa {
Scanner input=new Scanner(System.in);
/**
* 是否继续
*/
String choice="";
/**
* 电脑人物
*/
String name="";
String name2="";
/**
* 用户录入数字
*/
int num,num2,num3;
/**
*
* 产生随机数
*/
int random=(int)((Math.random()*3)+1);
/**
* 电脑人物随机出拳
* 1.剪刀 2.石头 3.布
*/
/**
* 战果
*/
int count; //次数
int victory;
int fail;
/**
* 电脑出拳
*/
public void show9() {
switch(random) {
case 1:
System.out.println(name+"出拳:剪刀");
break;
case 2:
System.out.println(name+"出拳:石头");
break;
case 3:
System.out.println(name+"出拳:布");
break;
}
}
/**
*
* 储存电脑人物
*/
public void show5() {
switch(num) {
case 1:
name="刘备";
break;
case 2:
name="关羽";
break;
case 3:
name="张飞";
break;
}
System.out.println("您选择了"+name+"来进行PK");
System.out.println(name2+" V S "+name);
System.out.println("对战!");
System.out.println("艾克神");
}
/**
* 用户选择
*
*/
public void show6() {
System.out.println("请出拳:1.剪刀 2.石头 3.布");
num2=input.nextInt();
switch(num2) {
case 1:
System.out.println("您出拳: 剪刀");
break;
case 2:
System.out.println("您出拳: 石头");
break;
case 3:
System.out.println("您出拳: 布");
break;
}
}
/**
* 进入首页
*
*/
public void show4() {
System.out.println("---------- 欢 迎 进 入 游 戏 世 界---------");
System.out.println("\n***************************");
System.out.println("猜拳大赛即将开始....");
System.out.println("*****************************");
System.out.println("\n 开 始...............");
System.out.println("出拳规则 : 1.剪刀 2.石头 3.布");
System.out.print("请选择要对战的角色 "
+ "(1:刘备兄 2:关羽哥 3:张飞弟) : ");
num=input.nextInt();
System.out.println("请输入你的名字 : ");
}
/**
* 判断结果
*/
public void show2() {
boolean is=false;
do {
count++;
if((num2==1 && random==3) || (num2==2 && random==1) || (num2==3 && random==2)) {
System.out.println("恭喜您战胜了" +name);
victory++;
}else if(num2==random) {
System.out.println(" 平 局 ");
}else {
System.out.println("您输了呀!继续加油.....");
fail++;
}
System.out.println("是否进入下一局:(y/n)");
choice=input.next();
if(choice.equals("y")) {
show6();
show9();
is=true;
}else {
is=false;
break;
}
}while(is);
}
/**
* 显示战果
*
*/
public void show3() {
System.out.println("\n\n"+name+" V S"+name2 );
System.out.println("\n对战次数:" +count+"次");
System.out.println("姓名\t得分");
System.out.println(name2+"\t"+victory);
System.out.println(name+"\t"+fail);
}
/**
* 显示结果
*/
public void show7() {
if(victory > fail) {
System.out.println("恭喜您战胜了" +name);
}else if(victory==fail) {
System.out.println("打成平局! 下次继续加油");
}else {
System.out.println("真他娘的笨....");
}
}
}
---------------------------------------------------------------------测试类
package Demo2;
import java.util.Scanner;
import Demo3.Demo;
public class Demoaa1 {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
Demoaa demo=new Demoaa();
demo.show4();
demo.name2=input.next();
demo.show5();
demo.show6();
demo.show9();
demo.show2();
demo.show3();
demo.show7();
}
}
1