Package: DilemmaMove
DilemmaMove
| name | instruction | branch | complexity | line | method | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| DilemmaMove() | 
  | 
  | 
  | 
  | 
  | 
||||||||||||||||||||
| applyTo(IDilemmaState, IDilemmaPlayer) | 
  | 
  | 
  | 
  | 
  | 
||||||||||||||||||||
| equals(Object) | 
  | 
  | 
  | 
  | 
  | 
||||||||||||||||||||
| hashCode() | 
  | 
  | 
  | 
  | 
  | 
||||||||||||||||||||
Coverage
1: package de.fhdw.gaming.ipspiel23.dilemma.moves.internals;
2: 
3: import de.fhdw.gaming.core.domain.GameException;
4: import de.fhdw.gaming.ipspiel23.dilemma.domain.DilemmaAnswerType;
5: import de.fhdw.gaming.ipspiel23.dilemma.domain.IDilemmaPlayer;
6: import de.fhdw.gaming.ipspiel23.dilemma.domain.IDilemmaState;
7: import de.fhdw.gaming.ipspiel23.dilemma.moves.IDilemmaMove;
8: 
9: /**
10:  * Represents a move allowed by the rules of the game.
11:  * <p>
12:  * The purpose of this class is to be able to check whether a {@link IDilemmaMove} implementation is allowed by the
13:  * rules of the game. As this class is not public, custom strategies are unable to create {@link IDilemmaMove} objects
14:  * that inherit from this class, so custom moves can be distinguished from possible moves easily.
15:  * </p>
16:  */
17: public abstract class DilemmaMove implements IDilemmaMove {
18:     
19:     /**
20:      * Protected constructor.
21:      */
22:     protected DilemmaMove() {
23:         // nothing to do
24:     }
25: 
26:     @Override
27:     public void applyTo(final IDilemmaState state, final IDilemmaPlayer player) throws GameException {
28:         player.setAnswer(getAnswer());
29:     }
30: 
31:     @Override
32:     public abstract DilemmaAnswerType getAnswer();
33: 
34:     @Override
35:     public boolean equals(final Object obj) {
36:•        if (obj instanceof DilemmaMove) {
37:             final DilemmaMove other = (DilemmaMove) obj;
38:             return other.getAnswer().equals(this.getAnswer());
39:         }
40:         return false;
41:     }
42:     
43:     @Override
44:     public int hashCode() {
45:         return this.getAnswer().hashCode() + 31 * this.toString().hashCode();
46:     }
47: }