骰子游戏(JAVA)

importjava.util.Random;

importjava.util.*;

importjavax.swing.JOptionPane;

importjava.io.File;

importjava.util.HashMap;

importjava.util.Iterator;

importjava.util.Map;

importjava.util.Set;

importjava.util.Map.Entry;

publicclassDicerGame{

staticinta=0,b=0,c=0,d=0,e=0,f=0;

staticdoubleg=0;

Stringstr,str1,str2,str3;

intx[][]=newint[a][6];

inty=0;

intcount=0;

Stringz[]=newString[5];

Randomr=newRandom();

Map<String,Integer>map=newHashMap<String,Integer>();publicDicerGame(){

//if(o==1){

//给数组x[i][j]增加a*6个面的值

for(inti=0;i<x.length;i++){

for(intj=0;j<x[0].length;j++){

b=b+1;

x[i][j]=b;

if(b==6){

b=0;

}

}

}

//Z[F]用于统计随机抽出的骰子是不是全部一样

for(intp=0;p<x.length;p++){

c=r.nextInt(6);

y=x[p][c]+y;

z[f]=String.valueOf(x[p][c]);

f++;

"+z[4];

2+"元");

你输了");

"+z[4];}for(Stringstr:z){Integernum=map.get(str);num=null==num?1:num+1;map.put(str,num);}if(z.length!=map.size()){//System.out.println("存在相同的数字!");}Setset=map.entrySet();Iterator<Entry>it=set.iterator();while(it.hasNext()){Entry<String,Integer>entry=(Entry<String,Integer>)it.next();count++;}//判断结果d=1,d=2,d=3,d=4四种情况下得输赢if(d==1){str1="电脑的点数是"+y+"\n"+z[0]+""+z[1]+""+z[2]+""+z[3]+"if(y>((a*6)/2)){JOptionPane.showMessageDialog(null,str1+"\n"+"你赢了"+g*}elseif(y<=((a*6)/2)){JOptionPane.showMessageDialog(null,str1+"\n"+"你输了");}elseif(count==5){JOptionPane.showMessageDialog(null,str1+"\n"+"围骰,通杀"+"}}if(d==2){str1="电脑的点数是"+y+"\n"+z[0]+""+z[1]+""+z[2]+""+z[3]+"

if(y>=((a*6)/2)){

JOptionPane.showMessageDialog(null,str1+"\n"+"你输了");

}elseif(y<((a*6)/2)){

JOptionPane.showMessageDialog(null,str1+"\n"+"你赢了"

+g*2+"元");

}

elseif(count==5){

JOptionPane.showMessageDialog(null,str1+"\n"+"围骰,通杀"+"

你输了");

}

}

if(d==3){

str1="电脑的点数是"+y+"\n"+z[0]+""+z[1]+""+z[2]+""+z[3]+"

"+z[4];

if(y>((a*6)/2)){

JOptionPane.showMessageDialog(null,str1+"\n"+"你输了");

}elseif(y<((a*6)/2)){

JOptionPane.showMessageDialog(null,str1+"\n"+"你输了");

}elseif(y==((a*6)/2)){

JOptionPane.showMessageDialog(null,str1+"\n"+"你赢了"+g*

4+"元");

}

elseif(count==5){

JOptionPane.showMessageDialog(null,str1+"\n"+"围骰,通杀"+"

你输了");

}

}

if(d==4){

str1="电脑的点数是"+y+"\n"+z[0]+""+z[1]+""+z[2]+""+z[3]+"

"+z[4];

if(count==5){

JOptionPane.showMessageDialog(null,str1+"\n"+"你赢了"+g*

10

+"元");

}else

JOptionPane.showMessageDialog(null,str1+"\n"+"你输了");

}

}

publicstaticvoidmain(String[]args){

//e=Integer.valueOf(JOptionPane.showInputDialog("游戏类型(1:赌大小)"));

a=Integer.valueOf(JOptionPane.showInputDialog("亲,输入骰子个数(最大个数为5,最小个数为2):"));

if(a>5||a<=1){

JOptionPane.showMessageDialog(null,"亲,骰子个数不符合规定哦,请退出");System.exit(1);


}

g=Double.valueOf(JOptionPane.showInputDialog("亲,投注金额:"));

d=Integer.valueOf(JOptionPane.showInputDialog("亲,1:大,2:小,3:和4:围骰"));

if(d>4||d<0){

JOptionPane.showMessageDialog(null,"亲,这不可以买噢,请退出");

System.exit(1);

}

DicerGamedicer=newDicerGame();

}

}


喜欢java,并且想学java的宝宝们,可以加java学习QQ群~ 群里每天都有老师辅导上课的哦~
java直播辅导群:175161984

阅读更多
换一批

没有更多推荐了,返回首页