Okay, so I got this code for a "Poker Memory" game where I flip the cards and if I get a pair, I get points, and if I get Three of a Kind, I get points as well, etc.
This one gives points when I flip three cards of the same number:
protected boolean addToTurnedCardsBuffer(Card card) { // add the card to the list this.turnedCardsBuffer.add(card); if(this.turnedCardsBuffer.size() == getCardsToTurnUp()) { // We are uncovering the last card in this turn // Record the player's turn this.turnsTakenCounter.increment(); // get the other card (which was already turned up) Card otherCard1 = (Card) this.turnedCardsBuffer.get(0); Card otherCard2 = (Card) this.turnedCardsBuffer.get(1); if((card.getRank().equals(otherCard1.getRank())) && (card.getRank().equals(otherCard2.getRank()))) { // Three cards match, so remove them from the list (they will remain face up) this.turnedCardsBuffer.clear(); } else { // The cards do not match, so start the timer to turn them down this.turnDownTimer.start(); } } return true; }
Now, my question is, how do I modify this code so that I can get a Full House? (Three of the same, plus two more of another). I already worked on the being able to flip 5 cards part, but when I got a full house I didn't get all the points. Here are the modifications I made:
protected boolean addToTurnedCardsBuffer(Card card) { // add the card to the list this.turnedCardsBuffer.add(card); if(this.turnedCardsBuffer.size() == getCardsToTurnUp()) { // We are uncovering the last card in this turn // Record the player's turn this.turnsTakenCounter.increment(); // get the other card (which was already turned up) Card otherCard1 = (Card) this.turnedCardsBuffer.get(0); Card otherCard2 = (Card) this.turnedCardsBuffer.get(1); Card otherCard3 = (Card) this.turnedCardsBuffer.get(2); Card otherCard4 = (Card) this.turnedCardsBuffer.get(3); if((card.getRank().equals(otherCard1.getRank())) && (card.getRank().equals(otherCard2.getRank())) && (otherCard3.getRank().equals(otherCard4.getRank())) ) { // Three cards match, so remove them from the list (they will remain face up) this.turnedCardsBuffer.clear(); } else { // The cards do not match, so start the timer to turn them down this.turnDownTimer.start(); } } return true; }
This one did not work. I guess it might be because I need to put the 2 other cards INSIDE the if. Any hints or help would be appreciated. Thanks a lot.