First.java

/* Class author: Luca 'Syr' Lombardo Created on: 10/10/17 */ import java.util.Objects; import java.util.Scanner; /* LAST UPDATE [Luca 'Syr' Lombardo - 12/10/17]: - Added daily check of Game Over by calling the Stats method dayLimitExceeded in the Game Loop - Corrected a bug that caused an exception if player chose a name with a space in it TO DO: - Comments for variables & methods in class Dice */ public class First { // Main program public static void main(String[] args) { Scanner mainScanner = new Scanner(System.in); Stats player = new Stats("PLAYER_ERROR", -1); String playerName = "PLAYERNAME_ERROR"; int currentDay = -1; int playerMoney = -1; boolean nameLoopConfirm = false; // Control variable. 1 if name has been chosen correctly boolean gameOver = false; // GameLoop main control variable // Print game introduction printIntroduction(); // Loop goes on until name confirmation while (nameLoopConfirm == false) { String nameConfirmAnswer; // Ask for name input System.out.println("Enter your name: "); // Initialize user stats with name input and starting money player = new Stats(mainScanner.nextLine(), 1000); // Get Stats info by calling getters playerName = player.getName(); currentDay = player.getDay(); playerMoney = player.getMoney(); // Ask for name confirmation System.out.println("So, your name is " + playerName + "? Y/N"); nameConfirmAnswer = mainScanner.next(); if (Objects.equals(nameConfirmAnswer.toLowerCase(), "y") || Objects.equals(nameConfirmAnswer.toLowerCase(), "yes")) { nameLoopConfirm = true; } } // GameLoop while (gameOver == false) { int playerActivity = -1; boolean validActivity = false; // Control variable. True if player chose a valid activity // Update stats currentDay = player.getDay(); playerMoney = player.getMoney(); // Print stats System.out.println("Name: " + playerName); System.out.println("Day: " + currentDay); System.out.println("Money: " + playerMoney + "$"); // Choose the activity while (validActivity == false) { System.out.println("\nWhat do you want to do today?" + "\n1 - Play games at the Casino"); playerActivity = mainScanner.nextInt(); // First level switch. A case is an activity (Casino, etc) switch (playerActivity) { // Casino case 1: System.out.println("You're at the Casino. What game do you want to play? \n1 - Roulette\n2 - Dice"); int playerCasinoGame = mainScanner.nextInt(); while (validActivity == false) { // Second level switch. A case is a Casino game (Roulette, etc) switch (playerCasinoGame) { // Play roulette case 1: while (validActivity == false) { System.out.println("You're playing roulette. Choose your bet: \n1 - Single number\n2 - Even or odd"); int playerRouletteBet = mainScanner.nextInt(); Roulette roulette = new Roulette(); // Third level switch. A case is a Roulette Bet (Single Number, etc) switch (playerRouletteBet) { // Single number case 1: roulette.plein(player); validActivity = true; break; // Even or odd case 2: roulette.evenOrOdd(player); validActivity = true; break; // Bad bet default: System.out.println("Error: please choose a valid bet."); break; } } break; // Play dice case 2: Dice dice = new Dice(); dice.playDice(player); validActivity = true; break; // Bad casino game default: System.out.println("Error: please please choose a valid game."); break; } } break; // Bad activity default: System.out.println("Error: please choose a valid activity."); break; } } // A day passed player.setDay(++currentDay); // Check if time is over (last day has passed) gameOver = player.dayLimitExceeded(); } // Print Game Over screen System.out.println("GAME OVER!"); // Close the scanner object along with System.in mainScanner.close(); } // Print game introduction static public void printIntroduction() { System.out.println("*** FROM 0 TO 1 MILLION TO 0 ***\nA.k.a 02M20 Alpha 0.1\nA game by Syr"); System.out.println("Hello and welcome to 02M20! In this game, you're a criminal on an undercover mission: your goal is to gain your fake boss's trust\n" + "by earning him a million dollars, and then losing everything. Why? Because your real boss gave you this order, that's why." + "\nYou have 30 days. Good luck!"); } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.