我一直在疯狂在这个程序即时通讯写作。我的甲板似乎不工作,我已经为每一个信息的追踪,但8小时后直接它仍然无法工作=(请帮助指出我需要更好地工作或如何去编码它更好。java扑克牌阵列
package poker;
public class Deck {
private Card[] cards;
// deck constructor with initial array
public Deck() {
Card[] x= new Card[52];
int index = 0;
for (int suit = 0; suit < 3; suit++) {
for (int value = 1; value < 13; value++) {
cards[index] = new Card(value, suit);
index++;
}
}
}
// copy constructor with a shallow copy of the array
public Deck(Deck other) {
Card[] c = new Card[52];
int index = 0;
for (int suit = 0; suit <= 3; suit++) {
for (int value = 1; value <= 13; value++) {
cards[index] = new Card(suit, value);
index++;
}
}
}
// method for cards in any position
public Card getCardAt(int position) {
if (position >= cards.length) {
throw new IndexOutOfBoundsException("Values are out of bounds");
} else {
return cards[position];
}
}
// number of cards left after each draw
public int getNumCards() {
return cards.length;
}
// Randomized rearrangement of cards
//have no idea to go about this any further
public void shuffle() {
int temp=0;
for (int row=0;row<cards.length;row++){
int random = (int)(Math.random()*((cards.length-row)+1));
Deck.this.cards[temp]= this.getCardAt(row);
cards[row]=cards[random];
cards[random]=cards[temp];
}
}
//cutting of the cards
public void cut(int position) {
//int temp = this.cards
}
// something to think about on dealing from taking the differences in
// dealing the cards
public Card[] deal(int numCards) {
/* numCards = 5;
for (int i = 0; i < numCards; i++) {
numCards = cards.length - numCards;
}
return deal(numCards);*/
{
numCards = this.getNumCards();
numCards ++;
return deal(5);
}
}
}
我试图JUnit测试,但我似乎在他们吮吸,但我想
package poker;
import junit.framework.TestCase;
public class StudentTests extends TestCase {
public void testDeck() {
int value=0;
int suit = 0;
Card[] x = new Card[52];
//Card = new Card(getValue(), getSuit());
assertTrue(getValue() == 1 && getSuit() == value);
assertTrue(getValue() == 1 && getSuit() == suit);
;
}
public void testCopyConstructor(){
int value = 0;
int suit = 0;
Card[] sc = new Card[52];
//Card = new Card(getValue(), getSuit());
assertTrue(getValue() == 1 && getSuit() == 0);
}
/* public void testShuffle()
{
Card[] sc = new Card[52];
Card[] sc2 = new Card[52];
assertTrue(sc==(sc2));
//shuffle method
assertFalse(sc==(sc2));
//another shuffle method here
//i have no idea
assertFalse(sc==(sc2));} */
private int getValue() {
// TODO Auto-generated method stub
return 1;
}
private int getSuit() {
// TODO Auto-generated method stub
return 0;
}
}
我感觉你,但这个问题可能会被关闭,除非你添加一些更多的细节。究竟是什么问题?如果我们甚至不知道它应该做什么,“套牌似乎不工作”并不是很有帮助。你知道问题出在哪里吗?你是否收到特定的错误信息? – Pops 2011-04-14 19:06:19