Howdy! I am new to java and am currently trying to complete a java assignment given to me to create a poker game with two players each given five cards in the form of two arrays of buttons. For the most part it works (I think) but I am having a difficult time trying to assign values to each hand strength. I have been attempting to add values to the hand strengths inside the handType() method. My question is: Can I assign an integer value to a boolean? I assume the answer is no. Any thoughts on how to assign my hand strengths (ie highCard = 0, pair = 1, twoPair = 2 and so on)?
My Code is as follows (I tried to clean it up a bit, sorry in advance for the mess):
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Player { private String name; private Card[] playerHand = new Card[5]; private ImageIcon playerPicture; private int numberDealt = 0; private boolean highCard; private boolean pair; private boolean twoPair; private boolean threeOfAKind; private boolean fullHouse; private boolean straight; private boolean flush; private boolean fourOfAKind; private boolean straightFlush; private boolean royalFlush; private String handType; public Player() { name = "Card Shark"; playerPicture = new ImageIcon("owned.gif"); numberDealt = 0; } public String getName() { return name; } public void setName(String n) { name = n; } public ImageIcon getplayerPicutre() { return playerPicture; } public void setplayerPicture(ImageIcon p) { playerPicture = p; } public Card getplayerHand() { if(numberDealt < 0) { } else { numberDealt --; } } public void setplayerHand(Card c) { playerHand[numberDealt] = c; if(numberDealt < 5) { numberDealt ++; } } public String handType() { if(highCard == true) { return "Player has High Card"; } if(pair == true) { return "Player has a pair"; } if(twoPair == true) { return "Player has a pair"; } if(threeOfAKind == true) { return "Player has three of a kind"; } if(fullHouse == true) { return "Player has a full house"; } if(straight == true) { return "Player has a straight"; } if(flush == true) { return "Player has a flush"; } if(fourOfAKind == true) { return "Player has four of a kind"; } if(straightFlush == true) { return "Player has a straight flush"; } if(royalFlush == true) { return "Player has a royal flush"; } return handType; } public void sortByRank() { for(int x=0; x<4; x++) { for(int s=0; s<4; s++) { if(playerHand[s].getRank() > playerHand[s+1].getRank()) { playerHand[s] Card tempCard = playerHand[s]; playerHand[s] = playerHand[s+1]; playerHand[s+1] = tempCard; } } } } public void sortByValue() { for(int x=0; x<4; x++) { for(int s=0; s<4; s++) { if(playerHand[s].getValue() > playerHand[s+1].getValue()) { Card tempCard = playerHand[s]; playerHand[s] = playerHand[s+1]; playerHand[s+1] = tempCard; } } } } public void sortBySuit() { for(int x=0; x<4; x++) { for(int s=0; s<4; s++) { if(playerHand[s].getSuit() > playerHand[s+1].getSuit()) { Card tempCard = playerHand[s]; playerHand[s] = playerHand[s+1]; playerHand[s+1] = tempCard; } } } } public boolean highCard() { if(pair == false); { if(twoPair == false); { if(threeOfAKind == false) { if(fullHouse == false) { if(straight == false) { if(flush == false) { if(straightFlush == false) { if(royalFlush == false) { highCard = true; } } } } } } } } return highCard; } public boolean pair() { for(int slot=0; slot<4; slot++) { if(playerHand[slot].getValue() == playerHand[slot+1].getValue()) { pair = true; } else { pair = false; } } return pair; } public boolean twoPair() { for(int slot=0; slot<2; slot++) { if(playerHand[slot].getValue() == playerHand[slot+1].getValue()) { if(playerHand[slot+2].getValue() == playerHand[slot+3].getValue()) { twoPair = true; } else { twoPair = false; } } } return twoPair; } public boolean threeOfAKind() { for(int slot=0; slot<3; slot++) { if(playerHand[slot].getValue() == playerHand[slot+1].getValue()) { if(playerHand[slot+1].getValue() == playerHand[slot+2].getValue()) { threeOfAKind = true; } } } return threeOfAKind; } public boolean fullHouse() { for(int slot=0; slot<1; slot++) { if(playerHand[slot].getValue() == playerHand[slot+1].getValue()) { if(playerHand[slot+1].getValue() == playerHand[slot+2].getValue()) { if(playerHand[slot+3].getValue() == playerHand[slot+4].getValue()) { fullHouse = true; } } } } return fullHouse; } public boolean straight() { for(int slot=0; slot<3; slot++) { if(playerHand[slot].getValue() == playerHand[slot+1].getValue()+1) { straight = true; } } return straight; } public boolean flush() { for(int slot=0; slot<1; slot++) { if(playerHand[slot].getSuit() == playerHand[slot+1].getSuit()) { if(playerHand[slot+1].getSuit() == playerHand[slot+2].getSuit()) { if(playerHand[slot+2].getSuit() == playerHand[slot+3].getSuit()) { if(playerHand[slot+3].getSuit() == playerHand[slot+4].getSuit()) { flush = true; } } } } } return flush; } public boolean fourOfAKind() { for(int slot=0; slot<2; slot++) { if(playerHand[slot].getValue() == playerHand[slot+1].getValue()) { if(playerHand[slot+1].getValue() == playerHand[slot+2].getValue()) { if(playerHand[slot+2].getValue() == playerHand[slot+3].getValue()) { if(playerHand[slot+3].getValue() == playerHand[slot+4].getValue()) { fourOfAKind = true } } } } } return fourOfAKind; } public boolean straightFlush() { if(straight == true && flush == true) { straightFlush = true; } else { straightFlush = false; } return straightFlush; } public boolean royalFlush() { if(flush == true) { for(int slot=0; slot<1; slot++) { if(playerHand[slot].getValue() == 10) { if(playerHand[slot+1].getValue() == 11) { if(playerHand[slot+2].getValue() == 12) { if(playerHand[slot+3].getValue() == 13) { if(playerHand[slot+4].getValue() == 14) { royalFlush = true; } } } } } } } return royalFlush; } public String gethandType() { return handType; } } // end player