人机猜拳(顺序:一-->二-->三-->四)

四.public class Test{
public static void main(String[] args){
Game game=new Game();
game.initial();
game.startGame();}
}

三.public class game{Person person;Computer=computerint count ;public void initial(){person=new Person();computer=new Computer();count=0;}public void startgame(){System.out.println("欢迎进入猜拳");System.out.println("********");System.out.println("**猜拳开始**");System.out.println("********");System.out.prontln("出拳规则:1.剪刀2.石头3.布");Scanner input=new Scanner(System.in);System.out.println("请选择对方角色:(1.刘备2.曹操3.孙权)");int role=input.nextInt();System.out.println("请输入你的名字");person. name=input.next();switch(role){case 1:computer.name="刘备";break;case 2:computer.name="孙权"break;case 3:computer.name="曹操"break;}System.out.println(computer.name+"vs"+person.name+"\n")System.out.println("是否开始游戏(y/n)");String con=input.next();while(con.equals("y")){int pershow=person.showfist();int comshow=computer.showfist();if(pershow==comshow){System.out.println("真衰,平局");}else if((pershow==1&&comshow==2)||(pershow==2&&comshow==3)||(pershow==3&&comshow==1)){System.out.println("真悲哀,你输了");computer.score++;count++;}else if(pershow==2&&comshow==1||pershow==3&&show==2||pershow==1&&comshow==3){System.out.println("恭喜你你赢了!");person.score++;count++;}System.out.println("是否开始下一轮?y/n");con=input.next();}System.out.println("对战次数"+count);System.out.println("computer.name+"vs"+person.name");System.out.println("computer.score+"vs"+person.name");if(computer.score>person.score){System.out.println("你输了");}else(computer.score==person.score){System.out.println("平局");}else{System.out.println("你赢了");}} }


一.public class computer{
String name="电脑";
int score=0;
public int showfist(){
int show=(int)(Math.random()*10)%3+1
switch(show){
case 1:
System.out.println("电脑出拳:剪刀");
break;
case 2:
System.out.println("电脑出拳:石头");
break;
case 3:
System.out.println(电脑出拳:布);
break;}
return show;
}}


二public class person{
String name="匿名";
int score=0;
public int showfist(){
System.out.println("请猜拳(1.剪刀,2.石头,3.布(请选择))");
Scanner input=new Scanner(System.in)
int show=input.nextInt();
switch(show){
case 1:
 System.out.println("你出:剪刀");
break;
case 2:
System.out.println("你出:石头");
break;
case 3:
System.out.println("你出:布");
break;}
return show;}}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值