java语言实现猜拳游戏的编写

java语言实现猜拳游戏的编写

ID:8979915

大小:27.00 KB

页数:3页

时间:2018-04-13

java语言实现猜拳游戏的编写_第1页
java语言实现猜拳游戏的编写_第2页
java语言实现猜拳游戏的编写_第3页
资源描述:

《java语言实现猜拳游戏的编写》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库

1、packageTG.Java_17;publicclassComputer{publicintgetFist(){intfist=(int)(Math.random()*10)%3+1;switch(fist){case1:System.out.println("机器:石头");break;case2:System.out.println("机器:剪刀");break;case3:System.out.println("机器:布");break;}returnfist;}}packageTG.Java_17;importjava.util.Scanner;publicclassPe

2、rson{publicintgetFist(){Scannerinput=newScanner(System.in);System.out.println("请用户猜拳:1.石头2.剪刀3.布");intfist=input.nextInt();switch(fist){case1:System.out.println("人类:石头");break;case2:System.out.println("人类:剪刀");break;case3:System.out.println("人类:布");break;default:System.out.println("对不起哈我们没有这个猜

3、拳选项");}returnfist;}}packageTG.Java_17;importjava.util.Scanner;publicclassTestFist{publicstaticvoidmain(String[]args){Personper=newPerson();Computercom=newComputer();Stringanswer=null;Scannerinput=newScanner(System.in);intpCount=0;intcCount=0;do{intpFist=per.getFist();intcFist=com.getFist();//我

4、们判读一下if((pFist==1&&cFist==2)

5、

6、(pFist==2&&cFist==3)

7、

8、(pFist==3&&cFist==1)){pCount++;}elseif((pFist==2&&cFist==1)

9、

10、(pFist==3&&cFist==2)

11、

12、(pFist==1&&cFist==3)){cCount++;}else{}System.out.println("小样的?你服不服啊?(y/n)");answer=input.next();}while(!"y".equals(answer));if(pCount>cCount){System.out.printl

13、n("恭喜,人类赢了!");}elseif(pCount

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。