Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package gamecomponents;
- import gamecomponents.Card;
- import gamecomponents.Deck;
- public class GameLogic {
- protected Deck deck;
- protected int psum;
- protected int dsum;
- protected int dealeraces;
- protected int playeraces;
- public GameLogic() {
- // Initialize deck, sum and aces.
- deck = new Deck();
- psum = 0;
- dsum = 0;
- dealeraces = 0;
- playeraces = 0;
- //Shuffle the deck
- deck.shuffle();
- }
- public Card drawdealer() {
- // Draw a card from the deck
- Card dealer_drawn_card = deck.draw();
- // Calculate the value to add to sum
- int dealervalue = dealer_drawn_card.rank().value();
- //Set the value of a jack,queen and king to 10
- if (dealervalue > 10) {
- dealervalue = 10;
- }
- //Code for the ace value
- if (dealervalue == 1) {
- dealervalue = 11;
- // If the card is an ace, increase the count of aces.
- dealeraces++;
- }
- //Adds the rank of the card to sum
- dsum = dsum + dealervalue;
- // Return the card that was drawn.
- return dealer_drawn_card;
- }
- public Card drawplayer() {
- // Draw a card from the deck
- Card player_drawn_card = deck.draw();
- // Calculate the value to add to sum
- int playervalue = player_drawn_card.rank().value();
- //Set the value of a jack,queen and king to 10
- if (playervalue > 10) {
- playervalue = 10;
- }
- //Code for the ace value
- if (playervalue == 1) {
- playervalue = 11;
- // If the card is an ace, increase the count of aces.
- playeraces++;
- }
- //Adds the rank of the card to sum
- psum = psum + playervalue;
- // Return the card that was drawn.
- return player_drawn_card;
- }
- public int psum() {
- // Getter for sum.
- return psum;
- }
- public int dsum() {
- // Getter for sum.
- return dsum;
- }
- }
Add Comment
Please, Sign In to add comment