Skip to content

Method: changeName(String)

1: package de.fhdw.gaming.ipspiel22.vierGewinnt.domain.impl;
2:
3: import java.util.Optional;
4:
5: import de.fhdw.gaming.core.domain.GameException;
6: import de.fhdw.gaming.ipspiel22.vierGewinnt.domain.VGPlayer;
7: import de.fhdw.gaming.ipspiel22.vierGewinnt.domain.VGPlayerBuilder;
8:
9: /**
10: * Implements {@link VGPlayerBuilder}.
11: */
12: public class VGPlayerBuilderImpl implements VGPlayerBuilder {
13: /**
14: * The name of the player.
15: */
16: private Optional<String> name;
17:
18: /**
19: * If {@code true}, the player will be using red tokens, else she will be using yellow tokens.
20: */
21: private boolean usingRedChips;
22:
23: /**
24: * Creates an {@link VGPlayerBuilderImpl}.
25: */
26: VGPlayerBuilderImpl() {
27: this.name = Optional.empty();
28: this.usingRedChips = true;
29: }
30:
31: @Override
32: public VGPlayerBuilderImpl changeName(final String newName) {
33: this.name = Optional.of(newName);
34: return this;
35: }
36:
37: @Override
38: public VGPlayer build() throws GameException {
39: return new VGPlayerImpl(
40: this.name.orElseThrow(),
41: this.usingRedChips);
42: }
43:
44: @Override
45: public VGPlayerBuilder changeUsingRedChips(final boolean newUsingRedChips) {
46: this.usingRedChips = newUsingRedChips;
47: return this;
48: }
49:
50: @Override
51: public boolean isUsingRedChips() {
52: return this.usingRedChips;
53: }
54: }