Advertisement
TooFewSecrets

Terrible W&A Calculator

Jun 11th, 2020
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.22 KB | None | 0 0
  1. import java.util.Random;
  2.  
  3. public class EscapeChance {
  4.         static String[] SUITS = {
  5.             "Clubs", "Diamonds", "Hearts", "Spades"
  6.         };
  7.  
  8.         static String[] RANKS = {
  9.             "2", "3", "4", "5", "6", "7", "8", "9", "10",
  10.             "Jack", "Queen", "King", "Ace"
  11.         };
  12.         static String[] deck = new String[52];
  13.  
  14.         // initialize deck
  15.         public static void createDeck() {
  16.         for (int i = 0; i < RANKS.length; i++) {
  17.             for (int j = 0; j < SUITS.length; j++) {
  18.                 deck[SUITS.length*i + j] = RANKS[i] + " of " + SUITS[j];
  19.             }
  20.         }
  21.         }
  22.  
  23.         // shuffle
  24.         public static void shuffleDeck() {
  25.         for (int i = 0; i < 52; i++) {
  26.             int r = i + (int) (Math.random() * (52-i));
  27.             String temp = deck[r];
  28.             deck[r] = deck[i];
  29.             deck[i] = temp;
  30.             }
  31.         }
  32.        
  33.         public static int rollDice() {
  34.             Random random = new Random();
  35.             int rand = 0;
  36.             rand = random.nextInt(5)+1;
  37.             return rand;
  38.         }
  39.  
  40.  
  41.     public static void main (String [] args) {
  42.         boolean winner = false;
  43.         int attempts = 0;
  44.         int deathTimer = 0;
  45.         int evacTickets = 10;
  46.         int turnsRemaining = 0;
  47.         int evacChance = 0;
  48.         int turnActivated = 0;
  49.         int turnBoosted = 0;
  50.         int turnCount = 0;
  51.         int evacStarted = 0;
  52.         int boosterOn = 0;
  53.         createDeck();
  54.         while (winner == false) {
  55.             shuffleDeck();
  56.             for (int i = 0; i < 52; i++){
  57.                 if (turnsRemaining == 0) {
  58.                     turnsRemaining = rollDice();
  59.                     turnCount++;
  60.                 }
  61.                 turnsRemaining--;
  62.                     if ("Ace of Hearts".equals(deck[i])) {
  63.                         evacStarted = 1;
  64.                         turnActivated = turnCount;
  65.                     }
  66.                     else if ("King of Hearts".equals(deck[i])) {
  67.                         deathTimer++;
  68.                     }
  69.                     else if ("King of Spades".equals(deck[i])) {
  70.                         deathTimer++;
  71.                     }
  72.                     else if ("King of Aces".equals(deck[i])) {
  73.                         deathTimer++;
  74.                     }
  75.                     else if ("King of Diamonds".equals(deck[i])) {
  76.                         deathTimer++;
  77.                     }
  78.                     else if ("Ace of Diamonds".equals(deck[i])){
  79.                         boosterOn = 1;
  80.                         turnBoosted = turnCount;
  81.                     }
  82.                     else if ("Two of Clubs".equals(deck[i])){
  83.                         turnsRemaining = 0;
  84.                     }
  85.                    
  86.                 if (deathTimer == 4) {
  87.                     break;
  88.                 }
  89.                 if (evacStarted == 1 && turnsRemaining == 0) {
  90.                     evacChance = rollDice();
  91.                     if (boosterOn == 1 && evacChance >= 5){
  92.                             evacTickets--;
  93.                     }
  94.                     else if (evacChance == 6){
  95.                             evacTickets--;
  96.                         }
  97.                     }
  98.  
  99.             if (evacTickets == 0){
  100.                 System.out.println("Escape successful! It took this many attempts to survive:");
  101.                 System.out.println(attempts);
  102.                 System.out.println("There were this many cards remaining:");
  103.                 System.out.println(52-i);
  104.                 System.out.println("The beacon was drawn on this turn:");
  105.                 System.out.println(turnActivated);
  106.                 System.out.println("And the beacon was boosted on this turn:");
  107.                 System.out.println(turnBoosted);
  108.                 System.out.println("It took this many turns:");
  109.                 System.out.println(turnCount);
  110.                 winner = true;
  111.                 break;
  112.             }
  113.         }
  114.         attempts++;
  115.         evacStarted = 0;
  116.         boosterOn = 0;
  117.         evacTickets = 10;
  118.         deathTimer = 0;
  119.         turnActivated = 100;
  120.         turnBoosted = 100;
  121.         turnCount = 0;
  122.         turnsRemaining = 0;
  123.     }
  124.  
  125.     }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement