From a52672ea26430761c3ce0737e93f0626ca66a011 Mon Sep 17 00:00:00 2001 From: Yann Dirson Date: Sun, 20 Apr 2008 21:52:42 +0200 Subject: [PATCH] Make component interfaces inherit Component. --- src/core/behaviour.h | 3 ++- src/core/state.h | 3 ++- src/variants/chess/behaviour.cpp | 11 +++++++++-- src/variants/chess/behaviour.h | 9 ++++++--- src/variants/chess/chess.cpp | 7 +++++-- src/variants/chess/state.cpp | 3 +-- src/variants/chess/state.h | 4 +--- src/variants/crazyhouse/behaviour.h | 1 + src/variants/crazyhouse/state.h | 3 +-- 9 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/core/behaviour.h b/src/core/behaviour.h index c5f345d..bfecefb 100644 --- a/src/core/behaviour.h +++ b/src/core/behaviour.h @@ -10,6 +10,7 @@ #ifndef CORE__BEHAVIOUR_H #define CORE__BEHAVIOUR_H +#include "component.h" #include "export.h" #include "point.h" @@ -20,7 +21,7 @@ class Move; /** * @brief Encapsulates general rules on piece movement. */ -class TAGUA_EXPORT IBehaviour { +class TAGUA_EXPORT IBehaviour: public Component { public: virtual ~IBehaviour(); diff --git a/src/core/state.h b/src/core/state.h index d587586..e4714fe 100644 --- a/src/core/state.h +++ b/src/core/state.h @@ -11,6 +11,7 @@ #ifndef CORE__STATE_H #define CORE__STATE_H +#include "component.h" #include "taguaobject.h" class Board; @@ -29,7 +30,7 @@ class Move; * A State component also provides methods to setup the initial * configuration and to make a move. */ -class TAGUA_EXPORT IState { +class TAGUA_EXPORT IState: public Component { public: virtual ~IState(); diff --git a/src/variants/chess/behaviour.cpp b/src/variants/chess/behaviour.cpp index 4c60f7f..8ab8384 100644 --- a/src/variants/chess/behaviour.cpp +++ b/src/variants/chess/behaviour.cpp @@ -16,6 +16,11 @@ namespace Chess { +Behaviour::Behaviour() +: IBehaviour() { } +Behaviour::Behaviour(const Behaviour& other) +: IBehaviour() { } + void Behaviour::captureOn(IState* state, const Point& square) const { state->board()->set(square, Piece()); } @@ -48,6 +53,8 @@ Point Behaviour::direction(const IColor* player) const { return Point(0, player == White::self() ? -1 : 1); } -} // namespace Chess - +IBehaviour* Behaviour::clone() const { + return new Behaviour(*this); +} +} // namespace Chess diff --git a/src/variants/chess/behaviour.h b/src/variants/chess/behaviour.h index 74662cc..ff00a49 100644 --- a/src/variants/chess/behaviour.h +++ b/src/variants/chess/behaviour.h @@ -11,22 +11,25 @@ #define CHESS__BEHAVIOUR_H #include -#include namespace Chess { -class Behaviour : public Component, public IBehaviour { +class Behaviour : public IBehaviour { Q_OBJECT public: + Behaviour(); + Behaviour(const Behaviour& other); + virtual void captureOn(IState* state, const Point& square) const; virtual void move(IState* state, const Move& m) const; virtual void advanceTurn(IState* state) const; virtual Point captureSquare(const IState* state, const Move& m) const; virtual const IColor* opponent(const IColor* player) const; virtual Point direction(const IColor* player) const; +public Q_SLOTS: + virtual IBehaviour* clone() const; }; } // namespace Chess #endif // CHESS__BEHAVIOUR_H - diff --git a/src/variants/chess/chess.cpp b/src/variants/chess/chess.cpp index a88fef2..ba15e82 100644 --- a/src/variants/chess/chess.cpp +++ b/src/variants/chess/chess.cpp @@ -39,8 +39,11 @@ extern "C" KDE_EXPORT Repository* taguachess_initrepo(IVariantLoader*) { CastlingRules* castling_rules = new CastlingRules; repo->addComponent("extra/castling_rules", castling_rules); - - repo->addComponent("state", new State(new Behaviour, castling_rules, Point(8, 8))); + + Behaviour* behaviour = new Behaviour; + repo->addComponent("behaviour", behaviour); + + repo->addComponent("state", new State(behaviour, castling_rules, Point(8, 8))); Validator* validator = new Validator; repo->addComponent("validator", validator); repo->addComponent("animator_factory", new AnimatorFactory); diff --git a/src/variants/chess/state.cpp b/src/variants/chess/state.cpp index 7065a21..27ee75b 100644 --- a/src/variants/chess/state.cpp +++ b/src/variants/chess/state.cpp @@ -32,8 +32,7 @@ State::State(const IBehaviour* behaviour, } State::State(const State& other) -: Component() -, IState() +: IState() , m_board(other.m_board) , m_flags(other.m_flags) , m_turn(other.m_turn) diff --git a/src/variants/chess/state.h b/src/variants/chess/state.h index 4e591bc..e9d84cb 100644 --- a/src/variants/chess/state.h +++ b/src/variants/chess/state.h @@ -12,7 +12,6 @@ #define CHESS__STATE_H #include -#include #include #include #include @@ -24,7 +23,7 @@ namespace Chess { class ICastlingRules; -class State : public Component, public IState { +class State : public IState { Q_OBJECT Board m_board; TaguaObject m_flags; @@ -77,4 +76,3 @@ public Q_SLOTS: } // namespace Chess #endif // CHESS__STATE_H - diff --git a/src/variants/crazyhouse/behaviour.h b/src/variants/crazyhouse/behaviour.h index 42c066b..0c68701 100644 --- a/src/variants/crazyhouse/behaviour.h +++ b/src/variants/crazyhouse/behaviour.h @@ -15,6 +15,7 @@ namespace Crazyhouse { class Behaviour : public Delegators::Behaviour { +Q_OBJECT public: Behaviour(const IBehaviour* behaviour); diff --git a/src/variants/crazyhouse/state.h b/src/variants/crazyhouse/state.h index e0ebace..3d83305 100644 --- a/src/variants/crazyhouse/state.h +++ b/src/variants/crazyhouse/state.h @@ -11,7 +11,6 @@ #define CRAZYHOUSE__STATE_H #include -#include #include class IPoolCollection; @@ -21,7 +20,7 @@ class IPoolCollection; */ namespace Crazyhouse { -class State : public Component, public Delegators::State { +class State : public Delegators::State { Q_OBJECT IPoolCollection* m_pools; public: -- 2.11.4.GIT