import java.awt.*; import java.awt.event.*; /** * Models a human player in the game */ public class Humans extends Players { final String FISH_MSG="Go Fish! \n"; /** * Constructor for a human player */ public Humans(String name, goFish MyGame, String FishMsg) { super(name,MyGame,FishMsg); } /** * The player takes a turn (displays the current hand) */ public void takeTurn() { // Display the current hand before letting the player move String CurrentHand = MyHand.Show(); Game.PlayerHand.setText(CurrentHand); // Display my current hand } /** * Handle a keypress */ public void keyDown( int key) { char UserInput = (char) key; // convert integer key to a char Cards CardDesired = new Cards('A'); try { CardDesired.Set(UserInput); if(MyHand.HowMany(CardDesired) == 0) { Game.Commentary.append("you can only request cards you have.\n"); } else if(MakeMove( UserInput ) == true) // let the human player move { // player gets to move again, // so display current hand String CurrentHand = MyHand.Show(); Game.PlayerHand.setText(CurrentHand); } else Game.nextPlayer(); // TBD: hand doesn't get refreshed if human wins } catch (OutOfRangeException e) { Game.Commentary.append("Valid card symbols are " + Cards.CardSymbols + "\n"); } } public void keyPressed(KeyEvent e) {;} public void keyReleased (KeyEvent e) {;} } // end class