summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/model/Stone.java
blob: 5d61a56383962ac2885da50075738a59c3d7d05e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package jrummikub.model;

import java.io.Serializable;

/** Basic Rummikub Stone */

public class Stone implements Sizeable, Serializable {
	private static final long serialVersionUID = 7032593080727812277L;

	private int value;
	private StoneColor color;
	private final boolean joker;

	/**
	 * Creates a joker of the given color. The color is only used for displaying.
	 * 
	 * @param color
	 *          joker color
	 */
	public Stone(StoneColor color) {
		this.value = 0;
		this.color = color;
		this.joker = true;
	}

	/**
	 * Creates a normal stone of a given color and value
	 * 
	 * @param value
	 *          stone value
	 * @param color
	 *          stone color
	 */
	public Stone(int value, StoneColor color) {
		this.value = value;
		this.color = color;
		this.joker = false;
	}

	/**
	 * Returns the color of the stone.
	 * 
	 * @return stone color
	 */
	public StoneColor getColor() {
		return color;
	}

	/**
	 * Returns whether the stone is a joker or not.
	 * 
	 * @return true when the stone is a joker
	 */
	public boolean isJoker() {
		return joker;
	}

	/**
	 * Returns the value of the stone. Don't use this value for jokers.
	 * 
	 * @return stone value
	 */
	public int getValue() {
		return value;
	}

	@Override
	public float getWidth() {
		return 1;
	}

	@Override
	public float getHeight() {
		return 1;
	}

	@Override
	public String toString() {
		if (joker) {
			return "[" + color + " J]";
		} else {
			return "[" + color + " " + value + "]";
		}
	}
}