1 /* $Id: GameEntity.java 30 2013-04-27 18:40:17Z mihlon $ */
2
3 //////////////////////////////////////////////////////////////////////////////
4 // //
5 // This program is free software: you can redistribute it and/or modify //
6 // it under the terms of the GNU General Public License as published by //
7 // the Free Software Foundation, either version 3 of the License, or //
8 // at your option any later version. //
9 // //
10 // This program is distributed in the hope that it will be useful, //
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
13 // GNU General Public License for more details. //
14 // //
15 // You should have received a copy of the GNU General Public License //
16 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
17 // //
18 //////////////////////////////////////////////////////////////////////////////
19
20 package cs.pancava.caltha.worlds;
21
22 import java.awt.Graphics2D;
23
24 /**
25 * <p><b>Tato trida definuje zakladni vlastnosti instance herniho sveta v editoru.</b></p>
26 *
27 * @author Milan Vaclavik<br />
28 * @version $Revision: 30 $<br />
29 * $LastChangedBy: mihlon $<br />
30 */
31 public abstract class GameEntity
32 {
33 /**
34 * Poradove cislo.
35 */
36 private int id;
37
38 /**
39 * X-ova souradnice vytvoreneho objektu.
40 */
41 private int locationX;
42
43 /**
44 * Y-ova souradnice vytvoreneho objektu.
45 */
46 private int locationY;
47
48 /**
49 * True - dany objekt je vybran (oznacen).
50 * False - dany objekt neni vybran (oznacen).
51 */
52 private Boolean selected;
53
54 /**
55 * Typ herniho objektu.
56 */
57 private int type;
58
59 /**
60 * Konstruktor - nastavuje zakladni vlastnosti vytvoreneho objektu.
61 * @param x int: X-ova souradnice vytvareneho objektu.
62 * @param y int: y-ova souradnice vytvareneho objektu.
63 * @param t int: Typ vytvoreneho objektu.
64 * @param counter int : Citac vytvorenych objektu.
65 */
66 public GameEntity(final int x, final int y, final int t, final int counter)
67 {
68 this.id = counter;
69 this.locationX = x;
70 this.locationY = y;
71 this.selected = false;
72 this.type = t;
73 }
74
75 /**
76 * Prazdny kontruktor pro takove objekty, ktere maji vzlastni vyznam.
77 * @param t int: Typ vytvoreneho objektu
78 */
79 public GameEntity(final int t)
80 {
81 this.type = t;
82 }
83
84 /**
85 * Reset counteru -> zaciname tvorit novy svet.
86 */
87 public static void resetCounter()
88 {
89 // TODO: Proc je tento prikaz zakomentovany ?
90 // GameEntity.counter = 0;
91 }
92
93 /**
94 * Abstraktni trida, ktera vraci stred objektu v ose X.
95 * @return int : Stred objektu v ose X.
96 */
97 public abstract int getCenterX();
98
99 /**
100 * Abstraktni trida, ktera vraci stred objektu v ose Y.
101 * @return int : Stred objektu v ose Y.
102 */
103 public abstract int getCenterY();
104
105 /**
106 * Abstraktni trida, ktera vraci nejaky objekt GameEntity.
107 * @return GameEntity : Objekt, ktery vracime.
108 */
109 public abstract GameEntity getFirstRoom();
110
111 /**
112 * Abstraktni trida, ktera vraci grafickou reprezentaci daneho objektu v editoru.
113 * @return : Graficke ztvarneni daneho obektu z vytvoreneho sveta.
114 */
115 //public abstract RectangularShape getGraphicsObject();
116 public abstract Object getGraphicsObject();
117
118 /**
119 * Snizi hodnotu ID o jedna.
120 */
121 public final void downID()
122 {
123 if (this.id > 0)
124 {
125 this.id -= 1;
126 }
127 }
128
129 /**
130 * Vraci ID obektu.
131 * @return int : ID vytvoreneho objektu.
132 */
133 public final int getId()
134 {
135 return this.id;
136 }
137
138 /**
139 * Vrati X-ovou souradnici daneho objektu.
140 * @return int : X-ova souradnice daneho objektu
141 */
142 public final int getLocationX()
143 {
144 return this.locationX;
145 }
146
147 /**
148 * Vrati Y-ovou souradnici daneho objektu.
149 * @return int : Y-ova souradnice daneho objektu
150 */
151 public final int getLocationY()
152 {
153 return this.locationY;
154 }
155
156 /**
157 * Abstraktni trida, ktera vraci nejaky objekt GameEntity.
158 * @return GameEntity : Objekt, ktery vracime.
159 */
160 public abstract GameEntity getSecondRoom();
161
162 /**
163 * Vraci stav objektu - zda byl nebo nebyl vybran (oznacen).
164 * @return Boolean : true - objekt byl vybran, jinak vraci false.
165 */
166 public final Boolean isSeleted()
167 {
168 return this.selected;
169 }
170
171 /**
172 * Nastavi X-ovou souradnici daneho objektu.
173 * @param x int : X-ova souradnice daneho objektu
174 */
175 public final void setLocationX(final int x)
176 {
177 this.locationX = x;
178 }
179
180 /**
181 * Nastavi Y-ovou souradnici daneho objektu.
182 * @param y int : Y-ova souradnice daneho objektu
183 */
184 public final void setLocationY(final int y)
185 {
186 this.locationY = y;
187 }
188
189 /**
190 * Nastavi stav objektu - vybran/nevybran.
191 * @param s Boolean : true - objekt byl vybran, jinak je false.
192 */
193 public final void setSelected(final Boolean s)
194 {
195 this.selected = s;
196 }
197
198 /**
199 * Zobrazi grafickou reprezentaci daneho obektu v editoru.
200 * @param g2 Graphics2D : Graficky kontext, do ktereho se bude kreslit.
201 */
202 public abstract void showGraphicsObject(Graphics2D g2);
203
204 /**
205 * Vrati typ herniho objektu.
206 * @return int : Typ herniho objektu.
207 */
208 public final int getType()
209 {
210 return this.type;
211 }
212 }