Player.java - package game public class Player protected static int playerCount = 0 private Hand hand private int myPlayerId public Player

Player.java - package game public class Player protected...

This preview shows page 1 - 2 out of 2 pages.

package game; public class Player { protected static int playerCount = 0; private Hand hand; private int myPlayerId; public Player() { Player.playerCount += 1; this.myPlayerId = Player.playerCount; } public String getPlayerName() { return "Player " + Integer.toString(this.myPlayerId); } public void setPlayerHand(Hand hand) { this.hand = hand; } public Hand getPLayerHand() { return this.hand; } public Card playNextCard(Deck deck, Card lastCard, boolean anyCard) { Card myCard = new Card(); if (anyCard == false) { int cardId = this.hand.getMatchingCard(lastCard); if (cardId> - 1) { myCard = this.hand.getCard(cardId); this.hand.playCard(myCard); return myCard; } boolean matchFound = false; while (matchFound == false) { this.drawCard(deck,1); System.out.println(this.getPlayerName() + "draws a card"); cardId = this.hand.getMatchingCard(lastCard); if (cardId > -1) { myCard = this.hand.getCard(cardId); matchFound = true; } } } else {
Image of page 1
Image of page 2

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture