File indexing completed on 2024-02-18 04:04:53

0001 /*
0002     SPDX-FileCopyrightText: 2007 Paolo Capriotti <p.capriotti@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "message.h"
0008 
0009 HeaderMessage::HeaderMessage(const QString& protocolVersion,
0010                              const QString& clientName,
0011                              const QString& clientVersion,
0012                              const QString& clientDescription)
0013 : m_protocol_version(protocolVersion)
0014 , m_client_name(clientName)
0015 , m_client_version(clientVersion)
0016 , m_client_description(clientDescription)
0017 {
0018 }
0019 
0020 HeaderMessage::HeaderMessage()
0021 : m_protocol_version(QStringLiteral("0.1.0"))
0022 , m_client_name(QStringLiteral("KBattleship"))
0023 , m_client_version(QStringLiteral("4.0"))
0024 , m_client_description(QStringLiteral("The Naval Battle game"))
0025 {
0026 }
0027 
0028 void HeaderMessage::accept(MessageVisitor& visitor) const
0029 {
0030     visitor.visit(*this);
0031 }
0032 
0033 RejectMessage::RejectMessage(bool versionMismatch, const QString& reason)
0034 : m_version_mismatch(versionMismatch)
0035 , m_reason(reason)
0036 {
0037 }
0038 
0039 void RejectMessage::accept(MessageVisitor& visitor) const
0040 {
0041     visitor.visit(*this);
0042 }
0043 
0044 NickMessage::NickMessage(const QString& nickname)
0045 : m_nickname(nickname)
0046 {
0047 }
0048 
0049 void NickMessage::accept(MessageVisitor& visitor) const
0050 {
0051     visitor.visit(*this);
0052 }
0053 
0054 
0055 void BeginMessage::accept(MessageVisitor& visitor) const
0056 {
0057     visitor.visit(*this);
0058 }
0059 
0060 MoveMessage::MoveMessage(const Coord& move)
0061 : m_move(move)
0062 {
0063 }
0064 
0065 void MoveMessage::accept(MessageVisitor& visitor) const
0066 {
0067     visitor.visit(*this);
0068 }
0069 
0070 NotificationMessage::NotificationMessage(const Coord& move,
0071                                          bool hit, bool death,
0072                                          const Coord& start, const Coord& stop)
0073 : m_move(move)
0074 , m_hit(hit)
0075 , m_death(death)
0076 , m_start(start)
0077 , m_stop(stop)
0078 {
0079 }
0080 
0081 void NotificationMessage::accept(MessageVisitor& visitor) const
0082 {
0083     visitor.visit(*this);
0084 }
0085 
0086 ChatMessage::ChatMessage(const QString& nickname, const QString& chat)
0087 : m_nickname(nickname)
0088 , m_chat(chat)
0089 {
0090 }
0091 
0092 void ChatMessage::accept(MessageVisitor& visitor) const
0093 {
0094     visitor.visit(*this);
0095 }
0096 
0097 
0098 void RestartMessage::accept(MessageVisitor& visitor) const
0099 {
0100     visitor.visit(*this);
0101 }
0102 
0103 GameOverMessage::GameOverMessage()
0104 {
0105 }
0106 
0107 void GameOverMessage::addShip(const Coord& pos, int size, Ship::Direction direction)
0108 {
0109     m_ships.append(ShipInfo(pos, size, direction));
0110 }
0111 
0112 void GameOverMessage::accept(MessageVisitor& visitor) const
0113 {
0114     visitor.visit(*this);
0115 }
0116 
0117 GameOptionsMessage::GameOptionsMessage(const QString& enableAdjacentShips, const QString& oneOrSeveralShips,
0118     const BattleShipsConfiguration* configuration)
0119 : m_enabledAdjacentShipsString(enableAdjacentShips)
0120 , m_oneOrSeveralShipsString(oneOrSeveralShips)
0121 , m_battleShipsConfiguration(configuration)
0122 {
0123 }
0124 
0125 GameOptionsMessage::GameOptionsMessage(const bool enableAdjacentShips, const bool oneOrSeveralShips,
0126     const BattleShipsConfiguration &configuration)
0127     : m_enabledAdjacentShipsString(enableAdjacentShips ? QStringLiteral("true") : QStringLiteral("false"))
0128 , m_oneOrSeveralShipsString(oneOrSeveralShips ? QStringLiteral("true") : QStringLiteral("false"))
0129 , m_battleShipsConfiguration(new BattleShipsConfiguration(configuration))
0130 {
0131 }
0132 
0133 void GameOptionsMessage::accept(MessageVisitor& visitor) const
0134 {
0135     visitor.visit(*this);
0136 }