public static void main(String[] argv) { int i, inbet = 99, round = 1; int deck[] = new int[52]; // 初始化牌組 for (i = 0; i < 52; i++) deck[i] = 0; // 遊戲開始 System.out.println("PXXCasino Jacks or better, written by p04922003 Yen-Cheng Lai"); System.out.print("Game Start, Please enter your name: "); Scanner input = new Scanner(System.in); // 名字、錢 Scanner input2 = new Scanner(System.in); // 要keep的牌 String name = input.next(); // 產生玩家 player p = new player(name); // 初始值為99 // 取牌 // Computer.dealCard(p.handCard,deck); System.out.println("Welcome " + p.name + ", you got " + p.playerMoney + " P-dolars!!"); while (inbet != 0 && (p.playerMoney > 0)) { // 當下注金額>0且玩家錢>0時遊戲繼續 System.out.printf("Throw coins you want to bet for round %d:\n", round); System.out.println("(1-5 to bet and 0 to quit)"); inbet = input.nextInt(); Computer.dealCard(p.handCard, deck); if (0 < inbet && inbet <= 5) { ++round; p.playerMoney -= inbet; // 扣錢 System.out.print("You got cards: "); Card.showCard(p.handCard); System.out.println(" "); // 選擇要保留的手牌 System.out.println("Which cards you \"want keep\":"); System.out.println("(Type \"abcde\" to keep each and \"q\"to hold all)"); System.out.println("(x to re-deal all)"); String choose = input2.next(); // player輸入的字串 p.keepCard(p.handCard, deck, choose); Computer.dealCard(p.handCard, deck); // System.out.print("Your new cards are: "); Card.showCard(p.handCard); System.out.println(" "); System.out.print("You got a "); switch (Computer.judgeCard(p.handCard)) { case 0: System.out.println("nothing hand."); break; case 1: System.out.println("Jacks or Better hand."); break; case 2: System.out.println("Two pair hand."); break; case 3: System.out.println("Three of a kind hand."); break; case 4: System.out.println("Straight hand."); break; case 6: System.out.println("Flush hand."); break; case 9: System.out.println("Full House hand."); break; case 25: System.out.println("Four of a kind hand."); break; case 50: System.out.println("Straight flush hand."); break; case 250: System.out.println("Royal flush hand."); break; } p.playerMoney = Computer.drawMoney(Computer.judgeCard(p.handCard), inbet, p.playerMoney); System.out.println("You have " + p.playerMoney + " P-dollars now"); } else if (inbet == 0) break; else { System.out.println("(1-5 to bet and 0 to quit)"); continue; } // 清空玩家手牌 for (i = 0; i < p.handCard.length; i++) { deck[p.handCard[i]] = 0; p.handCard[i] = 99; } } System.out.print("Good Bye" + p.name + ". you play for " + round + " round"); System.out.printf(" and have " + p.playerMoney + " now"); input.close(); input2.close(); }