Ich schreibe einen UnoPlayer.java-Code für eine Hauptmethode, die bereits ausgeschrieben wurde, um die Rechtmäßigkeit unserer UnoPlayer-Methode zu testen.Wie kann man nach einem bestimmten Datentyp in der Liste suchen?
Ich versuche zu überprüfen, ob die Menge einer Farbe (ein Datentyp) in meiner Hand größer als die Menge der anderen Farben ist.
Hand ist ein Listentyp !!
Also, für Color.BLUE, ich habe dies:
if (hand.contains(Color.BLUE > Color.RED && Color.GREEN && Color.YELLOW)) {
colorReturned = Color.BLUE;
}
Ich weiß, dass dies nicht, weil meine Farbe Datentyp mit Binäroperanden funktioniert nicht funktioniert, weil sie nicht Ints sind. Wie würde ich es Code, so dass es sagt
// if (Hand mehr Color.BLUE als der Rest der Farben enthält) {
// Gibt Color.BLUE}
hier ist die Karte Umsetzung:
private UnoPlayer.Color color;
private UnoPlayer.Rank rank;
private int number;
public Card(UnoPlayer.Color color, UnoPlayer.Rank rank) {
this.color = color;
this.rank = rank;
this.number = -1;
}
public Card(UnoPlayer.Color color, int number) {
this.color = color;
this.rank = UnoPlayer.Rank.NUMBER;
this.number = number;
}
public Card(UnoPlayer.Color color, UnoPlayer.Rank rank, int number) {
this.color = color;
this.rank = rank;
this.number = number;
}
Welche Art von Variable ist 'Hand'? –
@ChrisGong Hand ist eine Liste!Entschuldigung für keine Angabe – hattic
Eine Liste von 'int' oder' Integer'? –