File indexing completed on 2024-09-01 03:53:00
0001 /* 0002 SPDX-FileCopyrightText: 2007 Paolo Capriotti <p.capriotti@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef ENTITY_H 0008 #define ENTITY_H 0009 0010 #include <QObject> 0011 0012 #include "sea.h" 0013 #include "seaview.h" 0014 #include "stats.h" 0015 #include "ships.h" 0016 0017 class Shot; 0018 class QIcon; 0019 0020 class Entity : public QObject 0021 { 0022 Q_OBJECT 0023 public: 0024 enum CompatibilityLevel 0025 { 0026 COMPAT_KBS3, 0027 COMPAT_KBS4 0028 }; 0029 protected: 0030 Sea::Player m_player; 0031 SeaView* m_seaview; 0032 QString m_nick; 0033 CompatibilityLevel m_level; 0034 Stats m_stats; 0035 // not owned by the entity 0036 const BattleShipsConfiguration* m_battleShipsConfiguration; 0037 bool m_restarted; 0038 0039 public: 0040 Entity(Sea::Player player, SeaView* seaview, const BattleShipsConfiguration* battleShipsConfiguration); 0041 ~Entity() override; 0042 virtual void notify(Sea::Player player, const Coord& c, const HitInfo& info) = 0; 0043 virtual void notifyChat(const Entity* entity, const QString& text) = 0; 0044 virtual void notifyNick(Sea::Player player, const QString& nick) = 0; 0045 virtual void hit(Shot* shot) = 0; 0046 virtual void notifyGameOptions() = 0; 0047 virtual void startPlacing() = 0; 0048 virtual void start() = 0; 0049 virtual void startPlaying() { } 0050 virtual void notifyReady(Sea::Player) { } 0051 virtual void notifyShips(Sea::Player) { } 0052 virtual void notifyGameOver(Sea::Player) { } 0053 0054 Stats* stats(); 0055 0056 virtual Sea::Player player() const { return m_player; } 0057 0058 QString nick() const { return m_nick; } 0059 CompatibilityLevel compatibilityLevel() const { return m_level; } 0060 virtual QIcon icon() const = 0; 0061 virtual void setNick(const QString& nick); 0062 Q_SIGNALS: 0063 void shoot(int player, const Coord& c); 0064 void shipsPlaced(); 0065 void ready(int player); 0066 void chat(const QString& text); 0067 void nickChanged(int player, const QString& nickname); 0068 void compatibility(int level); 0069 void abortGame(); 0070 void restartPlacingShips(Sea::Player player); 0071 void gameOptionsInterchanged(); 0072 public Q_SLOTS: 0073 virtual void setCompatibilityLevel(int level); 0074 virtual void notifyAbort() = 0; 0075 virtual void notifyRestartPlacing(Sea::Player player) = 0; 0076 }; 0077 0078 #endif // ENTITY_H 0079