Hi, I am writing a game. Three card brag. The rules of the game are
1.Each player is dealt three cards.
2.The hand is then assigned a rank based on the cards recieved
3. The hand Ranks are 0,1,2,3
4. the hand ranks are then compared and the highest hand rank from that game is the winner, other wise it's a draw.
I'm almost finished with this game, but im having trouble figuring out how to tally each players total game points. the game points are just the values from the hand ranks added to each other from each game. the score should automatically update once the user clicks on the button to start a new game.another trick to it is that the winner of the game automatically gets a point just for winning.
so an example of what im trying to do.
first game:
player 1 has a hand rank of 3//winner
player 1 Total Score:0
player 2 has a hand rank of 2
player 2 Total score: 0
second game:
player 1 has a hand rank of 2//winner
player 1 Total Score:7
player 2 has a hand rank of 1
player 2 Total Score :2
how would i go about doing this, i have to catch the value of the handRank and add it to the last value of the handRank everytime but how would i do this? through an array?? with a for loop running? I don't know, I'm lost. Any suggestions would be appreciated. here is my player.java code for you guys. if you need to see the rest of my code. let me know.
public class Player {
private String name="";
private int cardsInHandForGame;
private int cardsInHand = 0;
private int totalGamePoints;
private Card[] hand = new Card[3];
private int handRank;
public Player() {
totalGamePoints = 0;
handRank = 0;
for(int i = 0; i < cardsInHandForGame; ++i)
{
hand[i] = new Card();
}
}
//Name
public void setName(String n)
{
name = n;
}
public String getName( )
{
return name;
}
public void setCardsInHandForGame(int numberOfCards)
{
cardsInHandForGame = numberOfCards;
}
//Hand Rank
public int getHandRank()
{
return handRank;
}
//Total Game Points
public int getTotalPoints()
{
return totalGamePoints;
}
public String toString() {
String s ="";
////write this===============================
return s;
}
//returns the player's name, current hand rank, and total pts
public String getNameHandRankAndPoints() {
String s = "your hand rank is: "+ handRank
/*+"your total score is: " + totalGamePoints*/;
//this is where i should output the score!!
return s;
}
//setCard Is called when a card is dealt to the player.
//The Frame will call this, passing a Card c,
//setting it into the player's hand (at the current
//cardsInHand position), increment the number of cards
//in the player's hand (cardsInHand++).
//When the player has the maximum number of cards for the game,
//the player determines the hand rank and assigns points to his score.
public void setCard(Card c) { //put the card in the player hand
hand[cardsInHand] = c; //increment hand index
cardsInHand++;
if(cardsInHand == (cardsInHandForGame)) {
cardsInHand = 0;
determineHandRank();
}
}
//performs the logic needed to determine the winning hand level
//assigns value (0,1,2,3) to handRank.
//winning hand points are assigned to totalGamePoints
public int determineHandRank( ) {
//you write this, assign value to handRank, add to points
//handRank; holds the current hand's winning rank value
//0 = not a winning hand
//1 = lowest level, J, Q, K
//2 = mid-level, 2 or 3 of any suit or rank
//3 = high-level, 3-3's or an Ace
//If 3 3's or an Ace in Hand[0], Hand[1], or Hand[2], then Rank = 3
if((hand[0].getRank()== hand[1].getRank() && hand[1].getRank() == hand[2].getRank()) || (hand[0].getRank()== 14 || hand[1].getRank() == 14 || hand[2].getRank() == 14 ))
{
handRank = 3;
}
else if((hand[0].getRank() == hand[1].getRank()) || (hand[0].getRank() == hand[2].getRank()) || (hand[1].getRank() == hand[2].getRank()))
{
handRank = 2;
}
else if((hand[0].getRank() >10 && hand[0].getRank() < 14) || (hand[1].getRank() >10 && hand[1].getRank() < 14 )|| (hand[2].getRank() >10 && hand[2].getRank() < 14 ))
{
handRank = 1;
}
else
{
handRank = 0;
}
return handRank;
//If 2 or 3 and suit or rank in Hand[0], Hand[1], or Hand[2], then Rank = 2
//If 1 Jack Queen or King in Hand[0], Hand[1], or Hand[2], then Rank = 1
//else = 0
}
//If the player has won the hand, give'em an extra point
//Note: this will be called from the Frame!
public void creditGameWin( )
{
totalGamePoints++;
}
}