Java AppleGame小游戏(第一版)
生活随笔
收集整理的這篇文章主要介紹了
Java AppleGame小游戏(第一版)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
游戲規則:用戶首先需要在提供的多種水果中挑選一種,并輸入想要投入的金幣個數來開始游戲。如果轉盤轉到的水果序號與用戶輸入的序號相同,則用戶勝利并獲得大量金幣,否則用戶失敗,并扣除相應的金幣。在一輪游戲結束后,用戶可以選擇是否進入下一輪游戲。
package com.yts.applegame;import java.util.Scanner;public class AppleGame_02 {public static int capmone = 100;// 本金public static void showMenu() {// 菜單頁面System.out.println("*序號.名稱----------倍數");System.out.println("*1. 蘋果-------2");System.out.println("*2. 葡萄-------5");System.out.println("*3. 橘子-------10");System.out.println("*4. 香蕉-------15");System.out.println("*5. 西瓜-------20");System.out.println("*6. 水果拼盤----50");System.out.println("*當前剩余金幣:" + capmone);}public static void vicOrDef(int a, int b, int c, int d) { // 用戶勝負判斷if (a == b) {System.out.println("恭喜,你猜對了!");capmone += c * (d - 1);} else {System.out.println("抱歉,你猜錯了!");capmone -= c;}}public static void main(String[] args) {// 數據初始化int multi; // 翻倍倍數int bet; // 投入金幣Scanner sc = new Scanner(System.in);int theSys;// 系統生成隨機數,作為轉盤轉到的水果int theSyss; // 水果序號修正int theGuess; // 用戶的選擇int rflag;// 判斷是否繼續游戲System.out.println("******歡迎來到蘋果機小游戲******");while (true) {theSys = (int) (Math.random() * 20 + 1);// 系統生成隨機數,作為轉盤轉到的水果// System.out.println(theSys); //作弊器// 是否開始游戲System.out.println("*是否開始游戲:開始則輸入1,退出則輸入0");rflag = sc.nextInt();if (rflag == 0) {System.out.println("游戲結束,歡迎下次再來!");break;}showMenu();// 用戶選擇水果while (true) {System.out.print("*請輸入你要挑選的水果所對應的序號(1~6之間):");theGuess = sc.nextInt();// 水果序號判定if (theGuess >= 1 && theGuess <= 6) {break;} else {System.out.println("*請輸入正確的序號!");}}while (true) {// 用戶投入金幣System.out.print("請選擇要投入的金幣:");bet = sc.nextInt();// 投入金幣數目判定if (bet > 0 && bet <= capmone) {break;} else {System.out.println("*請輸入正確的金幣數目:");}}// 蘋果機結果判定System.out.println("-蘋果機開始轉動了-");System.out.println("-----結果是-----");switch (theSys) {case 1:case 2:case 3:case 4:case 5:case 6:System.out.println("------蘋果------");theSyss = 1;multi = 2;vicOrDef(theGuess, theSyss, bet, multi);break;case 7:case 8:case 9:case 10:case 11:System.out.println("------葡萄------");theSyss = 2;multi = 5;vicOrDef(theGuess, theSyss, bet, multi);break;case 12:case 13:case 14:case 15:System.out.println("------橘子------");theSyss = 3;multi = 10;vicOrDef(theGuess, theSyss, bet, multi);break;case 16:case 17:case 18:System.out.println("------香蕉------");theSyss = 4;multi = 15;vicOrDef(theGuess, theSyss, bet, multi);break;case 19:case 20:System.out.println("------西瓜------");theSyss = 5;multi = 20;vicOrDef(theGuess, theSyss, bet, multi);break;case 21:System.out.println("-----水果拼盤-----");theSyss = 6;multi = 50;vicOrDef(theGuess, theSyss, bet, multi);break;}// 用戶結果處理System.out.println("*當前剩余金幣" + capmone);if (capmone <= 0) {System.out.println("*金幣不足,游戲結束!");break;}}}}總結
以上是生活随笔為你收集整理的Java AppleGame小游戏(第一版)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: kubernetes的Kubectl命令
- 下一篇: java动态时钟_Java实现的动态数字