所以基本上我正在製作一張牌的遊戲,我試圖從我的牌組頂部移除一張牌certainAmount
,然後將certainAmount
作爲certainAmount
我不明白爲什麼我的邏輯是不正確的java陣列和arraylist中的牌遊戲
private ArrayList<Card> cards;
public Deck() {
cards = new ArrayList <Card>();
for (int type= 0; type<=4; type++){
for (int value=1; value<=9; value++){
Card newCard = new Card (value, type);
cards.add(newCard);
}
}
}
public Deck(Deck other) {
cards = new ArrayList<Card> (other.cards);
}
public Card getCardAt(int position) {
Card gottenCard = cards.get(position);
return gottenCard;
}
public int getNumCards() {
int sizeOfArrayList = cards.size();
return sizeOfArrayList;
}
//remove certain amount (numCards) of cards from top of arraylist
public Card[] deal(int numCards) {
Card[] newArray = new Card[numCards];
//assigning removed card to new array positions
for (int newArrayPosition=0; j<newArrayPosition;newArrayPosition++) {
newArray[j] = cards.remove((cards.size()-1));
for (int newArrayPosition=0; j<newArrayPosition;newArrayPosition++) {
newArray[j] = cards.remove((cards.size()-1));
}
return newArray;
}
你如何知道你的邏輯不正確? –
我我們提交服務器中得到的錯誤說:java.lang.AssertionError:期望值<0>卻被:<4> @cainiaofei – emmynaki
我想你最好發佈更詳細的代碼 –