-2
在我的代碼中,我無法找到一種方法將我的方法PlayGame()
中的human
和dealer
變量分配給它們各自的由DealCards()
組成的字符串。Java中的紙牌遊戲問題
每當我跑javac
我得到一個錯誤String[] cannot be converted to String.
,因爲他們是在方法DealCards()
的dealerOther
陣列中的獨立字符串我不但是明白這一點。有人可以請給我一些關於這個問題的幫助。
import java.util.Random;
public class GAME_8315085 {
static Random rand = new Random();
public static String[] MakeDeck() {
String[] deck=new String[51];
int k=0;
String[] suits={"\u2660", "\u2661", "\u2662", "\u2663"};
String[] ranks={"2","3","4","5","6","7","8","9","10","J","Q","K","A"};
for (int i=0;i<suits.length;i++) {
for (int j=0;j<ranks.length;j++) {
if (suits[i].equals("\u2663") && ranks[j].equals("Q")) {
;
}
else {
deck[k]=ranks[j]+suits[i];
k++;
}
}
}
return deck;
}
public static void ShuffleDeck(String[] deck) {
for (int i=0;i<deck.length;i++) {
int random = rand.nextInt(deck.length);
String tmp=deck[i];
deck[i] = deck[random];
deck[random]=tmp;
}
}
public static String[][] DealCards(String[] deck) {
String[][] dealerOther = new String[2][26];
int j=0;
for (int i=0; i<=deck.length;i+=2) {
dealerOther[0][j]=deck[i];
j++;
}
j=0;
for (int i=1; i<deck.length;i+=2) {
dealerOther[1][j]=deck[i];
j++;
}
return dealerOther;
}
public static void PlayGame() {
String[] deck = MakeDeck();
ShuffleDeck(deck);
String[][] tmp=DealCards(deck);
String human=tmp[0];
String dealer=tmp[1];
}
public static void main(String[] args) {
PlayGame();
}
}