Guest User

Untitled

a guest
Oct 20th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. package gamecomponents;
  2.  
  3. import gamecomponents.Card;
  4. import gamecomponents.Deck;
  5.  
  6. public class GameLogic {
  7. protected Deck deck;
  8. protected int psum;
  9. protected int dsum;
  10. protected int dealeraces;
  11. protected int playeraces;
  12.  
  13.  
  14. public GameLogic() {
  15. // Initialize deck, sum and aces.
  16. deck = new Deck();
  17. psum = 0;
  18. dsum = 0;
  19. dealeraces = 0;
  20. playeraces = 0;
  21.  
  22. //Shuffle the deck
  23. deck.shuffle();
  24. }
  25.  
  26. public Card drawdealer() {
  27.  
  28. // Draw a card from the deck
  29. Card dealer_drawn_card = deck.draw();
  30.  
  31. // Calculate the value to add to sum
  32. int dealervalue = dealer_drawn_card.rank().value();
  33.  
  34. //Set the value of a jack,queen and king to 10
  35. if (dealervalue > 10) {
  36. dealervalue = 10;
  37. }
  38.  
  39. //Code for the ace value
  40. if (dealervalue == 1) {
  41. dealervalue = 11;
  42. // If the card is an ace, increase the count of aces.
  43. dealeraces++;
  44. }
  45.  
  46. //Adds the rank of the card to sum
  47. dsum = dsum + dealervalue;
  48.  
  49. // Return the card that was drawn.
  50. return dealer_drawn_card;
  51.  
  52. }
  53.  
  54. public Card drawplayer() {
  55.  
  56. // Draw a card from the deck
  57. Card player_drawn_card = deck.draw();
  58.  
  59. // Calculate the value to add to sum
  60. int playervalue = player_drawn_card.rank().value();
  61.  
  62. //Set the value of a jack,queen and king to 10
  63. if (playervalue > 10) {
  64. playervalue = 10;
  65. }
  66.  
  67. //Code for the ace value
  68. if (playervalue == 1) {
  69. playervalue = 11;
  70. // If the card is an ace, increase the count of aces.
  71. playeraces++;
  72. }
  73.  
  74. //Adds the rank of the card to sum
  75. psum = psum + playervalue;
  76.  
  77. // Return the card that was drawn.
  78. return player_drawn_card;
  79.  
  80. }
  81.  
  82. public int psum() {
  83. // Getter for sum.
  84. return psum;
  85. }
  86.  
  87. public int dsum() {
  88. // Getter for sum.
  89. return dsum;
  90. }
  91. }
Add Comment
Please, Sign In to add comment