Hello!
I am trying to create a model class of a Crazy Eights game that uses abstraction from a Player class. The model follows these rules:
1. The game starts with each player being given some number of cards from the deck.
2. A single card is taken from the deck and placed on top of the discard pile (and is visible to the player).
3. A player's turn consists of taking zero or more cards from the deck (adding them to their hand) and then playing a card on the top of the discard pile (removing it from their hand).
4. A player can always play a card from their hand that has the same rank as the top card in the discard pile.
5. A player can always play a card from their hand that has the same suit as the top card in the discard pile.
6. A player can always play a card with rank 8. When a player plays an 8, they are allowed to change the suit of the card to any of the four suits of their choosing. (You will do this by removing the eight from your hand and then returning a new Card object with the desired suit.)
7. A player is allowed to (repeatedly) take a card from the deck before playing a card to the discard pile. You must play a card if you are able to. If the deck runs out of cards, the game ends.
8. The player that discards all their cards first is the winner. If the deck is exhausted before any player can play all their cards then there is no winner.
9. You are NOT implementing a crazy eights game. You are building the classes that would be needed for such a game. You are building the model for the game.
10. Player should NOT be "able to cheat" in the play method.
public abstract class Player{
protected Hand hand;
public Player(Hand hand){ this.hand = hand; }
public abstract Card play(Card top_of_discard_pile, Deck deck);
public final int cardsLeft(){ return this.hand.numberOfCards(); }
}
public class CrazyEightsPlayer extends Player {
public CrazyEightsPlayer(Hand hand) {
super(hand);
}
@Override
public Card play(Card top_of_discard_pile, Deck deck) {
while ((deck != null) && hand != null) {
if ( ){
} else {
}
}
return ;
}
}
What I have tried:
I have just done a lot of typing and backspacing, inputting a bunch of different things to try to make it work. I am new to coding so I struggle a lot trying to come up with ways to make things work >.<
Please help!