KaiserGame.java

1
package de.aikiit.game.kaiser;
2
3
import org.assertj.core.util.VisibleForTesting;
4
5
/**
6
 * This class encapsulates the actual game flow.
7
 * A player
8
 * <ul>
9
 *     <li>is shown current statistics and</li>
10
 *     <li>can start to act</li>
11
 *     <li>until the maximum number of rounds is reached and the game ends.</li>
12
 * </ul>
13
 */
14
public class KaiserGame {
15
16
    /**
17
     * The player can play at most this number of rounds.
18
     */
19
    public static final int MAX_ROUNDS = 10;
20
    private final KaiserEngine engine;
21
    private final KaiserEnginePrinter printer;
22
    /**
23
     * The current round of the game.
24
     */
25
    private int round = 0;
26
27
    public KaiserGame() {
28
        this(new KaiserEngine());
29
    }
30
31
    @VisibleForTesting
32
    KaiserGame(KaiserEngine engine) {
33
        this.engine = engine;
34
        this.printer = new KaiserEnginePrinter(this.engine);
35
    }
36
37
    private void incrementRoundCounter() {
38 1 1. incrementRoundCounter : Replaced integer addition with subtraction → NO_COVERAGE
        round++;
39
    }
40
41
    /**
42
     * Start the game and allow player interactions until the maximum number of rounds is reached.
43
     */
44
    public void run() {
45 1 1. run : removed call to de/aikiit/game/kaiser/KaiserGame::intro → SURVIVED
        intro();
46 1 1. run : removed call to de/aikiit/game/kaiser/KaiserGame::status → SURVIVED
        status();
47 2 1. run : negated conditional → NO_COVERAGE
2. run : changed conditional boundary → NO_COVERAGE
        while (round < MAX_ROUNDS) {
48 1 1. run : removed call to de/aikiit/game/kaiser/KaiserGame::incrementRoundCounter → NO_COVERAGE
            incrementRoundCounter();
49 1 1. run : removed call to de/aikiit/game/kaiser/KaiserEngine::startNewRound → NO_COVERAGE
            engine.startNewRound();
50 1 1. run : removed call to de/aikiit/game/kaiser/KaiserGame::status → NO_COVERAGE
            status();
51 1 1. run : removed call to de/aikiit/game/kaiser/KaiserGame::actions → NO_COVERAGE
            actions();
52 1 1. run : removed call to de/aikiit/game/kaiser/KaiserEngine::finishRoundAfterActions → NO_COVERAGE
            engine.finishRoundAfterActions();
53
        }
54
55 1 1. run : removed call to de/aikiit/game/kaiser/KaiserGame::finish → NO_COVERAGE
        finish();
56 1 1. run : removed call to de/aikiit/game/kaiser/KaiserGame::byeByeBanner → NO_COVERAGE
        byeByeBanner();
57
    }
58
59
    /**
60
     * Shows information about the game flow and welcomes the player.
61
     */
62
    public void intro() {
63 1 1. intro : removed call to de/aikiit/game/kaiser/KaiserGame::banner → SURVIVED
        banner();
64 1 1. intro : removed call to java/io/PrintStream::println → SURVIVED
        System.out.println("Versuchen Sie die antike Stadt " + KaiserEnginePrinter.ANSI_YELLOW + ">SUMERIA<" + KaiserEnginePrinter.ANSI_RESET + " zu regieren!");
65 1 1. intro : removed call to java/io/PrintStream::println → SURVIVED
        System.out.println("Ihre Regierungszeit beträgt " + MAX_ROUNDS + " Jahre.");
66 1 1. intro : removed call to java/io/PrintStream::println → SURVIVED
        System.out.println("Nach jeweils einem Jahr erhalten Sie einen Bericht über die Entwicklung in der Stadt.");
67 1 1. intro : removed call to java/io/PrintStream::println → SURVIVED
        System.out.println("Dann werden wir weitersehen .......");
68 1 1. intro : removed call to java/io/PrintStream::println → SURVIVED
        System.out.println();
69
    }
70
71
    /**
72
     * Shows the game's banner.
73
     */
74
    public void banner() {
75
        // generated with the help of https://manytools.org/hacker-tools/ascii-banner/
76
        // font: banner
77 1 1. banner : removed call to java/io/PrintStream::println → SURVIVED
        System.out.println(KaiserEnginePrinter.ANSI_RED);
78 1 1. banner : removed call to java/io/PrintStream::println → SURVIVED
        System.out.println("""
79
                #    #                              \s
80
                #   #    ##   #  ####  ###### ##### \s
81
                #  #    #  #  # #      #      #    #\s
82
                ###    #    # #  ####  #####  #    #\s
83
                #  #   ###### #      # #      ##### \s
84
                #   #  #    # # #    # #      #   # \s
85
                #    # #    # #  ####  ###### #    #\s
86
                                                    \s
87
                                                                    """);
88 1 1. banner : removed call to java/io/PrintStream::println → SURVIVED
        System.out.println(KaiserEnginePrinter.ANSI_RESET);
89
    }
90
91
    /**
92
     * Shows console banner after the game is over.
93
     */
94
    public void byeByeBanner() {
95
        // generated with the help of https://manytools.org/hacker-tools/ascii-banner/
96
        // font: banner
97 1 1. byeByeBanner : removed call to java/io/PrintStream::println → SURVIVED
        System.out.println(KaiserEnginePrinter.ANSI_RED);
98 1 1. byeByeBanner : removed call to java/io/PrintStream::println → SURVIVED
        System.out.println("""
99
                ######                  ######                  #    #                              \s
100
                #     # #   # ######    #     # #   # ######    #   #    ##   #  ####  ###### ##### \s
101
                #     #  # #  #         #     #  # #  #         #  #    #  #  # #      #      #    #\s
102
                ######    #   #####     ######    #   #####     ###    #    # #  ####  #####  #    #\s
103
                #     #   #   #         #     #   #   #         #  #   ###### #      # #      ##### \s
104
                #     #   #   #         #     #   #   #         #   #  #    # # #    # #      #   # \s
105
                ######    #   ######    ######    #   ######    #    # #    # #  ####  ###### #    #\s
106
                                                                                                    \n                                                                           """);
107 1 1. byeByeBanner : removed call to java/io/PrintStream::println → SURVIVED
        System.out.println(KaiserEnginePrinter.ANSI_RESET);
108
    }
109
110
    /**
111
     * Shows the underlying status of the current round the player is in.
112
     */
113
    public void status() {
114 1 1. status : removed call to java/io/PrintStream::println → SURVIVED
        System.out.println(printer.getStatus(round));
115 1 1. status : removed call to java/io/PrintStream::println → SURVIVED
        System.out.println(printer.getYearResult(round));
116
    }
117
118
    /**
119
     * Performs user interactions.
120
     * The player can either
121
     * <ul>
122
     *     <li>buy or sell land</li>
123
     *     <li>feed the population</li>
124
     *     <li>perform agricultural operations per round.</li>
125
     * </ul>
126
     */
127
    public void actions() {
128 1 1. actions : removed call to java/io/PrintStream::println → SURVIVED
        System.out.println();
129 1 1. actions : removed call to java/io/PrintStream::println → SURVIVED
        System.out.println(KaiserEnginePrinter.ANSI_PURPLE + "#+#+#+#+ Was möchten Sie tun?" + KaiserEnginePrinter.ANSI_RESET);
130
131
        // only buy or sell is allowed
132 1 1. actions : negated conditional → NO_COVERAGE
        if (!KaiserActions.buy(this.engine)) {
133 1 1. actions : removed call to de/aikiit/game/kaiser/KaiserActions::sell → NO_COVERAGE
            KaiserActions.sell(this.engine);
134
        }
135
136 1 1. actions : removed call to de/aikiit/game/kaiser/KaiserActions::feed → NO_COVERAGE
        KaiserActions.feed(this.engine);
137 1 1. actions : removed call to de/aikiit/game/kaiser/KaiserActions::cultivate → NO_COVERAGE
        KaiserActions.cultivate(this.engine);
138
139 1 1. actions : removed call to java/io/PrintStream::println → NO_COVERAGE
        System.out.println();
140
    }
141
142
    /**
143
     * Shows results after the game is over.
144
     */
145
    public void finish() {
146 1 1. finish : removed call to java/io/PrintStream::println → SURVIVED
        System.out.println(printer.getResults());
147 1 1. finish : removed call to java/io/PrintStream::println → SURVIVED
        System.out.println(printer.evaluateRegency());
148
    }
149
}

