Browse Source

feat: improve oop design

仿照THUAI5的API设计模式
tags/0.1.0
DragonAura 3 years ago
parent
commit
e567d89f3e
1 changed files with 57 additions and 2 deletions
  1. +57
    -2
      CAPI/API/include/API.h

+ 57
- 2
CAPI/API/include/API.h View File

@@ -128,9 +128,24 @@ protected:
ILogic& logic;
};

class IHumanAPI : public IAPI
// 给Logic使用的IAPI接口,为了保证面向对象的设计模式
class IAPIForLogic : public IAPI
{
IAPIForLogic(ILogic& logic) :
IAPI(logic)
{
}
virtual void StartTimer() = 0;
virtual void EndTimer() = 0;
};

class IHumanAPI : public IAPIForLogic
{
public:
HumanAPI(ILogic& logic) :
IAPIForLogic(logic)
{
}
virtual std::future<bool> StartFixMachine() = 0;
virtual std::future<bool> EndFixMachine() = 0;
virtual std::future<bool> GetFixStatus() = 0;
@@ -141,9 +156,13 @@ public:
[[nodiscard]] virtual std::shared_ptr<const THUAI6::Human> GetSelfInfo() const = 0;
};

class IButcherAPI : public IAPI
class IButcherAPI : public IAPIForLogic
{
public:
ButcherAPI(Logic& logic) :
IAPIForLogic(logic)
{
}
virtual std::future<bool> Attack(double angleInRadian) = 0;
virtual std::future<bool> CarryHuman() = 0;
virtual std::future<bool> ReleaseHuman() = 0;
@@ -151,4 +170,40 @@ public:
[[nodiscard]] virtual std::shared_ptr<const THUAI6::Buthcer> GetSelfInfo() const = 0;
};

class HumanAPI : public IHumanAPI
{
public:
HumanAPI(Logic& logic) :
logic(logic)
{
}
};

class DebugHumanAPI : public IHumanAPI
{
public:
DebugHumanAPI(Logic& logic) :
logic(logic)
{
}
};

class ButhcerAPI : public IButcherAPI
{
public:
ButhcerAPI(Logic& logic) :
logic(logic)
{
}
};

class DebugButcherAPI : public IButcherAPI
{
public:
DebugButcherAPI(Logic& logic) :
logic(logic)
{
}
};

#endif

Loading…
Cancel
Save