【发布时间】:2014-02-24 23:45:54
【问题描述】:
我在为我的班级解决这个问题时遇到了麻烦。我有一个卡片组类,我必须制定一种制作卡片组的方法,将其洗牌,然后将其发给两只手。我不知道如何启动它们,有人可以帮助我吗?我对这些东西很感兴趣。
public class Game
{
public static Card[] deck = new Card[52];
public static Card[] xHand, yHand;
public static Scanner in = new Scanner(System.in);
public static int numInHand, x=0,y=0;
public static void main(String[] args)
{
System.out.println("Press Enter to make a new deck.");
in.nextLine();
makeDeck();
System.out.println("A new deck.\n");
for(int i = 0; i < deck.length; i++)
System.out.println(deck[i]);
System.out.println("Press Enter to shuffle the deck.");
in.nextLine();
shuffle();
System.out.println("\nA shuffled deck.\n");
for(int i = 0; i < deck.length; i++)
System.out.println(deck[i]);
System.out.println("How many cards would should we deal to each player?");
numInHand = in.nextInt();
in.nextLine();
xHand = new Card[numInHand];
yHand = new Card[numInHand];
deal();
System.out.println("\nYour Hand.\n");
for(int i = 0; i < xHand.length; i++)
if(xHand[i]!=null) System.out.println(xHand[i]);
System.out.println("\nYour Opponent's Hand.\n");
for(int i = 0; i < yHand.length; i++)
if(xHand[i]!=null) System.out.println(yHand[i]);
play();
}
public static void makeDeck()
{
}
public static void shuffle()
{
}
public static void deal()
{
}
}
【问题讨论】:
-
你能用文字确切地写出
makeDeck()应该做什么吗?然后,您可能对如何将其转换为 Java 有一些想法。 -
您到底遇到了什么问题?基本上你好像什么都没开始。
-
试试看这个,可能会给你一些想法:stackoverflow.com/questions/10369375/…
-
我不知道我应该如何启动 makeDeck。它应该在卡片数组中创建一副卡片并将它们列出来。我还没有开始,因为我不知道如何伤心
-
尝试一下。用文字写下或大声说出需要做的事情。然后去做。您知道您需要一些卡片,您需要哪些卡片以及需要多少张?
标签: java