-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcommandManager.h
More file actions
45 lines (43 loc) · 1.15 KB
/
commandManager.h
File metadata and controls
45 lines (43 loc) · 1.15 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
#pragma once
#include <vector>
#include <string>
#include <iostream>
#include "robot.h"
#include "ship.h"
#include "goods.h"
#include "log.h"
#include <sstream>
// 这个类负责收集机器人和船只的指令,并最终统一输出。
class CommandManager
{
private:
std::vector<std::string> robotCommands; // 存储机器人指令
std::vector<std::string> shipCommands; // 存储船只指令
public:
void addRobotCommand(const std::string &command)
{
robotCommands.emplace_back(command);
}
void addShipCommand(const std::string &command)
{
shipCommands.emplace_back(command);
}
void outputCommands() const
{
std::ostringstream stream;
// 输出所有机器人指令
for (const auto &command : robotCommands)
stream << command << "\n";
// 输出所有船舶指令
for (const auto &command : shipCommands)
stream << command << "\n";
stream << "OK\n";
// 刷新输出缓冲区
std::cout << stream.str() << std::flush;
}
void clearCommands()
{
robotCommands.clear();
shipCommands.clear();
}
};