Mutations

38

1.1
Location : incrementRoundCounter
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

45

1.1
Location : run
Killed by : none
removed call to de/aikiit/game/kaiser/KaiserGame::intro → SURVIVED
Covering tests

46

1.1
Location : run
Killed by : none
removed call to de/aikiit/game/kaiser/KaiserGame::status → SURVIVED
Covering tests

47

1.1
Location : run
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : run
Killed by : none
changed conditional boundary → NO_COVERAGE

48

1.1
Location : run
Killed by : none
removed call to de/aikiit/game/kaiser/KaiserGame::incrementRoundCounter → NO_COVERAGE

49

1.1
Location : run
Killed by : none
removed call to de/aikiit/game/kaiser/KaiserEngine::startNewRound → NO_COVERAGE

50

1.1
Location : run
Killed by : none
removed call to de/aikiit/game/kaiser/KaiserGame::status → NO_COVERAGE

51

1.1
Location : run
Killed by : none
removed call to de/aikiit/game/kaiser/KaiserGame::actions → NO_COVERAGE

52

1.1
Location : run
Killed by : none
removed call to de/aikiit/game/kaiser/KaiserEngine::finishRoundAfterActions → NO_COVERAGE

55

1.1
Location : run
Killed by : none
removed call to de/aikiit/game/kaiser/KaiserGame::finish → NO_COVERAGE

