-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.h
More file actions
45 lines (38 loc) · 1.33 KB
/
Copy pathcli.h
File metadata and controls
45 lines (38 loc) · 1.33 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 <QString>
#include "gamemodel.h"
// 命令行会话:把棋盘渲染成文本,解析并执行用户输入的命令。
// 与 GUI 共享同一个 GameModel,所有游戏操作(解雾/转向/移动/攻击/跳过/选舰/开局)都能通过命令完成。
class CliSession
{
public:
explicit CliSession(GameModel& model);
QString start(); // 开始新游戏并返回初始画面
QString execute(const QString& line); // 执行一条命令,返回输出(空串表示退出)
bool quit() const { return m_quit; }
private:
QString renderBoard() const;
QString renderStatus() const;
QString renderShips() const;
QString renderJson() const;
QString help() const;
QChar cellChar(int r, int c) const;
QString dirName(int dir) const;
QString afterAction(const QString& msg);
// 各命令处理
QString cmdSelect(const QStringList& t);
QString cmdReveal(const QStringList& t);
QString cmdTurn(const QStringList& t);
QString cmdMove();
QString cmdAttack(const QStringList& t);
QString cmdPass();
QString cmdUndo();
QString cmdRedo();
QString cmdLog();
QString cmdSave(const QStringList& t);
QString cmdAi();
QString cmdSurrender();
GameModel& m_model;
int m_selected = -1;
bool m_quit = false;
};