public enum Shape extends java.lang.Enum<Shape>
beats(cz.gyarab.util.game.rps.Shape)
, resp. winner(cz.gyarab.util.game.rps.Shape)
.Enum Constant and Description |
---|
PAPER
Papír zabalí kámen.
|
ROCK
Kámen tupí nůžky.
|
SCISSORS
Nůžky rozstřihnou papír.
|
Modifier and Type | Method and Description |
---|---|
Shape |
beats()
Zjistí, který symbol je poražen tímto.
|
boolean |
beats(Shape opponent)
Zjistí, jestli tento symbol poráží druhý symbol.
|
static Shape |
random()
Vybere náhodný symbol.
|
static Shape |
random(java.util.Random random)
Vybere náhodný symbol pomocí poskytnutého generátoru náhodných čísel.
|
static Shape |
valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name.
|
static Shape[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
int |
winner(Shape opponent)
Zjistí, kdo je vítěz souboje.
|
public static final Shape ROCK
public static final Shape PAPER
public static final Shape SCISSORS
public static Shape[] values()
for (Shape c : Shape.values()) System.out.println(c);
public static Shape valueOf(java.lang.String name)
name
- the name of the enum constant to be returned.java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is nullpublic static Shape random()
public static Shape random(java.util.Random random)
random
- generátor náhodných číselpublic int winner(Shape opponent)
Pozn.: Návratová hodnota je inspirována návratovou hodnotou metody
Comparable.compareTo(T)
. Nelze však použít přímo rozhraní
Comparable
, protože metoda předpokládá tranzitivitu porovnávaných
hodnot (a > b ^ b > c → a > c), což v tomto případě
neplatí.
opponent
- porovnávaný symbol-1
, pokud tento symbol s porovnávaným prohrává,
+1
, pokud vyhrává, 0
, pokud remízujepublic boolean beats(Shape opponent)
opponent
- porovnávaný symboltrue
, pokud je tento symbol vítězem nad porovnávaným; při
remíze a prohře false
public Shape beats()