package RanDom;
import java.util.Scanner;
import java.util.Random;
public class GameDemo {
public static void sop(Object obj)
{
System.out.println(obj);
}
public static void main(String[] Ags)
{
sop("---------欢迎进入游戏世界---------");
sop("");
sop("");
sop("*****************************");
sop(" **猜拳开始**");
sop("*****************************");
sop("出拳规则:1 石头 2 剪刀 3 布 4 退出");
sop("对战人物:1 修罗 2 地狱犬 3 啸月天狼 4 退出");
sop("三局两胜制");
sop("");
sop("");
sop("请输入对战人物:");
Scanner in = new Scanner(System.in);
int vs = in.nextInt();
sop("请输入猜拳序号:");
int get = in.nextInt();
new Vs(vs,get).getNum();
}
}
class Vs {
private int vs,get;
Vs(int vs, int get)
{
this.vs = vs;
this.get = get;
}
public void getNum()
{
if(vs==4||get==4)
{
System.out.println("游戏结束!");
}else if(vs<=0||vs>4||get<=0||get>4)
{
System.out.println("数字输入错误!");
}
else if(vs==1)
{
System.out.println("修罗与您对战,中途不给逃跑哦!");
new xiuLuo().VS(get);
}
else if(vs==2)
{
System.out.println("地狱犬与您对战,中途不给逃跑哦!");
new dog(get);
}
else
System.out.println("啸月天狼与您对战,中途不给逃跑哦!");
new xiaoYue(get);
}
}
class xiuLuo {
private int count1 = 0;//胜利
private int count2 = 0;//平局
private int count3 = 0;//失败
private int x;
private int y;
xiuLuo(){}
public void sop(Object obj)
{
System.out.println(obj);
}
public void VS(int get)
{
Scanner s = new Scanner(System.in);
if(get==1)
{
Random r = new Random();
x = r.nextInt(3)+1;
if(x==1)
{
sop("双方均为石头,平局");
if((count1+count2+count3)==2)
{
sop("次数达到上限,游戏结束。");
System.exit(0);
}
sop("请输入猜拳序号:");
y = s.nextInt();
++count2;
VS(y);
}else if(x==2)
{
sop("我出了石头,对方出了剪刀,胜利!");
if(count1==1)
{
sop("恭喜游戏胜利!");
System.exit(0);
}
sop("请输入猜拳序号:");
y = s.nextInt();
++count1;
VS(y);
}
else if(x==3)
{
sop("我出了石头,对方出了布,失败!");
if((count1+count2+count3)==2)
{
sop("次数达到上限,游戏结束。");
System.exit(0);
}
sop("请输入猜拳序号:");
y = s.nextInt();
++count3;
VS(y);
}
}
if(get==2)
{
Random r = new Random();
x = r.nextInt(3)+1;
if(x==1)
{
sop("我出了剪刀,对方出了石头,失败!");
if((count1+count2+count3)==2)
{
sop("次数达到上限,游戏结束。");
System.exit(0);
}
sop("请输入猜拳序号:");
y = s.nextInt();
++count3;
VS(y);
}else if(x==2)
{
sop("双方均为剪刀,平局!");
if((count1+count2+count3)==2)
{
sop("次数达到上限,游戏结束!");
System.exit(0);
}
sop("请输入猜拳序号:");
y = s.nextInt();
++count2;
VS(y);
}
else if(x==3)
{
sop("我出了剪刀,对方出了布,胜利!");
if(count1==1)
{
sop("游戏胜利!");
System.exit(0);
}
sop("请输入猜拳序号:");
y = s.nextInt();
++count1;
VS(y);
}
}
if(get==3)
{
Random r = new Random();
x = r.nextInt(3)+1;
if(x==1)
{
sop("我出了布,对方出了石头,胜利!");
if(count1==1)
{
sop("游戏胜利!");
System.exit(0);
}
sop("请输入猜拳序号:");
y = s.nextInt();
++count1;
VS(y);
}else if(x==2)
{
sop("我出了布,对方出了剪刀,失败!");
if((count1+count2+count3)==2)
{
sop("次数达到上限,游戏结束!");
System.exit(0);
}
sop("请输入猜拳序号:");
y = s.nextInt();
++count3;
VS(y);
}
else if(x==3)
{
sop("双方均出了布,平局。");
if((count1+count2+count3)==2)
{
sop("次数达到上限,游戏结束。");
System.exit(0);
}
sop("请输入猜拳序号:");
y = s.nextInt();
++count2;
VS(y);
}
}
}
}
class dog extends xiuLuo{
dog(int get)
{
super.VS(get);
}
}
class xiaoYue extends xiuLuo{
xiaoYue(int get)
{
super.VS(get);
}
}
不知道该如何调整难度,就写了个简单点的
|