Advertisement
Guest User

Fruitmachine model

a guest
Dec 10th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. import java.util.Random;
  2.  
  3. public class fruitMachineModel {
  4.  
  5. public static void spin(gameBalance game) { // spin initiates random card generation.
  6. Random randle = new Random();
  7. String card = "";
  8. String cardOne = "";
  9. String cardTwo = "";
  10. String cardThree = "";
  11. for (int i = 1; i<=3; i++ ) {
  12. int word = randle.nextInt(4);
  13. if (word == 0) {
  14. card = "Joker";
  15. } else if (word == 1) {
  16. card = "Queen";
  17. } else if (word == 2) {
  18. card = "King";
  19. } else if(word == 3) {
  20. card = "Ace";
  21. }
  22. if (i == 1) { // with each iteration of loop store new randomly generated card in a separate string
  23. cardOne = card;
  24. } else if (i == 2) {
  25. cardTwo = card;
  26. } else if( i == 3) {
  27. cardThree = card;
  28. }
  29. }
  30. String outPut = cardOne + cardTwo + cardThree;
  31. System.out.println(outPut);
  32. scoreCalc(cardOne, cardTwo, cardThree, game);
  33. }
  34.  
  35. private static void scoreCalc(String cardOne, String cardTwo, String cardThree, gameBalance game) {
  36.  
  37. if (((cardOne.equals("Joker")) && (cardTwo.equals("Joker")) && (cardThree.equals("Joker")))) {
  38. game.withdraw(75, game);
  39. System.out.println("-75 points \n" + game.getBalance());
  40.  
  41. // 3x joker deduct 75 points from game balance
  42.  
  43. } else if ((( cardOne.equals("Joker")) && (cardTwo.equals("Joker"))) ||
  44. ( ( cardOne.equals("Joker")) && (cardThree.equals("Joker"))) ||
  45. ( ( cardTwo.equals("Joker") && (cardThree.equals("Joker"))))) {
  46. game.withdraw(50, game);
  47. System.out.println(" -50 points \n" + game.getBalance());
  48. // 2x joker deduct 50 points from game balance
  49.  
  50. } else if ( ( cardOne.equals("Joker")) || (cardTwo.equals("Joker")) || (cardThree.equals("Joker")) ) {
  51. game.withdraw(25, game);
  52. System.out.println( "-25 points \n" + game.getBalance());
  53. // 1 x Joker deduct 25 points from game balance
  54.  
  55. }else if (( cardOne != cardTwo ) && (cardOne != cardThree) && ( cardTwo != cardThree )) {
  56. System.out.println("you lose nothing, your balance remains " + game.getBalance());
  57. // all cards different no deductions from game balance
  58.  
  59. } else if ( ( ( cardOne == cardTwo) && (cardOne != cardThree) ) ||
  60. ( ( cardOne == cardThree) && (cardOne != cardTwo) ) ||
  61. ( ( cardTwo == cardThree) && (cardTwo != cardOne) ) ){
  62. game.deposit(20, game);
  63. System.out.println( "+20 points \n" + game.getBalance());
  64. // two of a kind +20 points to game balance
  65.  
  66. } else {
  67. game.deposit(50, game);
  68. System.out.println("+50 points \n" + game.getBalance());
  69. // 3 of a king + 50 points to game balance
  70. }
  71.  
  72. }
  73.  
  74.  
  75.  
  76.  
  77.  
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement