Hallo habe folgendes Problem und wollte fragen ob mir jemand helfen kann.
Java:
package cardgame;
public class Card {
private final CardValue value;
private final CardColor color;
public Card(CardColor color, CardValue value) {
this.color = color;
this.value = value;
}
@Override
public String toString() {
return this.value.name() + " of " + this.color.name();
}
@Override
public boolean equals(Object other) {
Card otherCard = (Card) other;
return value == otherCard.value && color == otherCard.color;
}
}
-----
package cardgame;
public enum CardColor {
HEARTS, DIAMONDS, SPADES, CLOVER
}
-----
package cardgame;
public enum CardValue {
SEVEN(7), EIGHT(8), NINE(9), TEN(10), JACK(10), DAME(10), KING(10), AS(11);
private int value;
CardValue(int value){
this.value = value;
}
public int getCardValue() {
return value;
}
}
------
package cardgame;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class Stack {
final static private int STACK_SIZE = 32;
/**
* The actual stack of cards.
*/
Card[] cards;
/**
* The topmost card of this stack.
*/
int top;
/**
* Generates the stack of cards recursively.
*
* The generated stack consists of an ordered set of {@link #STACK_SIZE} cards,
* i.e. every possible combination of {@link cardgame.CardColor} and {@link cardgame.CardValue}.
*
* TODO: implement me
* @param color
* @param value
*/
private void generateCards(int color, int value) {
// anchor
if (top == Stack.STACK_SIZE)
return;
// ...
// recursion step
generateCards(color, value);
}
private void generateCardsAndShuffle() {
generateCards(0, 0);
shuffle();
}
/**
* Shuffles the stack of cards.
*
* TODO: implement me. Helpful: {@link Collections} and {@link Arrays}
*/
public void shuffle() {
}
/**
* Get the amount of cards remaining in this stack.
*
* @return {@link #top}
*/
public int size() {
return top;
}
/**
* Get the topmost card from this stack.
*
* TODO: implement me
* @return
*/
public Card reveal() {
return null;
}
}
Zuletzt bearbeitet: