我有一個任務來創建一個撲克遊戲,詢問有多少人在玩(1-7),以及他們是否想玩5張牌螺柱或7張。這些沒有投注圖等等。簡單的一方面看你有什麼遊戲。我需要讓方法Questions爲gameType和numPlayers都返回一個值。 5張牌組和7張牌組取決於從gameType變量返回的值。我不知道如何做到這一點......任何想法?Java-撲克玩家
我也必須以某種方式將多個玩家集成到甲板中。
import java.util.Scanner;
public class pokerGame {
public static void main(String[] args) {
Questions();
if (Questions == 5){
Deck5();}
else{
Deck7();}
}
public static int Questions() {
int numPlayers, gameType;
Scanner sc = new Scanner(System.in);
System.out.print("How many people do we have playing poker today? " + "Enter a number between 1 and 7: \n");
numPlayers = sc.nextInt();
System.out.println("Are you playing 7 car stud or 5 card stud?");
gameType = sc.nextInt();
return gameType;
}
public static String Deck5() {
int[] deck = new int[52];
String[] suits = { "Spades", "Hearts", "Diamonds", "Clubs" };
String[] ranks = { "Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King" };
// Initialize cards
for (int i = 0; i < deck.length; i++){
deck[i] = i;
String suit = suits[deck[i]/13];
String rank = ranks[deck[i] % 13];
//show the deck in the original order
System.out.println(deck[i] + ": " + rank + " of " + suit + "\n");
}
// Shuffle the cards
for (int i = 0; i < deck.length; i++) {
// Generate an index randomly
int index = (int) (Math.random() * deck.length);
int temp = deck[i];
deck[i] = deck[index];
deck[index] = temp;
}
// Display the 5 cards
for (int i = 0; i < 5; i++) {
String suit = suits[deck[i]/13];
String rank = ranks[deck[i] % 13];
System.out.println(rank + " of " + suit);
}
public static String Deck7();
int[] deck = new int[52];
String[] suits = { "Spades", "Hearts", "Diamonds", "Clubs" };
String[] ranks = { "Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King" };
// Initialize cards
for (int i = 0; i < deck.length; i++)
deck[i] = i;
// Shuffle the cards
for (int i = 0; i < deck.length; i++) {
// Generate an index randomly
int index = (int) (Math.random() * deck.length);
int temp = deck[i];
deck[i] = deck[index];
deck[index] = temp;
}
// Display the 5 cards
for (int i = 0; i < 7; i++) {
String suit = suits[deck[i]/13];
String rank = ranks[deck[i] % 13];
System.out.println(rank + " of " + suit);
}
}
}
您可以將您的代碼發佈到http://codereview.stackexchange.com/ – Sayakiss
我確定我們不知道您的意思。畢竟你的程序是你需要寫的。目前看起來不錯。 – 3kings
請在需要幫助時使用代碼發佈[MCVE]。它確實加快了這個過程。此外,@Sayakiss我同意,但他正在尋求幫助/執行,而不是改進。代碼審查更適合已經工作的項目。 –