Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- public class EscapeChance {
- static String[] SUITS = {
- "Clubs", "Diamonds", "Hearts", "Spades"
- };
- static String[] RANKS = {
- "2", "3", "4", "5", "6", "7", "8", "9", "10",
- "Jack", "Queen", "King", "Ace"
- };
- static String[] deck = new String[52];
- // initialize deck
- public static void createDeck() {
- for (int i = 0; i < RANKS.length; i++) {
- for (int j = 0; j < SUITS.length; j++) {
- deck[SUITS.length*i + j] = RANKS[i] + " of " + SUITS[j];
- }
- }
- }
- // shuffle
- public static void shuffleDeck() {
- for (int i = 0; i < 52; i++) {
- int r = i + (int) (Math.random() * (52-i));
- String temp = deck[r];
- deck[r] = deck[i];
- deck[i] = temp;
- }
- }
- public static int rollDice() {
- Random random = new Random();
- int rand = 0;
- rand = random.nextInt(5)+1;
- return rand;
- }
- public static void main (String [] args) {
- boolean winner = false;
- int attempts = 0;
- int deathTimer = 0;
- int evacTickets = 10;
- int turnsRemaining = 0;
- int evacChance = 0;
- int turnActivated = 0;
- int turnBoosted = 0;
- int turnCount = 0;
- int evacStarted = 0;
- int boosterOn = 0;
- createDeck();
- while (winner == false) {
- shuffleDeck();
- for (int i = 0; i < 52; i++){
- if (turnsRemaining == 0) {
- turnsRemaining = rollDice();
- turnCount++;
- }
- turnsRemaining--;
- if ("Ace of Hearts".equals(deck[i])) {
- evacStarted = 1;
- turnActivated = turnCount;
- }
- else if ("King of Hearts".equals(deck[i])) {
- deathTimer++;
- }
- else if ("King of Spades".equals(deck[i])) {
- deathTimer++;
- }
- else if ("King of Aces".equals(deck[i])) {
- deathTimer++;
- }
- else if ("King of Diamonds".equals(deck[i])) {
- deathTimer++;
- }
- else if ("Ace of Diamonds".equals(deck[i])){
- boosterOn = 1;
- turnBoosted = turnCount;
- }
- else if ("Two of Clubs".equals(deck[i])){
- turnsRemaining = 0;
- }
- if (deathTimer == 4) {
- break;
- }
- if (evacStarted == 1 && turnsRemaining == 0) {
- evacChance = rollDice();
- if (boosterOn == 1 && evacChance >= 5){
- evacTickets--;
- }
- else if (evacChance == 6){
- evacTickets--;
- }
- }
- if (evacTickets == 0){
- System.out.println("Escape successful! It took this many attempts to survive:");
- System.out.println(attempts);
- System.out.println("There were this many cards remaining:");
- System.out.println(52-i);
- System.out.println("The beacon was drawn on this turn:");
- System.out.println(turnActivated);
- System.out.println("And the beacon was boosted on this turn:");
- System.out.println(turnBoosted);
- System.out.println("It took this many turns:");
- System.out.println(turnCount);
- winner = true;
- break;
- }
- }
- attempts++;
- evacStarted = 0;
- boosterOn = 0;
- evacTickets = 10;
- deathTimer = 0;
- turnActivated = 100;
- turnBoosted = 100;
- turnCount = 0;
- turnsRemaining = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement