Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.tanner.starwarsbattles;
- import java.util.Random;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- // This is going to be a game.
- // You can choose an imperial fleet, dark fleet, or
- // rebel fleet.
- // The army will attack the death star, but there will be
- // different outcomes and options depending on what fleet
- // you choose and how many troops you go with.
- // Each army will have different abilities, and a different
- // number of troops.
- // The user can select different options by typing
- // different choices into the console, options being
- // displayed
- // and processed as integers/strings.
- Scanner optionReader = new Scanner(System.in);
- System.out.println("Welcome to Star Wars Battles!");
- System.out.println("In this game, you can choose your fleet, and battle the death star!");
- System.out.println("Each fleet has different abilities.");
- System.out.println("Let's select your fleet!");
- System.out.println("Pick the number of the fleet that you would like to use.");
- System.out.println("1: Imperial Fleet");
- System.out.println("2: Dark Fleet");
- System.out.println("3: Rebel Fleet");
- System.out.println("4: Tell me about each fleet!");
- int fleetChoice = optionReader.nextInt();
- if (fleetChoice == 1) {
- System.out.println("You chose to use the Imperial Fleet.");
- } else if (fleetChoice == 2) {
- System.out.println("You chose to use the Dark Fleet.");
- } else if (fleetChoice == 3) {
- System.out.println("You chose to use the Rebel Fleet.");
- } else if (fleetChoice == 4) {
- System.out.println("Each fleet has different abilities and specifications.");
- System.out.println("The imperial fleet has only 5 troops, but they are very powerful and tanky.");
- System.out.println(
- "The ability of the imperial fleet is a high-powered laser beam, which you can fire every 180 seconds.");
- System.out.println("The dark fleet has 100 troops, but they are not as powerful as the other troops.");
- System.out.println(
- "The ability of the dark fleet is the ability to call on their master-- Darth Vader. Darth Vader is about 5 times more powerful than the entire imperial fleet.");
- System.out.println("You can call on Darth Vader once every 200 seconds.");
- System.out.println("The rebel fleet has 50 troops, each of an average strength.");
- System.out.println(
- "However, there is one special troop in the fleet-- Luke Skywalker! Every 100 seconds, he can activate a super secret ability that will make him as powerful as an imperial fleet soldier for 10 seconds.");
- System.out.println("Do you understand? 1. Yes 2. No");
- Scanner anotherOptionReader = new Scanner(System.in);
- int doYouUnderstand = anotherOptionReader.nextInt();
- if (doYouUnderstand == 1) {
- System.out.print("\033[H\033[2J");
- System.out.flush();
- System.out.println("Great! Now choose your fleet:");
- System.out.println("1: Imperial Fleet");
- System.out.println("2: Dark Fleet");
- System.out.println("3: Rebel Fleet");
- int secondFleetChoice = anotherOptionReader.nextInt();
- if (secondFleetChoice == 1) {
- System.out.println("You have chosen the Imperial Fleet.");
- System.out.println("Would you like to attack the Death star?");
- System.out.println("1: Yes");
- System.out.println("2: No");
- Scanner initiateAttackChoice = new Scanner(System.in);
- int initiateAttackDecision = initiateAttackChoice.nextInt();
- if (initiateAttackDecision == 1) {
- System.out.print("\033[H\033[2J");
- System.out.flush();
- System.out.println("How to attack:");
- System.out.println("First, you must initiate an attack on the ship.");
- System.out.println("To do this, press 1.");
- Scanner attackChoice = new Scanner(System.in);
- int attackDecision = attackChoice.nextInt();
- if (attackDecision == 1) {
- System.out.println("Inflicted 50 damage on the death star! It has 950 health left.");
- System.out.println("Great job, but now it's the death star's turn!");
- System.out.println("I think you got this on your own now, good luck!");
- System.out.println("Press 6 to continue.");
- Scanner continueBattle = new Scanner(System.in);
- int continueInput = continueBattle.nextInt();
- if (continueInput == 6) {
- int deathStarHealth = 950;
- int imperialFleetHealth = 1500;
- while (deathStarHealth > 0 || imperialFleetHealth > 0) {
- if (deathStarHealth <= 0) {
- System.out.flush();
- System.out.println("Congratulations! You have defeated the death star!");
- break;
- } else if (imperialFleetHealth <= 0) {
- System.out.flush();
- System.out.println("Game over! You have been defeated by the death star!");
- break;
- }
- Random rand = new Random();
- int attackID = 1 + rand.nextInt((10 - 1) + 1);
- if (attackID == 1) {
- System.out.println(
- "The death star has fired a powerful laser beam! 100 fleet damage was inficted.");
- imperialFleetHealth = imperialFleetHealth - 100;
- System.out.println("The fleet has " + imperialFleetHealth + " health left.");
- } else if (attackID == 2) {
- System.out.println(
- "The death star has fired an explosive heat-seeking missle! 500 fleet damage was inflicted.");
- imperialFleetHealth = imperialFleetHealth - 500;
- System.out.println("The fleet has " + imperialFleetHealth + " health left.");
- }
- else if (attackID == 3) {
- System.out.println(
- "A soldier aboard the death star taken some shots at your fleet. 200 fleet damage was inflected.");
- imperialFleetHealth = imperialFleetHealth - 200;
- System.out.println("The fleet has " + imperialFleetHealth + " health left.");
- }
- else if (attackID == 4) {
- System.out.println(
- "A group of 100 storm troopers unleashed their lightsabers and attacked your fleet. 300 fleet damage was inflicted.");
- imperialFleetHealth = imperialFleetHealth - 300;
- System.out.println("The fleet has " + imperialFleetHealth + " health left.");
- }
- else if (attackID == 5) {
- System.out.println(
- "Darth Vader has appeared! He attacks! 500 fleet damage has been inflicted.");
- imperialFleetHealth = imperialFleetHealth - 500;
- System.out.println("The fleet has " + imperialFleetHealth + " health left.");
- } else if (attackID == 6) {
- System.out.println(
- "Uh oh! A metorite came in and struck your fleet AND the death star. 200 fleet damage was inflicted, and 100 damage was done to the death star.");
- imperialFleetHealth = imperialFleetHealth - 200;
- deathStarHealth = deathStarHealth - 100;
- System.out.println("Your fleet has " + imperialFleetHealth + " health left.");
- System.out.println("The death star has " + deathStarHealth + " health left.");
- } else if (attackID == 7) {
- System.out.println("");
- }
- else if (attackID == 8) {
- } else if (attackID == 9) {
- }
- else if (attackID == 10) {
- } else {
- System.out.println("Fatal error, shutting down!");
- return;
- }
- System.out.println("What will you choose to do next?");
- System.out.println("1: Attack");
- System.out.println("2: Use Ability");
- System.out.println("3: Surrender");
- System.out.println("4: Check the status of your fleet and the ships.");
- Scanner anotherAttackChoice = new Scanner(System.in);
- int anotherAttackDecision = anotherAttackChoice.nextInt();
- if (anotherAttackDecision == 1) {
- Random attackDMGGen = new Random();
- int attackDMG = 50 + attackDMGGen.nextInt((200 - 50) + 1);
- System.out.println("The attack was successful! " + attackDMG
- + " damage was dealt to the death star.");
- deathStarHealth = deathStarHealth - attackDMG;
- System.out.println("The death star has " + deathStarHealth + " health left.");
- } else if (anotherAttackDecision == 2) {
- } else if (anotherAttackDecision == 3) {
- Scanner areYouSure = new Scanner(System.in);
- System.out.println("Are you sure you want to surrender? Y/N");
- if (areYouSure.nextLine().equalsIgnoreCase("Y")) {
- System.out.println("Activated the getaway ship!");
- break;
- } else if (areYouSure.nextLine().equalsIgnoreCase("N")) {
- System.out.println("Cancelled the getway.");
- }
- } else if (anotherAttackDecision == 4) {
- System.out.println("Your fleet has " + imperialFleetHealth + " health left.");
- System.out.println("The death star has " + deathStarHealth + " health left.");
- }
- }
- }
- }
- else if (initiateAttackDecision == 2) {
- System.out.println("Attack canceled.");
- }
- else {
- System.out.println("Invalid decision.");
- }
- } else if (secondFleetChoice == 2) {
- System.out.println("You have chosen the Dark Fleet.");
- }
- else if (secondFleetChoice == 3) {
- System.out.println("You have chosen the Rebel Fleet.");
- } else {
- System.out.println("Invalid fleet number.");
- }
- }
- } else {
- System.out.println("Invalid fleet number.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement