欢迎来到天天文库
浏览记录
ID:8979915
大小:27.00 KB
页数:3页
时间:2018-04-13
《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
此文档下载收益归作者所有