001 package jagafa.object;
002
003 import jagafa.naming.CardNames;
004
005 /**
006 * Klasse Card: Enthält eine Karte mit Farbe und Kartenwert
007 */
008 public class Card {
009 /**
010 * Enthält Farbe und Wert der Karte internal representation; integer
011 * values!!!
012 */
013 private int color_;
014
015 private int value_;
016
017 /**
018 * Erstellt ein neues Kartenobjekt
019 * @param color The color
020 * @param value The value
021 */
022 public Card(int color, int value) {
023 color_ = color;
024 value_ = value;
025 }
026
027 /**
028 * Setzt die Farbe der Karte
029 * @param color The new value
030 */
031 public void setColor(int color) {
032 color_ = color;
033 }
034
035 public boolean equals(Card o) {
036 if (o.getColor() == (getColor()) && o.getValue() == (getValue())) {
037 return true;
038 }
039 return false;
040 }
041
042 /**
043 * Setzt den Wert der Karte
044 * @param value The new value
045 */
046 public void setValue(int value) {
047 value_ = value;
048 }
049
050 /**
051 * Get the value of the card
052 * @return The value
053 */
054 public int getValue() {
055 return value_;
056 }
057
058 /**
059 * Get the color of the card
060 * @return The color
061 */
062 public int getColor() {
063 return color_;
064 }
065
066 /**
067 * Get a exact copy of the card
068 * @return A copy of the card
069 */
070 public Card copy() {
071 return new Card(getColor(), getValue());
072 }
073
074 /**
075 * Liefert einen String mit Farbe und Wert der Karte
076 * @return A String with the print-friendly name of the card
077 */
078 public String toString() {
079 return CardNames.getName(this);
080 }
081
082
083 public int hashCode() {
084 int sum = 0;
085 sum += this.color_;
086 sum += this.value_;
087
088 return sum;
089 }
090
091
092
093 }