-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoggingObserverDriver.cpp
More file actions
54 lines (41 loc) · 1.32 KB
/
LoggingObserverDriver.cpp
File metadata and controls
54 lines (41 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* @file LoggingObserverDriver.cpp
* @brief Demonstrates Part 5: Game Log Observer integration.
*
* This driver tests that Command, CommandProcessor, Order,
* OrdersList, and GameEngine correctly inherit from Subject
* and ILoggable, and call Notify(this) when key events occur.
*/
#include "LoggingObserver.h"
#include "CommandProcessing.h"
#include "Orders.h"
#include "GameEngine.h"
#include <iostream>
using namespace std;
/**
* @brief Test function for the Game Log Observer system.
*/
void testLoggingObserver() {
cout << "=== Testing Game Log Observer ===\n\n";
LogObserver logger;
// Attach observer to all key subjects
CommandProcessor cp;
cp.Attach(&logger);
Command* cmd = new Command("loadmap world.map", " ");
cmd->Attach(&logger);
OrdersList orders;
orders.Attach(&logger);
Order* order = new Deploy();
order->Attach(&logger);
GameEngine engine;
engine.Attach(&logger);
// Trigger loggable actions
cp.saveCommand(cmd);
cmd->saveEffect("Map successfully loaded.");
orders.add(order);
order->execute();
engine.transition("assignreinforcement");
cout << "Log entries written to gamelog.txt.\n\n";
cout << "=== Game Log Observer Testing Complete ===\n\n";
delete order;
}