import java.awt.*; import Deck; import Card; import Player; import BuildStack; /* The hand is simply an array of cards. Count is the number of cards currently in the hand. */ public class Hand { private int index, size, count; private Card hand []; public Hand (int s) { int i; size = s; hand = new Card [size]; for (i = 0; i < size; i++) { hand[i] = new Card (); } index = size - 1; } public boolean isEmpty () { return (count == 0); } public void getHandValues (int g[]) /* Function: Adds the use values of each card into the gamestate array. Returns: Updated gamestate array. */ { int i; for (i=0; i< size; i++) g[i+4] = hand[i].showUseValue(); } public Card getCard (int index) /* function: remove the card from the player's hand and replace with a null card ( a card with a value of 0 ). Decrements a count of the number of cards in the hand. */ { Card temp = new Card (); temp.setUseValue(hand[index].showUseValue()); hand[index].setUseValue(0); count--; return temp; } public boolean addCard (Card c) /* function: places a card into the first empty spot in the hand array. If the hand is full then in returns false. Returns true and increments the hand count when the operation is successful. */ { int i = 0; boolean emptyspot = false; while (i < size && emptyspot == false) { if (hand[i].showUseValue() == 0) emptyspot = true; i++; } if (emptyspot) { hand[--i] = c; count++; return true; } else return false; } public boolean addCard (Card c, int index) /* function: places a card into the array slot indicated. If the hand is full then in returns false. Returns true and increments the hand count when the operation is successful. */ { hand[index] = c; count++; return true; } public boolean fillHand (Deck d) /* function: fills each empty slot in the hand array. An empty slot is marked by a card with a use value of 0. */ { int i; for (i = 0; i < size; i++) { if (d.isEmpty()) return false; else { if (hand[i].showUseValue() == 0) { hand[i] = d.Deal (); } } } count = size; index = size - 1; return true; } public boolean fillHand (Deck d, int handsize) /* function: fills each empty slot in the hand array. An empty slot is marked by a card with a use value of 0. This version allows from size of the hand to be changed. */ { int i; for (i = 0; i < handsize; i++) { if (hand[i].showUseValue() == 0) { hand[i] = d.Deal (); } } count = handsize; index = handsize - 1; return true; } }