Search code examples
javalistjava.util.scannerpoker

Java Poker Game


I am creating a java poker game so far I've got my program selecting random cards for the player, dealer and on the board (river). I now want my player to be able to input a value as a bet, I've though of using "Scanner bet = new Scanner(System.in);" but I also will need a pot and a place for the pot value to go if the dealer wins. I think that I'll need to have 2 or 3 list Player's cash, Pot, Houses cash.

This is my code so far:-

    public PockerMain() {
        // TODO Auto-generated constructor stub
    }

    public static void main(String[] args) 
    {
        List<PokerCard> deck = cardDeck();
        System.out.println(deck.size() + " Cards In Deck");
        System.out.println();
        playersHand(deck);
        housesHand(deck);
        theBoard(deck);
        System.out.println(deck.size() + " Cards In Deck");
    }
    public static void playersHand(List<PokerCard> deck)
    {

        PokerCard selectedCard = nextCardToPick(deck);
        PokerCard secondSelectedCard = secondCardToPick(deck);
        System.out.println(selectedCard + " this your random card");
        System.out.println(secondSelectedCard + " this is your other card");
        System.out.println();
        Scanner bet = new Scanner(System.in);
    }
    public static void housesHand(List<PokerCard> deck)
    {

        PokerCard dealersFirstCard = dealerHandFirstCard(deck);
        PokerCard dealersSecondCard = dealerHandSecondCard(deck);
        System.out.println(dealersFirstCard + " this is the dealers random card");
        System.out.println(dealersSecondCard + " this is the dealers other card");
        System.out.println();
    }
    public static void theBoard(List<PokerCard> deck)
    {

        PokerCard firstBoardCard = boardCardOne(deck);
        PokerCard secondBoardCard = boardCardTwo(deck);
        PokerCard thirdBoardCard = boardCardThree(deck);
        PokerCard forthBoardCard = boardCardFour(deck);
        PokerCard fithBoardCard = boardCardFive(deck);
        System.out.println(firstBoardCard + " this is the first card on the board");
        System.out.println(secondBoardCard + " this is the second card on the board");
        System.out.println(thirdBoardCard + " this is the third card on the board");
        System.out.println(forthBoardCard + " this is the forth card on the board");
        System.out.println(fithBoardCard + " this is the fith card on the board");
        System.out.println();

    }
    private static PokerCard createCard (short suit, short rank)
    {
        PokerCard card = new PokerCard (suit, rank);
        return card;
    }
    private static List<PokerCard> cardDeck ()
    {
        List<PokerCard> deck = new ArrayList<PokerCard> ();
        for (int i = 0; i < 4; i ++)
        {
            for (int j = 0; j < 13; j ++)
            {
                PokerCard card = createCard ((short)i, (short)j);
                deck.add(card);
            }

        }
        return deck;
    }
    /** 
     * this selects a card and the removes it from the list of cards
     * @param cardDeck is the list of cards
     * @return a random card selected from the cardDeck 
     */
    private static PokerCard nextCardToPick(List<PokerCard> cardDeck)
    {

        Random random = new Random();
        int nextCardToPick = random.nextInt(cardDeck.size());//get random number in range 0 - deck.size (assuming 52 cards then it will give value between 0 -51)
        PokerCard selectedCard = cardDeck.get(nextCardToPick);
        cardDeck.remove(selectedCard);//this will remove the card from the cardDeck
        return selectedCard;

    }
    private static PokerCard secondCardToPick(List<PokerCard> cardDeck)
    {

        Random random = new Random();
        int secondCardToPick = random.nextInt(cardDeck.size());//get random number in range 0 - deck.size (assuming 52 cards then it will give value between 0 -51)
        PokerCard secondSelectedCard = cardDeck.get(secondCardToPick);
        cardDeck.remove(secondSelectedCard);//this will remove the card from the cardDeck
        return secondSelectedCard;

    }
    private static PokerCard dealerHandFirstCard(List<PokerCard> cardDeck)
    {

        Random random = new Random();
        int dealerHandFirstCard = random.nextInt(cardDeck.size());//get random number in range 0 - deck.size (assuming 52 cards then it will give value between 0 -51)
        PokerCard dealersFirstCard = cardDeck.get(dealerHandFirstCard);
        cardDeck.remove(dealersFirstCard);//this will remove the card from the cardDeck
        return dealersFirstCard;

    }
    private static PokerCard dealerHandSecondCard(List<PokerCard> cardDeck)
    {

        Random random = new Random();
        int dealerHandSecondCard = random.nextInt(cardDeck.size());//get random number in range 0 - deck.size (assuming 52 cards then it will give value between 0 -51)
        PokerCard dealersSecondCard = cardDeck.get(dealerHandSecondCard);
        cardDeck.remove(dealersSecondCard);//this will remove the card from the cardDeck
        return dealersSecondCard;

    }
    private static PokerCard boardCardOne(List<PokerCard> cardDeck)
    {

        Random random = new Random();
        int boardCardOne = random.nextInt(cardDeck.size());//get random number in range 0 - deck.size (assuming 52 cards then it will give value between 0 -51)
        PokerCard firstBoardCard = cardDeck.get(boardCardOne);
        cardDeck.remove(firstBoardCard);//this will remove the card from the cardDeck
        return firstBoardCard;

    }
    private static PokerCard boardCardTwo(List<PokerCard> cardDeck)
    {

        Random random = new Random();
        int boardCardTwo = random.nextInt(cardDeck.size());//get random number in range 0 - deck.size (assuming 52 cards then it will give value between 0 -51)
        PokerCard secondBoardCard = cardDeck.get(boardCardTwo);
        cardDeck.remove(secondBoardCard);//this will remove the card from the cardDeck
        return secondBoardCard;

    }
    private static PokerCard boardCardThree(List<PokerCard> cardDeck)
    {

        Random random = new Random();
        int boardCardThree = random.nextInt(cardDeck.size());//get random number in range 0 - deck.size (assuming 52 cards then it will give value between 0 -51)
        PokerCard thirdBoardCard = cardDeck.get(boardCardThree);
        cardDeck.remove(thirdBoardCard);//this will remove the card from the cardDeck
        return thirdBoardCard;

    }
    private static PokerCard boardCardFour(List<PokerCard> cardDeck)
    {

        Random random = new Random();
        int boardCardFour = random.nextInt(cardDeck.size());//get random number in range 0 - deck.size (assuming 52 cards then it will give value between 0 -51)
        PokerCard forthBoardCard = cardDeck.get(boardCardFour);
        cardDeck.remove(forthBoardCard);//this will remove the card from the cardDeck
        return forthBoardCard;

    }
    private static PokerCard boardCardFive(List<PokerCard> cardDeck)
    {

        Random random = new Random();
        int boardCardFive = random.nextInt(cardDeck.size());//get random number in range 0 - deck.size (assuming 52 cards then it will give value between 0 -51)
        PokerCard fithBoardCard = cardDeck.get(boardCardFive);
        cardDeck.remove(fithBoardCard);//this will remove the card from the cardDeck
        return fithBoardCard;

    }
}

If you could help or point me in the direction that I need to go that would be great.


Solution

  • First thought i have is that you should do Player objects. It would consist in : - 2 poker cards - The amount of money the player/dealer has

    Now the methods :

    1. GetStack(); Returns the stack of the player
    2. MakeBet(double BetSize); Take away BetSize from player stack and put it in the pot.
    3. AddPotToStack(double PotAmount); Put the pot in the stack of the winner.
    4. NewHand(); Draw 2 poker cards and put them in the object.

    Hope this helps