Jade Bird Mini Game Platform Development
1. Choose the game ----- switch to choose the structure
public class Test { public static void main (String [] args) { System.out.println ("Welcome to the Jade Bird Tour Mini-Play Platform"); Scanner input = new Scanner (System.in); System.out.println (" \ nPlease choose your favorite game: \ n "); System.out.println (" * * * * * * * * * * * * * * * * * * * * * * * "); System.out.println ("1. Fight the landlord"); System.out.println ("2. Bullfighting"); System.out.println ("3. Bubble Dragon"); System.out.println ("4. Lianliankan") ; System.out.println ("* * * * * * * * * * * * * * * * * * * * * *"); System.out.print ("\ nPlease select, enter the number:"); int num = input.nextInt (); switch (num) { case 1: System.out.println ("You have entered the fighting room!"); Break; case 2: System.out.println ("You have entered the fighting room!"); Break; case 3: System.out.println (" You have entered the bubble dragon room! "); Break; case 4: System.out.println (" You have entered the Lianliankan room! "); Break; case 5: main (args); break; default: System.out .println ("Sorry, your input is incorrect"); break; } } }
2. Play games and advance -------- multiple if / break
public class Jinji { public static void main (String [] args) { Scanner input = new Scanner (System.in); int n = 1; int count = 0; // count int score = 0; // Game score String answer ; System.out.println ("Bluebird Mini Game Platform> Game Advancement \ n"); do { System.out.print ("You are playing the first" + n + "inning, the score is:"); score = input. nextInt (); // Enter the game score if (score> 80) {// Count the number of rounds with 80 points or more count ++; } n ++; if (n> 5) { System.out.println ("Game Over") ;; } else { System.out.print ("Will you continue to the next game? (Yes / no)"); answer = input.next (); if (answer.equals ("no")) { System.out.println ("You Has exited the game halfway "); break; } else { System.out.println (" Enter the next round "); } } } while (n <= 5); double rate = count / 5.0; // count reaches 80 points The above ratio if (n> 5) { if (rate> 0.8) { System.out.println ("\ nCongratulations pass the first level"); } else if (rate> 0.6) { System.out.println ("\ nThrough the second level, continue to work hard! "); } else { System.out.println ("\ nSorry, you failed to advance, continue to cheer!"); } } else { System.out.println ("\ nSorry, you failed to advance, continue to cheer! "); } } }
3. Play games and pay game coins ---- if structure, continue statement
public class Count { public static void main (String [] args) { System.out.println ("Bluebird mini game platform> game currency payment"); Scanner input = new Scanner (System.in); System.out.println ( "Please choose the type of game you are playing:"); System.out.println ("1. Card Type"); System.out.println ("2. Leisure Sports"); int num = input.nextInt (); System.out.println ("Please enter the length of your game:"); int time = input.nextInt (); switch (num) { case 1: if (time> 10) { System.out.println ("You played It is a card game, the duration is: "+ time +" hour, you can enjoy 50% discount, you need to pay "+ (0.5 * time * 10) +" game currency "); } else { System.out.println ("You are playing a card game, the duration is:" + time + "hour, you can enjoy 20% discount, you need to pay" + (0.8 * time * 10) + "game currency") ; } break; case 2: if (time <= 10) { System.out.println ("You are playing a casual sports game, the duration is:" + time + "hour, you can enjoy 20% discount, you need to pay "+ (0.8 * time * 20) +" game currency "); } else { System.out.println (" You are playing a casual sports game, the duration is: "+ time +" hour, you can enjoy 50% off For discounts, you need to pay "+ (0.5 * time * 20) +" game currency "); } break; } System.out.println (" Game Over "); } }
4. Add user information
public class User { public static void main (String [] args) { System.out.println ("Bluebird Mini Game Platform> Add User Information \ n"); int zs; // integer int age; // age int score; // Point Scanner input = new Scanner (System.in); System.out.println ("Please enter the number of users to be entered` :"); int count = input.nextInt (); for (int i = 0; i <count; i ++) { System.out.println ("Please enter the user number (<4-digit integer>):"); zs = input.nextInt (); if (zs <= 9999 && zs> = 1000) { } else { System.out.println ("wrong input"); continue; } System.out.println ("Please enter the user's age:"); age = input.nextInt (); if (age <= 10 || age> 100) { System.out.println ("Sorry, your age is not suitable for playing games"); System.out.println ("Enter information Fail \ n "); continue; } System.out.println (" Please enter membership points: "); score = input.nextInt (); System.out.println (" The member information you entered is: \ n ") ; System.out.println ("User ID:" + zs + "Age:" + age
+ "Points:" + score + "\ n"); } } }
Note : Flexible use of continue and break