1 | /********************************************************************************** |
---|---|
2 | This file is part of the game 'KTron' |
3 | |
4 | Copyright (C) 1998-2000 by Matthias Kiefer <matthias.kiefer@gmx.de> |
5 | Copyright (C) 2005 Benjamin C. Meyer <ben at meyerhome dot net> |
6 | Copyright (C) 2008-2009 Stas Verberkt <legolas at legolasweb dot nl> |
7 | |
8 | This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by |
10 | the Free Software Foundation; either version 2 of the License, or |
11 | (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
21 | |
22 | *******************************************************************************/ |
23 | |
24 | #include "snakepart.h" |
25 | |
26 | #include <KDebug> |
27 | |
28 | SnakePart::SnakePart(int playerNumber) : Object(ObjectType::SnakePart) |
29 | { |
30 | initialize(); |
31 | |
32 | this->m_playerNumber = playerNumber; |
33 | } |
34 | |
35 | // |
36 | // Init |
37 | // |
38 | |
39 | void SnakePart::initialize() |
40 | { |
41 | setPartType(SnakePartType::Empty); |
42 | setPartTop(false); |
43 | setPartBottom(false); |
44 | setPartLeft(false); |
45 | setPartRight(false); |
46 | } |
47 | |
48 | // |
49 | // Getters / Setters |
50 | // |
51 | |
52 | int SnakePart::getPlayerNumber() |
53 | { |
54 | return this->m_playerNumber; |
55 | } |
56 | |
57 | SnakePartType::Types SnakePart::getPartType() |
58 | { |
59 | return m_partType; |
60 | } |
61 | |
62 | void SnakePart::setPartType(SnakePartType::Types type) |
63 | { |
64 | m_partType = type; |
65 | } |
66 | |
67 | bool SnakePart::getPartTop() |
68 | { |
69 | return m_partTop; |
70 | } |
71 | |
72 | void SnakePart::setPartTop(bool value) |
73 | { |
74 | m_partTop = value; |
75 | } |
76 | |
77 | bool SnakePart::getPartBottom() |
78 | { |
79 | return m_partBottom; |
80 | } |
81 | |
82 | void SnakePart::setPartBottom(bool value) |
83 | { |
84 | m_partBottom = value; |
85 | } |
86 | |
87 | bool SnakePart::getPartLeft() |
88 | { |
89 | return m_partLeft; |
90 | } |
91 | |
92 | void SnakePart::setPartLeft(bool value) |
93 | { |
94 | m_partLeft = value; |
95 | } |
96 | |
97 | bool SnakePart::getPartRight() |
98 | { |
99 | return m_partRight; |
100 | } |
101 | |
102 | void SnakePart::setPartRight(bool value) |
103 | { |
104 | m_partRight = value; |
105 | } |
106 | |
107 | // |
108 | // Decode type |
109 | // |
110 | |
111 | void SnakePart::generateSVGName() |
112 | { |
113 | setSVGName(decodePart()); |
114 | } |
115 | |
116 | QString SnakePart::decodePart() |
117 | { |
118 | QString name; |
119 | |
120 | // Player |
121 | if (getPlayerNumber() == 0) |
122 | { |
123 | name = QLatin1String( "tron1-"); |
124 | } |
125 | else if (getPlayerNumber() == 1) |
126 | { |
127 | name = QLatin1String( "tron2-"); |
128 | } |
129 | |
130 | // Heads (or tails) |
131 | if (getPartType() == SnakePartType::Head) |
132 | { |
133 | if (getPartTop() && getPartLeft() && getPartRight()) |
134 | { |
135 | name += QLatin1String( "head-north"); |
136 | } |
137 | else if (getPartBottom() && getPartLeft() && getPartRight()) |
138 | { |
139 | name += QLatin1String( "head-south"); |
140 | } |
141 | else if (getPartTop() && getPartBottom() && getPartLeft()) |
142 | { |
143 | name += QLatin1String( "head-west"); |
144 | } |
145 | else if (getPartTop() && getPartBottom() && getPartRight()) |
146 | { |
147 | name += QLatin1String( "head-east"); |
148 | } |
149 | } |
150 | else if (getPartType() == SnakePartType::Hole) |
151 | { |
152 | if (getPartTop() && getPartLeft() && getPartRight()) |
153 | { |
154 | name += QLatin1String( "tail-south"); |
155 | } |
156 | else if (getPartBottom() && getPartLeft() && getPartRight()) |
157 | { |
158 | name += QLatin1String( "tail-north"); |
159 | } |
160 | else if (getPartTop() && getPartBottom() && getPartLeft()) |
161 | { |
162 | name += QLatin1String( "tail-east"); |
163 | } |
164 | else if (getPartTop() && getPartBottom() && getPartRight()) |
165 | { |
166 | name += QLatin1String( "tail-west"); |
167 | } |
168 | } |
169 | else if (getPartType() == SnakePartType::Tail) |
170 | { |
171 | if (getPartTop() && getPartLeft() && getPartRight()) |
172 | { |
173 | name += QLatin1String( "tail-south2"); |
174 | } |
175 | else if (getPartBottom() && getPartLeft() && getPartRight()) |
176 | { |
177 | name += QLatin1String( "tail-north2"); |
178 | } |
179 | else if (getPartTop() && getPartBottom() && getPartLeft()) |
180 | { |
181 | name += QLatin1String( "tail-east2"); |
182 | } |
183 | else if (getPartTop() && getPartBottom() && getPartRight()) |
184 | { |
185 | name += QLatin1String( "tail-west2"); |
186 | } |
187 | } |
188 | else if (getPartType() == SnakePartType::Body) |
189 | { |
190 | // Bodys |
191 | if (getPartTop() && getPartBottom()) |
192 | { |
193 | name += QLatin1String( "body-h"); |
194 | } |
195 | else if (getPartLeft() && getPartRight()) |
196 | { |
197 | name += QLatin1String( "body-v"); |
198 | } |
199 | else if (getPartLeft() && getPartTop()) |
200 | { |
201 | name += QLatin1String( "body-nw"); |
202 | } |
203 | else if (getPartTop() && getPartRight()) |
204 | { |
205 | name += QLatin1String( "body-ne"); |
206 | } |
207 | else if (getPartLeft() && getPartBottom()) |
208 | { |
209 | name += QLatin1String( "body-sw"); |
210 | } |
211 | else if (getPartBottom() && getPartRight()) |
212 | { |
213 | name += QLatin1String( "body-se"); |
214 | } |
215 | } |
216 | |
217 | return name; |
218 | } |
219 |