资源描述:
《新人学eclipse的小游戏》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、Eclipse中编写的Java小游戏初学java时编写的简单小游戏,非界面版,纯java基础组成,新人都能看得懂可以做的来,主要是其中的逻辑思想。使用eclipse编程,直接建立一个java复制代码进去就可以了。希望对大家学习java编程有点帮助类似于大家玩过的老虎机程序,在这里进行简化packageday;importjava.util.Random;importjava.util.Scanner;importjava.util.regex.Matcher;importjava.util.regex.Pattern;publ
2、icclassGame3{publicstaticvoidmain(String[]args){intmanly=100;String[]i={"龙","羊","猪","牛","虎","鸡","蛇","","虎","羊","牛","猪","鸡","蛇","牛","","羊","猪","蛇","鸡","猪","鸡","鸡",};Scannerscanner=newScanner(System.in);System.out.println("玩个小游戏,现在你手上有100分,从-龙虎猪牛羊鸡蛇-进行押注,可重复");System.
3、out.println("龙10倍,虎5倍,蛇3倍,牛、羊、猪2倍,鸡一倍,输入押注方式(龙5;虎1)。输入exit时则停止");Randomr=newRandom();Patternpattern=Pattern.compile("^([龙,虎,蛇,牛,羊,猪,鸡][0-9];)*[龙,虎,蛇,牛,羊,猪,鸡][0-9]{1}$");for(;;){System.out.println("游戏开始");intx=r.nextInt(i.length);intma=0;charya=i[x].charAt(0);Strings
4、tr=scanner.nextLine();Matchermatcher=pattern.matcher(str);if(matcher.find()){if(str.equalsIgnoreCase("")){System.out.println("输入为空,请重试,您的余额为"+manly);continue;}if(str.equalsIgnoreCase("exit")){System.out.println("游戏结束,您的余额为"+manly);break;}if(ya=='龙'){ma=10+1;}elseif(
5、ya=='虎'){ma=5+1;}elseif(ya=='蛇'){ma=3+1;}elseif(ya=='牛'
6、
7、ya=='羊'
8、
9、ya=='猪'){ma=2+1;}elseif(ya=='鸡'){ma=1+1;}else{System.out.println("很不巧,您中了空,再接再厉");}String[]strs=str.split(";");intme=0;for(inta=0;a10、seInt(strs[a].substring(1,strs[a].length()));intmanly1=manly;manly1=manly-in;if(manly1<0){System.out.println("不好意思,您的钱不够");break;}else{manly=manly1;}if(str1.equalsIgnoreCase(String.valueOf(ya))){me+=in*ma;}}if(me==0){System.out.println(ya+";很遗憾您没有中;您的余额为"+manly);}el
11、se{manly=manly+me;System.out.println("恭喜中了"+ya+";获得"+me+";您的余额为"+manly);}if(manly==0){System.out.println("你的余额为0,游戏结束");break;}}else{System.out.print("请输入正确的格式");}}}}