Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package tom;
- import javax.swing.*;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
- import java.util.Random;
- public class BettingManager {
- // This gets the variable
- private static JFrame jFrame = new JFrame();
- // JFrame displays a graphical window for the user
- private static List<bettingPlayer> bettingPlayers = new ArrayList<>();
- // This creates an Array list for the bettingPlayer class
- private static List<bet> bets = new ArrayList<>();
- // This creates an Array list for the bet class
- private static String[] options = {
- "Bet Under",
- "Bet Seven",
- "Bet Over",
- "Go back"};
- // This lists all the options for the available bets
- public static void main(String[] args)
- {
- openName();
- }
- private static void openName()
- {
- String name = JOptionPane.showInputDialog(jFrame, "Enter your name");
- // This displays the enter your name message
- bettingPlayer bettingPlayer = getBettingPlayer(name);
- // This gets the players name
- openOption(bettingPlayer);
- }
- private static void openOption(bettingPlayer bettingPlayer)
- {
- int option = JOptionPane.showOptionDialog(jFrame, "Hello " + bettingPlayer.getName() + ". You have " + bettingPlayer.getTriesLeft() + " tries left and $" + bettingPlayer.getMoney() + ".",
- // This displays the message the main screen message that contains their name and how much money they have left and how many tries
- null,
- JOptionPane.YES_NO_CANCEL_OPTION,
- JOptionPane.QUESTION_MESSAGE,
- null,
- options,
- options[3]);
- if (option == 3)
- {
- openName();
- } else
- {
- openBetAmount(bettingPlayer, option);
- }
- }
- private static void openBetAmount(bettingPlayer bettingPlayer, int option)
- {
- String value = JOptionPane.showInputDialog("How much do you want to bet?");
- // This displays the message asking the player how much do they want to bet
- if (value == null)
- {
- openOption(bettingPlayer);
- // End of if statement
- } else
- {
- int amount = Integer.parseInt(value);
- if (amount > bettingPlayer.getMoney())
- // End of if statement
- //
- {
- JOptionPane.showMessageDialog(jFrame,
- "You only have $" + bettingPlayer.getMoney(),
- "Error",
- JOptionPane.ERROR_MESSAGE);
- openBetAmount(bettingPlayer, option);
- // End of if statement
- } else
- {
- runBet(bettingPlayer, option, amount);
- }
- }
- }
- private static void runBet(bettingPlayer bettingPlayer, int option, int amount)
- {
- bet bet = new bet(bettingPlayer.getName(), amount);
- bets.add(bet);
- // This will run a new bet
- int roll = bet.rollDice();
- // This will roll the dice for the new bet
- if (option == getConditionID(roll))
- {
- int amountWon = 0;
- if (option == 0)
- {
- // End of the if statement
- amountWon = bet.getBetAmount() * 2;
- // Times the amount won from the bet by 2
- } else if (option == 1)
- {
- // End of the if else statement
- amountWon = bet.getBetAmount() * 5;
- // Times the amount won from the bet by 5
- } else if (option == 2)
- {
- amountWon = bet.getBetAmount() * 2;
- // Times the amount won from the bet by 2
- }
- // End of the if else statement
- JOptionPane.showMessageDialog(jFrame,
- "Computer rolled " + roll + ". You won $" + amountWon,
- "Congratulations",
- JOptionPane.PLAIN_MESSAGE);
- bettingPlayer.setMoney(bettingPlayer.getMoney() + amount);
- } else
- {
- JOptionPane.showMessageDialog(jFrame,
- "Computer rolled " + roll + ". You lost!",
- "Better luck next time!",
- JOptionPane.PLAIN_MESSAGE);
- bettingPlayer.setMoney(bettingPlayer.getMoney() - bet.getBetAmount());
- }
- bettingPlayer.setTriesLeft(bettingPlayer.getTriesLeft() - 1);
- // End of else statement
- if (bettingPlayer.getTriesLeft() == 0)
- {
- JOptionPane.showMessageDialog(jFrame,
- "You have no more tries! You have a total of $" + bettingPlayer.getMoney(),
- "Finished",
- JOptionPane.PLAIN_MESSAGE);
- // End of if statement
- } else
- {
- openOption(bettingPlayer);
- }
- }
- private static bettingPlayer getBettingPlayer(String name)
- {
- for (bettingPlayer bettingPlayer : bettingPlayers)
- {
- if (bettingPlayer.getName().equalsIgnoreCase(name))
- {
- return bettingPlayer;
- }
- }
- bettingPlayer bettingPlayer = new bettingPlayer();
- bettingPlayers.add(bettingPlayer);
- return bettingPlayer;
- }
- private static int getConditionID(int roll)
- {
- if (roll < 7)
- {
- // This is the if statement for if the roll is under 7
- return 0;
- } else if (roll == 7)
- // This is the if statement for if the roll is equal to 7
- {
- return 1;
- } else
- {
- return 2;
- }
- }
- }
- // This is the end of the class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement