BoBing博饼(java控制台输出)

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

/*²©±ý£¨¿ØÖÆ̨Êä³ö£©/*²©±ýСÓÎÏ·ÓÎϷʹÓÃ÷»×ÓÒ»¸±£¨6¸ö£©£¬²ÎÓëÓÎÏ·µÄÍæ¼ÒÂÖÁ÷ÒÀ´ÎÖÀ÷»×Ó£¬¿´÷»×ÓµãÊýµÃ±ý£ºÓÐ1¸ö¡°Ëĵ㡱£¬µÃ¡°Ò»Ð㡱±ý£»ÓÐ2¸ö¡°Ëĵ㡱£¬µÃ¡°¶þ¾Ù¡±±ý£»ÓÐ3¸ö¡°Ëĵ㡱£¬µÃ¡°Èýºì¡±±ý£»ÓÐ4¸öÏàͬµãÊý£¨³ýËĵãÍ⣩£¬µÃ¡°ËĽø¡±±ý£»Èô÷»×ÓµãÊý·Ö±ðΪ1-6˳ÐòÅÅÁУ¬µÃ¡°¶ÔÌá±±ý£»Íæ¼ÒµÃ¡°×´Ôª¡±±ýµÄÇé¿öÓм¸ÖÖ£¬ÆäµÈ¼¶°´´ÓСµ½´óÅÅÁÐÈçÏ£ºÓÐ4¸ö¡°Ëĵ㡱£¬µÃ¡°×´Ôª¡±£»ÓÐ5¸öÏàͬµãÊýµÄ£¬µÃ¡°Îå×ӵǿơ±£»ÓÐ4¸ö¡°Ëĵ㡱£¬¼ÓÉÏ2¸ö¡°Ò»µã¡±£¬µÃ¡°×´Ôª²å½ð»¨¡±£»ÌØÊâÇé¿ö£ºÈôÍæ¼ÒÖÀ³ö6¸ö¡°Ëĵ㡱µÃ¡°Áù±­ºì¡±£¬ÔòÖ±½Ó¶áµÃËùÓн±Æ·¡£³ÌÐòÒªÇ󣺣¨1£©£ºÓÎÏ·¿ªÊ¼Ê±£¬¿ÉÓÉÍæ¼ÒÉèÖý±Æ·Êý£¬ÀýÈ磺ÿ»á±ýÉè¡°×´Ôª¡±1¸ö£¬¡°¶ÔÌá±2¸ö£¬¡°Èýºì¡±4¸ö£¬¡°ËĽø¡±8¸ö£¬¡°¶þ¾Ù¡±16¸ö£¬¡°Ò»Ð㡱32¸ö¡££¨2£©£ºÓÎÏ·¿ªÊ¼Ê±£¬¿ÉÉ趨Íæ¼ÒÈËÊý£¬ÓÎÏ·ÖÐÓ¦Ìáʾ¸÷λÍæ¼ÒÂÖÁ÷ÒÀ´ÎÖÀ÷»×Ó£¬ÀýÈç¡°1ºÅÍæ¼ÒÇëÖÀɸ×Ó£ºy¡±£»£¨3£©ÓÎÏ·ÖУ¬Ó¦ÏÔʾÍæ¼Òÿ´ÎÖÀµÃµÄµãÊý£¬²¢ÏÔʾµÃ½±Çé¿ö¡£ÀýÈç¡°1,2,3,5,5,6ÎÞ½±£¬¼ÌÐøŬÁ¦¡±£»¡°1,4,4,3,5,6¶þ¾Ù£¬¹§Ï²¡±¡£³ÌÐòÓ¦Äܱ£´æ¸÷λÍæ¼ÒµÃ½±µÄ¼Ç¼¡££¨4£©ÓÎÏ·É趨µÄ¡°Ò»Ð㡱¡¢¡°¶þ¾Ù¡±¡¢¡°Èýºì¡±¡¢¡°ËĽø¡±¡¢¡°¶ÔÌᱵĽ±Æ·ÈôÁìÍ꣬ºóÐøÍæ¼ÒÈôÔÙÖÀ³ö´ËÀàµãÊý£¬²»Ôٵý±¡£µ«ÔÚÉÏÊö½±Æ·ÁìÍêÇ°£¬¡°×´Ôª±ý¡±²Éȡ׷±ýµÄ·½Ê½£¬¼´ÔÚÆäËû½±Æ··ÖÍêÇ°£¬ºóÒ»¸öÖÀµÃ¡°×´Ôª¡±µÄÈËÈô±ÈÇ°Ò»¸ö¡°×´Ôª¡±µÈ¼¶´ó£¬Ôò¿É×·µÃ¡°×´Ôª±ý¡±¡££¨5£©ËùÓн±Æ··ÖÍ꣬ÓÎÏ·½áÊø¡£»òÕßijÍæ¼ÒÖÀ³ö6¸ö¡°Ëĵ㡱£¬¶áµÃËùÓн±Æ·£¬ÆäËûÍæ¼Ò½«Í¬Ê±Ê§È¥ËùÓн±Æ·£¬ÓÎÏ·½áÊø¡££¨6£©ÓÎÏ·½áÊøºó£¬Ó¦Êä³öËùÓÐÍæ¼ÒµÃ½±Çé¿ö¡£*/¸£ÖÝ´óѧÈí¼þѧԺ09¼¶ÎºÒÕÈÙ*/importjava.util.Scanner;publicclassBoBing{privateint[]dice=newint[7];privateint[]diceNum=newint[7];privateintyixiu=0;//ÉèÖÃÒ»Ð㣻privateinterju=0;//ÉèÖöþ¾Ù;privateintsanhong=0;//ÉèÖÃÈýºì;privateintsijin=0;//ÉèÖÃËĽø;privateintduitang=0;//ÉèÖöÔÌÃ;finalintzhuangyuan=1;//ÉèÖÃ×´Ôª£»privateintliuhong=0;//Áù±­ºì£¬ÅжϽáÊø£»privateintpeople=0;//Íæ¼ÒÊý£»privateintyixiu1=0;//ͳ¼ÆÒ»Ðã;privateinterju1=0;//ͳ¼Æ¶þ¾Ù;privateintsanhong1=0;//ͳ¼ÆÈýºì;privateintsijin1=0;//ͳ¼ÆËĽø;privateintduitang1=0;//ͳ¼Æ¶ÔÌÃ;privateintzhuangyuan1=0;//ͳ¼Æ×´Ôª£»privateintwuzi=0;privateintchajin=0;privateintpos;//״Ԫ׷±ýÓã»±£´æÍæ¼Òϱêprivateint[]man=newint[7];//½áÊøÌõ¼þµÄÅжϣ»publicstaticclassPeople{publicintNyixiu=0;//ͳ¼ÆÒ»Ðã;publicintNerju=0;//ͳ¼Æ¶þ¾Ù;publicintNsanhong=0;//ͳ¼ÆÈýºì;publicintNsijin=0;//ͳ¼ÆËĽø;publicintNduitang=0;//ͳ¼Æ¶ÔÌÃ;publicintNzhuangyuan=0;//ͳ¼Æ×´Ôª£»}publicvoidPlay(){Scannersc=newScanner(System.in);System.out.println("ÉèÖø÷ÏƷÊýºÍ²ÎÓëÈËÊý£º");System.out.println("ÉèÖÃÒ»Ð㽱ƷÊý£º");yixiu=sc.nextInt();System.out.println("ÉèÖöþ¾Ù½±Æ·Êý£º");erju=sc.nextInt();System.out.println("ÉèÖÃÈýºì½±Æ·Êý£º");sanhong=sc.nextInt();System.out.println("ÉèÖÃËĽø½±Æ·Êý£º");sijin=sc.nextInt();System.out.println("ÉèÖöÔÌý±Æ·Êý£º");duitang=sc.nextInt();//System.out.println("ÉèÖÃ×´Ôª½±Æ·Êý£º");//zhuangyuan=sc.nextInt();System.out.println("ÉèÖòÎÓëÈËÊý£º");people=sc.nextInt();People[]person=newPeople[people+1];for(inti=1;i<=people;++i)person[i]=newPeople();//ʵÀý»¯People¶ÔÏó£»while(!GameOver(person)){for(intj=1;j<=6;++j)diceNum[j]=0;for(inti=1;i<=people;++i){for(intj=1;j<=6;++j)diceNum[j]=0;System.out.println("\n"+i+"ºÅÍæ¼ÒÇëÖÀɸ×Ó:");Stringch=sc.next();if("y".equals(ch))Game(i,person);elsecontinue;}}}publicvoidResult(People[]arry){if(liuhong==1)System.exit(1);else{System.out.println("½±Æ·È«²¿·¢Í꣬ÓÎÏ·½áÊø¡£");System.out.println("Íæ¼Ò»ñ½±Çé¿ö£º");System.out.println("Íæ¼Ò±àºÅ"+"\t"+"×´Ôª"+"\t"+"Ò»Ðã"+"\t"+"¶þ¾Ù"+"\t"+"ËĽø"+"\t"+"Èýºì"+"\t"+"¶ÔÌÃ");for(inti=1;i<=people;++i){System.out.print(i);System.out.print("\t"+arry[i].Nzhuangyuan);System.out.print("\t"+arry[i].Nyixiu);System.out.print("\t"+arry[i].Nerju);System.out.print("\t"+arry[i].Nsijin);System.out.print("\t"+arry[i].Nsanhong);System.out.println("\t"+arry[i].Nduitang);}}}publicbooleanGameOver(People[]arry){if(liuhong==1){System.out.println("¸ÃÍæ¼ÒÖ±½Ó¶áµÃËùÓн±Æ·£¬ÆäËûÍæ¼ÒͬʱʧȥËùÓн±Æ·¡£¡£¡£‡å");returntrue;}if(man[1]==1&&man[2]==1&&man[3]==1&&man[4]==1&&man[5]==1&&man[6]==1){Result(arry);returntrue;}returnfalse;}publicvoidGame(intt,People[]arry){for(inti=1;i<=6;++i){dice[i]=1+(int)(Math.random()*6);diceNum[dice[i]]++;}ShowResult(diceNum,t,arry);}publicvoidShowResult(int[]sum,intt,People[]arry){switch(sum[4]){case0:if(sum[1]==4||sum[2]==4||sum[3]==4||sum[5]==4||sum[6]==4){for(intj=1;j<=6;++j){if(j==6)System.out.print(dice[j]+"ËĽø£¬¹§Ï²");elseSystem.out.print(dice[j]+",");}if(sijin1<sijin){sijin1++;arry[t].Nsijin++;}else{System.out.print(",²»¹ýºÜÒź¶£¬ËĽø½±Æ·ÒÑ·¢ÍêºÙºÙ¡£");man[4]=1;}}elseif(sum[1]==5||sum[2]==5||sum[3]==5||sum[5]==5||sum[6]==5){for(intj=1;j<=6;++j){if(j==6)System.out.print(dice[j]+"Îå×ӵǿƣ¬¹§Ï².");elseSystem.out.print(dice[j]+",");}if(wuzi+zhuangyuan1+chajin<zhuangyuan){wuzi++;arry[t].Nzhuangyuan++;pos=t;}

1 / 10
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功