Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Full House help?

  1. #1
    Member
    Join Date
    Aug 2012
    Posts
    67
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Full House help?

    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.


  2. #2
    Junior Member
    Join Date
    Nov 2012
    Location
    Germany
    Posts
    20
    My Mood
    Bored
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: Full House help?

    The problem in the if-statement is that it fails, when the cards are not in order.
    e.g. AAAKK but not AAKAK

    You could solve this problem by checking three cards with the same number first
    and then check if the two other cards have also the same number.
    If not you can handle it as three of a kind.

Similar Threads

  1. Having problems with Queues, any help ad I would be great full!
    By sim18 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 25th, 2012, 04:09 PM
  2. Drawing in Full Screen
    By MizukiTHPS in forum AWT / Java Swing
    Replies: 7
    Last Post: March 27th, 2012, 11:48 AM
  3. Full Window when run the program.
    By faysal40 in forum AWT / Java Swing
    Replies: 1
    Last Post: May 12th, 2011, 11:37 PM