~keith-penguin/kdegames/trunk

« back to all changes in this revision

Viewing changes to kbattleship/src/message.cpp

  • Committer: Keith Worrell
  • Date: 2009-03-18 05:35:28 UTC
  • Revision ID: keith.worrell@gmail.com-20090318053528-mx6x9c0ngmg0kg6p
imported project

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com>
 
3
            
 
4
  This program is free software; you can redistribute it and/or modify
 
5
  it under the terms of the GNU General Public License as published by
 
6
  the Free Software Foundation; either version 2 of the License, or
 
7
  (at your option) any later version.
 
8
*/
 
9
 
 
10
#include "message.h"
 
11
 
 
12
HeaderMessage::HeaderMessage(const QString& protocolVersion,
 
13
                             const QString& clientName,
 
14
                             const QString& clientVersion,
 
15
                             const QString& clientDescription)
 
16
: m_protocol_version(protocolVersion)
 
17
, m_client_name(clientName)
 
18
, m_client_version(clientVersion)
 
19
, m_client_description(clientDescription)
 
20
{
 
21
}
 
22
 
 
23
HeaderMessage::HeaderMessage()
 
24
: m_protocol_version("0.1.0")
 
25
, m_client_name("KBattleship")
 
26
, m_client_version("4.0")
 
27
, m_client_description("The KDE Battleship clone")
 
28
{
 
29
}
 
30
 
 
31
void HeaderMessage::accept(MessageVisitor& visitor) const
 
32
{
 
33
    visitor.visit(*this);
 
34
}
 
35
 
 
36
RejectMessage::RejectMessage(bool versionMismatch, const QString& reason)
 
37
: m_version_mismatch(versionMismatch)
 
38
, m_reason(reason)
 
39
{
 
40
}
 
41
 
 
42
void RejectMessage::accept(MessageVisitor& visitor) const
 
43
{
 
44
    visitor.visit(*this);
 
45
}
 
46
 
 
47
NickMessage::NickMessage(const QString& nickname)
 
48
: m_nickname(nickname)
 
49
{
 
50
}
 
51
 
 
52
void NickMessage::accept(MessageVisitor& visitor) const
 
53
{
 
54
    visitor.visit(*this);
 
55
}
 
56
 
 
57
 
 
58
void BeginMessage::accept(MessageVisitor& visitor) const
 
59
{
 
60
    visitor.visit(*this);
 
61
}
 
62
 
 
63
MoveMessage::MoveMessage(const Coord& move)
 
64
: m_move(move)
 
65
{
 
66
}
 
67
 
 
68
void MoveMessage::accept(MessageVisitor& visitor) const
 
69
{
 
70
    visitor.visit(*this);
 
71
}
 
72
 
 
73
NotificationMessage::NotificationMessage(const Coord& move,
 
74
                                         bool hit, bool death,
 
75
                                         const Coord& start, const Coord& stop)
 
76
: m_move(move)
 
77
, m_hit(hit)
 
78
, m_death(death)
 
79
, m_start(start)
 
80
, m_stop(stop)
 
81
{
 
82
}
 
83
 
 
84
void NotificationMessage::accept(MessageVisitor& visitor) const
 
85
{
 
86
    visitor.visit(*this);
 
87
}
 
88
 
 
89
ChatMessage::ChatMessage(const QString& nickname, const QString& chat)
 
90
: m_nickname(nickname)
 
91
, m_chat(chat)
 
92
{
 
93
}
 
94
 
 
95
void ChatMessage::accept(MessageVisitor& visitor) const
 
96
{
 
97
    visitor.visit(*this);
 
98
}
 
99
 
 
100
 
 
101
void RestartMessage::accept(MessageVisitor& visitor) const
 
102
{
 
103
    visitor.visit(*this);
 
104
}
 
105
 
 
106
GameOverMessage::GameOverMessage()
 
107
{
 
108
}
 
109
 
 
110
void GameOverMessage::addShip(const Coord& pos, int size, Ship::Direction direction)
 
111
{
 
112
    m_ships.append(ShipInfo(pos, size, direction));
 
113
}
 
114
 
 
115
void GameOverMessage::accept(MessageVisitor& visitor) const
 
116
{
 
117
    visitor.visit(*this);
 
118
}
 
119
 
 
120