Java 扑克游戏

Java Poker Game

到目前为止,我正在创建一个 java 扑克游戏,我的程序会为玩家、发牌人和棋盘(河牌)选择随机牌。我现在希望我的玩家能够输入一个值作为赌注,虽然我使用了“Scanner bet = new Scanner(System.in);”,但如果庄家赢了,我还需要一个底池和一个放置底池价值的地方。我认为我需要列出 2 或 3 个玩家现金、底池、赌场现金。

到目前为止,这是我的代码:-

    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;

    }
}

如果你能帮助我或指出我需要去的方向,那就太好了。

我的第一个想法是您应该创建 Player 对象。它将包括: - 2张扑克牌 - player/dealer 拥有的金钱数额

现在方法:

  1. 获取堆栈(); Returns玩家筹码
  2. MakeBet(双BetSize);从玩家堆栈中取出 BetSize 并将其放入底池。
  3. AddPotToStack(双PotAmount);把底池放在赢家的筹码中。
  4. 新手();抽2张扑克牌放入物品中

希望对您有所帮助