/    Sign up×
Community /Pin to ProfileBookmark

Draw Poker: Java 14

Hello,

This program is the Java 14th version.
`package game;

import java.util.Arrays;
import java.util.Scanner;

public class DrawPoker {
/*
* Jian C Mitchell
*
* [email protected]
*
* 11/14/20
*
*/

private final int HAND_SIZE = 5;
private int again = 1;

// instantiate Deck and Player
Scanner scan = new Scanner(System.in);
Deck deck = new Deck();
Player player = new Player();
Card[] hand;

// plays the game
public void play()
{
while (again == 1)
{
// fill deck
deck.fillDeck();

// shuffle
deck.shuffle();

// player draws
hand = player.draw(deck);

// sort hand
Arrays.sort(hand);

// player redraws
this.checkHand();
hand = this.redraw();

// display hand again
// this.makeHand();
this.checkHand();

// sort hand
Arrays.sort(hand);

// evaluate the hand
this.evaluate();

// play again?
this.again();
}
System.out.println(“Thanks for playing! =]”);
}

// makes a hand
public void makeHand()
{
hand[0].rank = 1;
hand[1].rank = 2;
hand[2].rank = 3;
hand[3].rank = 4;
hand[4].rank = 5;

hand[0].suit = 1;
hand[1].suit = 1;
hand[2].suit = 1;
hand[3].suit = 1;
hand[4].suit = 1;
}

// tells player cards in hand
public void checkHand()
{
for (int handCounter = 0; handCounter < HAND_SIZE; handCounter++)
{
this.display(hand[handCounter]);
}
}

// asks if player wants to redraw
public Card[] redraw()
{
for (int counter = 0; counter < 5; counter++)
{
System.out.print(“Redraw card ” + (counter + 1) + “?” +
” (1 for yes, 0 for no)”);
int answer = scan.nextInt();
if (answer == 1)
{
hand[counter] = player.redraw(counter, deck);
}
}
deck.refreshDeckPosition();
return hand;
}


// evaluates the hand
public void evaluate()
{
if (this.royalFlush() == 1)
{
System.out.println(“You have a royal flush! +200”);
}
else if (this.straightFlush() == 1)
{
System.out.println(“You have a straight flush! +100”);
}
else if (this.fourOfaKind() == 1)
{
System.out.println(“You have four of a kind! +75”);
}
else if (this.fullHouse() == 1)
{
System.out.println(“You have a full house! +50”);
}
else if (this.flush() == 1)
{
System.out.println(“You have a flush! +35”);
}
else if (this.straight() == 1)
{
System.out.println(“You have a straight! +25”);
}
else if (this.triple() == 1)
{
System.out.println(“You have a triple! +20”);
}
else if (this.twoPairs() == 1)
{
System.out.println(“You have two pairs! +10”);
}
else if (this.pair() == 1)
{
System.out.println(“You have a pair! +2”);
}
else if (this.noPair() == 1)
{
System.out.println(“You have no matching cards! -5”);
}
}

// checks for a royal flush
public int royalFlush()
{
if (hand[0].rank == 1 && hand[1].rank == 10 && hand[2].rank == 11 &&
hand[3].rank == 12 && hand[4].rank == 13)
{
System.out.println(“Game Score: 200”);
return 1;
}
else
{
return 0;
}
}

// checks for a straight flush
public int straightFlush()
{
for (int counter = 1; counter < 5; counter++)
{
if (hand[0].suit != hand[counter].suit)
{
return 0;
}
}
for (int counter2 = 1; counter2 < 5; counter2++)
{
if (hand[counter2 – 1].rank != (hand[counter2].rank – 1))
{
return 0;
}

}
System.out.println(“Game Score: 100”);
return 1;

}

// checks for four of a kind
public int fourOfaKind()
{
if (hand[0].rank != hand[3].rank && hand[1].rank != hand[4].rank)
{
return 0;
}
else
{
System.out.println(“Game Score: 75”);
return 1;
}
}

// checks for full house
public int fullHouse()
{
int comparison = 0;
for (int counter = 1; counter < 5; counter++)
{
if (hand[counter – 1].rank == hand[counter].rank)
{
comparison++;
}
}
if (comparison == 3)
{
System.out.println(“Game Score: 50”);
return 1;
}
else
{
return 0;
}
}

// checks for flush
public int flush()
{
for (int counter = 1; counter < 5; counter++)
{
if (hand[0].suit != hand[counter].suit)
{
return 0;
}
}
System.out.println(“Game Score: 35”);
return 1;
}

// check for straight
public int straight()
{
for (int counter2 = 1; counter2 < 5; counter2++)
{
if (hand[counter2 – 1].rank != (hand[counter2].rank – 1))
{
return 0;
}

}
System.out.println(“Game Score: 25”);
return 1;
}

// checks for triple
public int triple()
{
if (hand[0].rank == hand[2].rank || hand[2].rank == hand[4].rank)
{
System.out.println(“Game Score: 20”);
return 1;
}
return 0;
}

// checks for two pairs
public int twoPairs()
{
int check = 0;
for(int counter = 1; counter < 5; counter++)
{
if (hand[counter – 1].rank == hand[counter].rank)
{
check++;
}
}
if (check == 2)
{
System.out.println(“Game Score: 10”);
return 1;
}
else
{
return 0;
}
}

// check for pair
public int pair()
{
int check = 0;
for(int counter = 1; counter < 5; counter++)
{
if (hand[counter – 1].rank == hand[counter].rank)
{
check++;
}
}
if (check == 1)
{
System.out.println(“Game Score: 2”);
return 1;
}
else
{
return 0;
}
}

// check for no pairs
public int noPair()
{
int check = 0;
for(int counter = 1; counter < 5; counter++)
{
if (hand[counter – 1].rank == hand[counter].rank)
{
check++;
}
}
if (check == 0)
{
System.out.println(“Game Score: 0”);
return 1;
}
else
{
return 0;
}

}

// asks user if they want to play again
public void again()
{
System.out.print(“Play again? (1 for yes, 0 for no)”);
again = scan.nextInt();
}

// generates string for each card in hand
public void display(Card card)
{
if (card.rank == 1)
{
System.out.print(“Ace of “);
}
if (card.rank == 2)
{
System.out.print(“Two of “);
}
if (card.rank == 3)
{
System.out.print(“Three of “);
}
if (card.rank == 4)
{
System.out.print(“Four of “);
}
if (card.rank == 5)
{
System.out.print(“Five of “);
}
if (card.rank == 6)
{
System.out.print(“Six of “);
}
if (card.rank == 7)
{
System.out.print(“Seven of “);
}
if (card.rank == 8)
{
System.out.print(“Eight of “);
}
if (card.rank == 9)
{
System.out.print(“Nine of “);
}
if (card.rank == 10)
{
System.out.print(“Ten of “);
}
if (card.rank == 11)
{
System.out.print(“Jack of “);
}
if (card.rank == 12)
{
System.out.print(“Queen of “);
}
if (card.rank == 13)
{
System.out.print(“King of “);
}
if (card.suit == 1)
{
System.out.print(“Spades”);
System.out.println();
}
if (card.suit == 2)
{
System.out.print(“Hearts”);
System.out.println();
}
if (card.suit == 3)
{
System.out.print(“Diamonds”);
System.out.println();
}
if (card.suit == 4)
{
System.out.print(“Clubs”);
System.out.println();
}

}
}

`
I’ve been having some problems with the following code;

I don’t know how to create a piece of code that can keep track of the following games score’s. I’ve been wanting to create a code that can keep track of a game like game 1, game 2, game 3 etc. with a continuous point system which has an increasing score like ‘Game Score: 2’, Game Score: 20’, Game Score: 50’, etc.

I hope to implement this into the Java code while keeping some of the current characteristics within.
Please help me with implementing a ‘score count’ and a code that will display the next game with 1, 2, 3, 4, etc. within the continuous loop.

I hope to get a response as soon as you are available and if you’re wondering about other parts of the code please inform me.

to post a comment
Java

3 Comments(s)

Copy linkTweet thisAlerts:
@wakhjNov 17.2020 — i have the same problem
Copy linkTweet thisAlerts:
@DuecodeNov 17.2020 — interesting
Copy linkTweet thisAlerts:
@wakhjNov 18.2020 — i have the same problem






[url=https://snaptube.one/][color=#a9a9a9][size=1]snaptube[/size][/color][/url] [url=https://vidmate.ltd/][color=#a9a9a9][size=1]vidmate[/size][/color][/url] [url=https://wordtopdf.ltd/][color=#a9a9a9][size=1]word to pdf[/size][/color][/url]
×

Success!

Help @jianMitchell spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...