Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- public class fruitMachineModel {
- public static void spin(gameBalance game) { // spin initiates random card generation.
- Random randle = new Random();
- String card = "";
- String cardOne = "";
- String cardTwo = "";
- String cardThree = "";
- for (int i = 1; i<=3; i++ ) {
- int word = randle.nextInt(4);
- if (word == 0) {
- card = "Joker";
- } else if (word == 1) {
- card = "Queen";
- } else if (word == 2) {
- card = "King";
- } else if(word == 3) {
- card = "Ace";
- }
- if (i == 1) { // with each iteration of loop store new randomly generated card in a separate string
- cardOne = card;
- } else if (i == 2) {
- cardTwo = card;
- } else if( i == 3) {
- cardThree = card;
- }
- }
- String outPut = cardOne + cardTwo + cardThree;
- System.out.println(outPut);
- scoreCalc(cardOne, cardTwo, cardThree, game);
- }
- private static void scoreCalc(String cardOne, String cardTwo, String cardThree, gameBalance game) {
- if (((cardOne.equals("Joker")) && (cardTwo.equals("Joker")) && (cardThree.equals("Joker")))) {
- game.withdraw(75, game);
- System.out.println("-75 points \n" + game.getBalance());
- // 3x joker deduct 75 points from game balance
- } else if ((( cardOne.equals("Joker")) && (cardTwo.equals("Joker"))) ||
- ( ( cardOne.equals("Joker")) && (cardThree.equals("Joker"))) ||
- ( ( cardTwo.equals("Joker") && (cardThree.equals("Joker"))))) {
- game.withdraw(50, game);
- System.out.println(" -50 points \n" + game.getBalance());
- // 2x joker deduct 50 points from game balance
- } else if ( ( cardOne.equals("Joker")) || (cardTwo.equals("Joker")) || (cardThree.equals("Joker")) ) {
- game.withdraw(25, game);
- System.out.println( "-25 points \n" + game.getBalance());
- // 1 x Joker deduct 25 points from game balance
- }else if (( cardOne != cardTwo ) && (cardOne != cardThree) && ( cardTwo != cardThree )) {
- System.out.println("you lose nothing, your balance remains " + game.getBalance());
- // all cards different no deductions from game balance
- } else if ( ( ( cardOne == cardTwo) && (cardOne != cardThree) ) ||
- ( ( cardOne == cardThree) && (cardOne != cardTwo) ) ||
- ( ( cardTwo == cardThree) && (cardTwo != cardOne) ) ){
- game.deposit(20, game);
- System.out.println( "+20 points \n" + game.getBalance());
- // two of a kind +20 points to game balance
- } else {
- game.deposit(50, game);
- System.out.println("+50 points \n" + game.getBalance());
- // 3 of a king + 50 points to game balance
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement