首页 > 游戏

掷骰子的游戏java代码

更新时间2018-10-07 16:07:35

最好有程序的解释说明,然后得符合我图片上的要求。。

本人java渣渣,实在是懂不了高级词汇。。。。掷骰子的游戏java代码

import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.ArrayList;import java.util.List;import java.util.Random;public class DiceGame {private static final String MARK_CONTINUE = "YES";private static int score = 0;//赢的次数private static List<Integer> dices = new ArrayList<Integer>();//骰子的集合private static Random random = new Random(47);public static void main(String[] args) throws IOException {init();run();}/*** 初始化*/private static void init() {//2骰子,2到12for (int i = 2; i < 13; i++) {dices.add(i);}}/*** 开始运行* @throws IOException*/private static void run() throws IOException {while (true) {if (newBet()) {firstBlood();} else {System.out.println("~~~欢迎再来!你的战绩:" + score + "~~~");System.exit(0);}}}/*** 第1轮得到comeout*/private static void firstBlood() {System.out.println(" 1.开始...");System.out.println("1.0.掷骰子...");// 1.得出comeoutint comeout = throwDice();//2. 初次 7,11为winif (comeout == 7 || comeout == 11) {score++;System.out.println("1.1.恭喜你!ComeOut结果是:" + comeout + ",你赢了!>_<!!!");return;} else if (comeout == 2 || comeout == 3 || comeout == 12) {//3.初次2,3,12为输score--;System.out.println("1.2.很遗憾!ComeOut结果是:" + comeout + ",你输了!-_-!!!");return;} else {//初次为其他,需要重新投,为7是输,11为赢,其他为继续循环投diceAgainUntilWhoIsDaddy(comeout);}}/*** 第2轮后的无限循环,直到有输赢** @param comeout*/private static void diceAgainUntilWhoIsDaddy(int comeout) {while (true) {System.out.println("1.3.本次结果为:" + comeout + ",需要重新投掷...");System.out.println("2.0.掷骰子...");comeout = throwDice();if (comeout == 7) {score--;System.out.println("2.2.很遗憾!结果是:" + comeout + ",你输了!-_-!!!");break;} else if (comeout == 11) {score++;System.out.println("2.1.恭喜你!结果是:" + comeout + ",你赢了!>_<!!!");break;}continue;}}/*** 一次掷骰子** @return*/private static Integer throwDice() {return dices.get(random.nextInt(dices.size()));}/*** 是否开新局** @return* @throws IOException*/private static boolean newBet() throws IOException {//0.是否开局System.out.println(" 0.是否开新局,输入yes/YES开始...输入其他任意非空字符结束游戏...");String cmd;BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));while ((cmd = reader.readLine()) != null) {if (cmd.trim().isEmpty()) {System.out.println("!!!!!!!!!!!不能输入空字符!!!!!!!!!");continue;}break;}return MARK_CONTINUE.equals(cmd.trim().toUpperCase());}}

相关标签:java

上一篇:生死狙击怎么左手拿枪详细的说出来

下一篇:造梦西游四修改器地址给个谢谢了