56

1.1
Location : run
Killed by : none
removed call to de/aikiit/game/kaiser/KaiserGame::byeByeBanner → NO_COVERAGE

63

1.1
Location : intro
Killed by : none
removed call to de/aikiit/game/kaiser/KaiserGame::banner → SURVIVED
Covering tests

64

1.1
Location : intro
Killed by : none
removed call to java/io/PrintStream::println → SURVIVED
Covering tests

65

1.1
Location : intro
Killed by : none
removed call to java/io/PrintStream::println → SURVIVED
Covering tests

66

1.1
Location : intro
Killed by : none
removed call to java/io/PrintStream::println → SURVIVED
Covering tests

67

1.1
Location : intro
Killed by : none
removed call to java/io/PrintStream::println → SURVIVED
Covering tests

68

1.1
Location : intro
Killed by : none
removed call to java/io/PrintStream::println → SURVIVED
Covering tests

77

1.1
Location : banner
Killed by : none
removed call to java/io/PrintStream::println → SURVIVED
Covering tests

78

1.1
Location : banner
Killed by : none
removed call to java/io/PrintStream::println → SURVIVED
Covering tests

88

1.1
Location : banner
Killed by : none
removed call to java/io/PrintStream::println → SURVIVED
Covering tests

97

1.1
Location : byeByeBanner
Killed by : none
removed call to java/io/PrintStream::println → SURVIVED
Covering tests

98

1.1
Location : byeByeBanner
Killed by : none
removed call to java/io/PrintStream::println → SURVIVED
Covering tests

107

1.1
Location : byeByeBanner
Killed by : none
removed call to java/io/PrintStream::println → SURVIVED
Covering tests

114

1.1
Location : status
Killed by : none
removed call to java/io/PrintStream::println → SURVIVED
Covering tests

115

1.1
Location : status
Killed by : none
removed call to java/io/PrintStream::println → SURVIVED
Covering tests

128

1.1
Location : actions
Killed by : none
removed call to java/io/PrintStream::println → SURVIVED
Covering tests

129

1.1
Location : actions
Killed by : none
removed call to java/io/PrintStream::println → SURVIVED
Covering tests

132

1.1
Location : actions
Killed by : none
negated conditional → NO_COVERAGE

133

1.1
Location : actions
Killed by : none
removed call to de/aikiit/game/kaiser/KaiserActions::sell → NO_COVERAGE

136

1.1
Location : actions
Killed by : none
removed call to de/aikiit/game/kaiser/KaiserActions::feed → NO_COVERAGE

137

1.1
Location : actions
Killed by : none
removed call to de/aikiit/game/kaiser/KaiserActions::cultivate → NO_COVERAGE

139

1.1
Location : actions
Killed by : none
removed call to java/io/PrintStream::println → NO_COVERAGE

146

1.1
Location : finish
Killed by : none
removed call to java/io/PrintStream::println → SURVIVED
Covering tests

147

1.1
Location : finish
Killed by : none
removed call to java/io/PrintStream::println → SURVIVED
Covering tests

Active mutators

Tests examined


Report generated by PIT 1.17.4