MCPcopy Create free account
hub / github.com/Apress/design-patterns-in-modern-cpp / Chess

Class Chess

Behavioral/TemplateMethod/template_method.cpp:31–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29};
30
31class Chess : public Game
32{
33public:
34 explicit Chess() : Game{ 2 } {}
35
36protected:
37 void start() override
38 {
39 cout << "Starting a game of chess with " << number_of_players << " players\n";
40 }
41
42 bool have_winner() override
43 {
44 return turns == max_turns;
45 }
46
47 void take_turn() override
48 {
49 cout << "Turn " << turns << " taken by player " << current_player << "\n";
50 turns++;
51 current_player = (current_player + 1) % number_of_players;
52 }
53
54 int get_winner() override
55 {
56 return current_player;
57 }
58
59private:
60 int turns{ 0 }, max_turns{ 10 };
61};
62
63int main()
64{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected