1 | using System; // Tämän tarpeellisuus pitäisi olla itsestäänselvyys |
---|
2 | using Jypeli; // Jypeli |
---|
3 | using Jypeli.ScreenObjects; // Jypeli.ScreenObjects |
---|
4 | using Jypeli.Assets; // Jypeli.Assets |
---|
5 | using System.Collections.Generic; // Jypelin tutoriaali |
---|
6 | using System.IO; // Streamreader vaatii tämän |
---|
7 | using System.Windows.Forms; // jotta voin näyttää msgboxeja |
---|
8 | using ALTKTechs; // Avaruuslaatikon moottorikomponentit |
---|
9 | using ALTKUnits; |
---|
10 | using ALTKCiv; |
---|
11 | using ALTKPromotions; |
---|
12 | using ALTKDiff; |
---|
13 | using ALTKAIBehaviour; |
---|
14 | using BaseRules; // Avaruuslaatikon sääntötiedosto, helpottaa modien tekemistä |
---|
15 | |
---|
16 | namespace ALTKTileEngine |
---|
17 | { |
---|
18 | public class Peli : Game |
---|
19 | { |
---|
20 | bool gamestarted = false; |
---|
21 | int currDiffLevel; // jotta tätä voidaan käyttää missä tahansa |
---|
22 | |
---|
23 | int[,] TerrainMap; // perusmaastokartta |
---|
24 | int[,] DTerrainMap; // erikoismaastokartta |
---|
25 | int[,] OwnershipMap; // ruudukon omistuskartta (kenen pelaajan hallinnassa on mikäkin ruutu) |
---|
26 | |
---|
27 | string Textpath; |
---|
28 | string OwnershipColorPath; |
---|
29 | |
---|
30 | int AmountofPlayers; |
---|
31 | |
---|
32 | // !!!!!!!!!!!!!!!!!!!!!!!!!!! |
---|
33 | // Pitänee tehdä vielä yksi ALTKSUnit-namespace ALTKCoreen. |
---|
34 | // Tämä sisältäisi tiedot yksiköiden omistajasta, yksikön perusyksiköstä ym. sekä myös karttakoordinaatit |
---|
35 | // (karttakoordinaatit säilyttää myös UnitMap, josta on helppo tarkastaa esim. liikuttaessa yksiköitä, onko ruudussa jo esim. vihollisyksiköitä. |
---|
36 | |
---|
37 | TextDisplay TileDisp; |
---|
38 | |
---|
39 | int kartanLeveys; |
---|
40 | int kartanKorkeus; |
---|
41 | |
---|
42 | // perusmaastotyypit |
---|
43 | const int Aavikko = 2, Tundra = 3, Vuoristo = 1, Lehtimetsa = 0; |
---|
44 | |
---|
45 | // erikoismaastotyypit |
---|
46 | const int Havumetsa = 2, Tyhja = 0, Kuusimetsa = 3; |
---|
47 | |
---|
48 | // Pelissä on kaksi eri tasoa, toisella perusmaasto ja toisella tarkempaa tietoa (esim. onko ruutu metsää ym.) |
---|
49 | GameObject[,] tile; |
---|
50 | GameObject[,] DTile; |
---|
51 | GameObject[,] TileOwnership; |
---|
52 | //Vector tileVector; |
---|
53 | |
---|
54 | Vector CamSpeedEast = new Vector(20.0, .0); |
---|
55 | Vector CamSpeedWest = new Vector(-20.0, .0); |
---|
56 | Vector CamSpeedNorth = new Vector(.0, 20.0); |
---|
57 | Vector CamSpeedSouth = new Vector(.0, -20.0); |
---|
58 | |
---|
59 | // Käytän ennemmin enemmän muistia kuin prosessoria, joten lasken nämä jo täällä |
---|
60 | int MouseScreenWidth; |
---|
61 | int MouseScreenHeight; |
---|
62 | int NegMouseScreenWidth; |
---|
63 | int NegMouseScreenHeight; |
---|
64 | protected override void Begin() |
---|
65 | { |
---|
66 | //SetWindowSize(true); |
---|
67 | Textpath = Application.StartupPath + "\\Content\\Textures\\"; |
---|
68 | OwnershipColorPath = Textpath + "Ownership\\"; |
---|
69 | InitRules(); |
---|
70 | InitStartMenu(); |
---|
71 | //InitControls(); |
---|
72 | //InitMap(); |
---|
73 | } |
---|
74 | void InitStartMenu() |
---|
75 | { |
---|
76 | Mouse.Enabled = true; |
---|
77 | Mouse.IsCursorVisible = true; |
---|
78 | |
---|
79 | GameObject TrainingButton = new GameObject(250, 30, Shapes.Rectangle); |
---|
80 | GameObject EasyButton = new GameObject(250, 30, Shapes.Rectangle); |
---|
81 | GameObject NormalButton = new GameObject(250, 30, Shapes.Rectangle); |
---|
82 | GameObject HardButton = new GameObject(250, 30, Shapes.Rectangle); |
---|
83 | GameObject VHardButton = new GameObject(250, 30, Shapes.Rectangle); |
---|
84 | GameObject NightmareButton = new GameObject(250, 30, Shapes.Rectangle); |
---|
85 | GameObject InsanityButton = new GameObject(250, 30, Shapes.Rectangle); |
---|
86 | |
---|
87 | for (int a = 0; a <= 6; a++) |
---|
88 | { |
---|
89 | if (a == 0) { SetDiffButton(TrainingButton, 0); } |
---|
90 | if (a == 1) { SetDiffButton(EasyButton, 1); } |
---|
91 | if (a == 2) { SetDiffButton(NormalButton, 2); } |
---|
92 | if (a == 3) { SetDiffButton(HardButton, 3); } |
---|
93 | if (a == 4) { SetDiffButton(VHardButton, 4); } |
---|
94 | if (a == 5) { SetDiffButton(NightmareButton, 5); } |
---|
95 | if (a == 6) { SetDiffButton(InsanityButton, 6); } |
---|
96 | } |
---|
97 | Mouse.ListenOn(TrainingButton, MouseButton.Left, Jypeli.ButtonState.Down, SelectDifficulty, "", 0); |
---|
98 | Mouse.ListenOn(EasyButton, MouseButton.Left, Jypeli.ButtonState.Down, SelectDifficulty, "", 1); |
---|
99 | Mouse.ListenOn(NormalButton, MouseButton.Left, Jypeli.ButtonState.Down, SelectDifficulty, "", 2); |
---|
100 | Mouse.ListenOn(HardButton, MouseButton.Left, Jypeli.ButtonState.Down, SelectDifficulty, "", 3); |
---|
101 | Mouse.ListenOn(VHardButton, MouseButton.Left, Jypeli.ButtonState.Down, SelectDifficulty, "", 4); |
---|
102 | Mouse.ListenOn(NightmareButton, MouseButton.Left, Jypeli.ButtonState.Down, SelectDifficulty, "", 5); |
---|
103 | Mouse.ListenOn(InsanityButton, MouseButton.Left, Jypeli.ButtonState.Down, SelectDifficulty, "", 6); |
---|
104 | } |
---|
105 | |
---|
106 | void SetDiffButton(GameObject diffbutton, int difflevel) |
---|
107 | { |
---|
108 | diffbutton.X = -250; |
---|
109 | diffbutton.Y = ((difflevel * -50) + 400); |
---|
110 | if (difflevel == 0) { diffbutton.Image = LoadImage(Textpath + "training"); } |
---|
111 | else if (difflevel == 1) { diffbutton.Image = LoadImage(Textpath + "easy"); } |
---|
112 | else if (difflevel == 2) { diffbutton.Image = LoadImage(Textpath + "normal"); } |
---|
113 | else if (difflevel == 3) { diffbutton.Image = LoadImage(Textpath + "hard"); } |
---|
114 | else if (difflevel == 4) { diffbutton.Image = LoadImage(Textpath + "vhard"); } |
---|
115 | else if (difflevel == 5) { diffbutton.Image = LoadImage(Textpath + "nightmare"); } |
---|
116 | else if (difflevel == 6) { diffbutton.Image = LoadImage(Textpath + "insanity"); } |
---|
117 | Add(diffbutton); |
---|
118 | //return diffbutton; |
---|
119 | } |
---|
120 | |
---|
121 | void SelectDifficulty(int difflevel) |
---|
122 | { |
---|
123 | ClearAll(); |
---|
124 | currDiffLevel = new int(); |
---|
125 | currDiffLevel = difflevel; |
---|
126 | InitControls(); |
---|
127 | InitMap(); |
---|
128 | gamestarted = true; |
---|
129 | } |
---|
130 | |
---|
131 | # region Kartan luominen |
---|
132 | |
---|
133 | void InitMap() |
---|
134 | { |
---|
135 | AmountofPlayers = new int(); |
---|
136 | Int32 i; |
---|
137 | Int32 j; |
---|
138 | string mLine; |
---|
139 | TextReader bReader; |
---|
140 | bReader = new StreamReader("Content\\Maps\\1\\base.txt"); |
---|
141 | //try |
---|
142 | //{ |
---|
143 | |
---|
144 | // Yleensä kartan kaksi ensimmäistä riviä ovat kommentteja |
---|
145 | bReader.ReadLine(); |
---|
146 | bReader.ReadLine(); |
---|
147 | |
---|
148 | kartanLeveys = Convert.ToInt32(bReader.ReadLine().Substring(9, 2)); |
---|
149 | kartanKorkeus = Convert.ToInt32(bReader.ReadLine().Substring(10, 2)); |
---|
150 | |
---|
151 | Int32 mapWidthJ = (kartanLeveys * 48) / 2; |
---|
152 | Int32 mapHeightJ = (kartanKorkeus * 48) / 2; |
---|
153 | |
---|
154 | bReader.ReadLine(); |
---|
155 | // Ladataan TerrainMapit muistiin myöhempää käyttöä varten |
---|
156 | |
---|
157 | TerrainMap = new int[kartanKorkeus, kartanLeveys]; |
---|
158 | DTerrainMap = new int[kartanKorkeus, kartanLeveys]; |
---|
159 | OwnershipMap = new int[kartanKorkeus, kartanLeveys]; |
---|
160 | InitTerrain(0); |
---|
161 | InitTerrain(1); |
---|
162 | InitTerrain(2); |
---|
163 | |
---|
164 | tile = new GameObject[kartanKorkeus, kartanLeveys]; |
---|
165 | DTile = new GameObject[kartanKorkeus, kartanLeveys]; |
---|
166 | TileOwnership = new GameObject[kartanKorkeus, kartanLeveys]; |
---|
167 | InitTerrainGraphics(0); |
---|
168 | InitTerrainGraphics(1); |
---|
169 | InitTerrainGraphics(2); |
---|
170 | |
---|
171 | // Koodi käännetty RGE:n VB.netistä |
---|
172 | // Asettaa ja piirtää pohjamaaston |
---|
173 | |
---|
174 | for (i = 0; i <= (kartanKorkeus - 1); i++) |
---|
175 | { |
---|
176 | mLine = bReader.ReadLine(); |
---|
177 | for (j = 0; j <= (kartanLeveys - 1); j++) |
---|
178 | { |
---|
179 | // MessageBox.Show(mLine + " " + j + " " + i); |
---|
180 | tile[i, j].Shape = Shapes.Rectangle; |
---|
181 | tile[i, j].X = (j * 48) - mapWidthJ; |
---|
182 | tile[i, j].Y = (i * 48) - mapHeightJ; |
---|
183 | TerrainMap[i, j] = getTerrainType(mLine.Substring(j, 1), 0, i, j); |
---|
184 | tile[i, j].Image = LoadImage(getTexture_fromTerrainType(TerrainMap[i, j], 0, i, j)); |
---|
185 | Add(tile[i, j]); |
---|
186 | |
---|
187 | //Mouse.ListenMovement(tile[i, j], showTileInfo_forTileDisp, null, i, j); |
---|
188 | // MessageBox.Show(Convert.ToString(TerrainMap[i, j])); |
---|
189 | } |
---|
190 | } |
---|
191 | |
---|
192 | // Luetaan karttatiedoston rivivälit |
---|
193 | bReader.ReadLine(); |
---|
194 | bReader.ReadLine(); |
---|
195 | |
---|
196 | // Rami 16. 6. 2010: Omistuskartta pitää sittenkin säätää ennen erikoismaastoa, sillä |
---|
197 | // kaupungit ja omistusrinki piirretään erikoismaaston asettamiskoodin kutsusta |
---|
198 | for (i = 0; i <= (kartanKorkeus - 1); i++) |
---|
199 | { |
---|
200 | for (j = 0; j <= (kartanLeveys - 1); j++) |
---|
201 | { |
---|
202 | // MessageBox.Show(mLine + " " + j + " " + i); |
---|
203 | TileOwnership[i, j].Shape = Shapes.Rectangle; |
---|
204 | TileOwnership[i, j].X = (j * 48) - mapWidthJ; |
---|
205 | TileOwnership[i, j].Y = (i * 48) - mapHeightJ; |
---|
206 | //TileOwnership[i, j].Image = LoadImage(Textpath + "nothing"); poistettu optimisoinnin takia |
---|
207 | //Add(TileOwnership[i, j]); eihän näitä tarvitse vielä lisätä, optimisointia |
---|
208 | //MessageBox.Show(TileOwnership[i, j].X + "x" + TileOwnership[i, j].Y + " " + DTile[i, j].X + "x" + DTile[i, j].Y + " Params: " + i + " " + j); |
---|
209 | // MessageBox.Show(Convert.ToString(TerrainMap[i, j])); |
---|
210 | } |
---|
211 | } |
---|
212 | |
---|
213 | // Asettaa ja piirtää erikoismaaston |
---|
214 | |
---|
215 | for (i = 0; i <= (kartanKorkeus - 1); i++) |
---|
216 | { |
---|
217 | mLine = bReader.ReadLine(); |
---|
218 | for (j = 0; j <= (kartanLeveys - 1); j++) |
---|
219 | { |
---|
220 | // MessageBox.Show(mLine + " " + j + " " + i); |
---|
221 | DTile[i, j].Shape = Shapes.Rectangle; |
---|
222 | DTile[i, j].X = (j * 48) - mapWidthJ; |
---|
223 | DTile[i, j].Y = (i * 48) - mapHeightJ; |
---|
224 | DTerrainMap[i, j] = getTerrainType(mLine.Substring(j, 1), 1, i, j); |
---|
225 | DTile[i, j].Image = LoadImage(getTexture_fromTerrainType(DTerrainMap[i, j], 1, i, j)); |
---|
226 | Add(DTile[i, j]); |
---|
227 | if (getTexture_fromTerrainType(DTerrainMap[i, j], 1, i, j).Contains("city")) |
---|
228 | { |
---|
229 | DrawOwnership(i, j); |
---|
230 | } |
---|
231 | //MessageBox.Show(DTile[i, j].X + "x" + DTile[i, j].Y); |
---|
232 | // MessageBox.Show(Convert.ToString(TerrainMap[i, j])); |
---|
233 | } |
---|
234 | } |
---|
235 | //catch |
---|
236 | //{ |
---|
237 | // MessageBox.Show("Map error!"); |
---|
238 | // bReader.Close(); |
---|
239 | // Exit(); |
---|
240 | //} |
---|
241 | bReader.Close(); |
---|
242 | //for (int playernumber = 0; playernumber <= 30; playernumber++) |
---|
243 | //{ |
---|
244 | // Rules.pCivs[playernumber].Color = setAIOwnershipColor(playernumber); |
---|
245 | //} |
---|
246 | Rules.pCivs[0].HumanPlayer = true; |
---|
247 | Rules.pCivs[0].Color = "red"; |
---|
248 | Level.BackgroundColor = Color.Black; |
---|
249 | InitGUI(); |
---|
250 | } |
---|
251 | |
---|
252 | private void InitGUI() |
---|
253 | { |
---|
254 | TileDisp = new TextDisplay(); |
---|
255 | TileDisp.X = Screen.Left + 120; |
---|
256 | TileDisp.Y = Screen.Bottom + 200; |
---|
257 | TileDisp.TextColor = Color.White; |
---|
258 | Add(TileDisp); |
---|
259 | } |
---|
260 | |
---|
261 | private void InitTerrain(int tlayer) |
---|
262 | { |
---|
263 | for (int a = 0; a <= (kartanKorkeus - 1); a++) |
---|
264 | { |
---|
265 | for (int b = 0; b <= (kartanLeveys - 1); b++) |
---|
266 | { |
---|
267 | GetTerrainLayer(tlayer)[a, b] = new int(); |
---|
268 | } |
---|
269 | } |
---|
270 | } |
---|
271 | |
---|
272 | int[,] GetTerrainLayer(int tlayer) |
---|
273 | { |
---|
274 | if (tlayer == 0) { return TerrainMap; } |
---|
275 | if (tlayer == 1) { return DTerrainMap; } |
---|
276 | if (tlayer == 2) { return OwnershipMap; } |
---|
277 | return TerrainMap; |
---|
278 | } |
---|
279 | |
---|
280 | private void InitTerrainGraphics(int tlayer) |
---|
281 | { |
---|
282 | for (int a = 0; a <= (kartanKorkeus - 1); a++) |
---|
283 | { |
---|
284 | for (int b = 0; b <= (kartanLeveys - 1); b++) |
---|
285 | { |
---|
286 | GetGraphicsLayer(tlayer)[a, b] = new PhysicsObject(48.0, 48.0); |
---|
287 | } |
---|
288 | } |
---|
289 | } |
---|
290 | |
---|
291 | GameObject[,] GetGraphicsLayer(int tlayer) |
---|
292 | { |
---|
293 | if (tlayer == 0) {return tile; } |
---|
294 | if (tlayer == 1) {return DTile; } |
---|
295 | if (tlayer == 2) { return TileOwnership; } |
---|
296 | return tile; |
---|
297 | } |
---|
298 | |
---|
299 | int getTerrainType(string ch, int terrainlayer, int i, int j) |
---|
300 | { |
---|
301 | if (terrainlayer == 0) |
---|
302 | { |
---|
303 | /*/ Maastotyypit |
---|
304 | * 0 = lehtimetsää |
---|
305 | * 1 = vuoristoa |
---|
306 | * 2 = aavikkoa |
---|
307 | * 3 = tundraa |
---|
308 | /*/ |
---|
309 | if (ch == " ") { return Lehtimetsa; } |
---|
310 | if (ch == "V") { return Vuoristo; } |
---|
311 | if (ch == "A") { return Aavikko; } |
---|
312 | if (ch == "T") { return Tundra; } |
---|
313 | } |
---|
314 | else if (terrainlayer == 1) |
---|
315 | { |
---|
316 | /*/ Erikoismaastotyypit |
---|
317 | * 0 = ei mitään |
---|
318 | * 1 = vuoristoa |
---|
319 | * 2 = metsää |
---|
320 | * 3 = kuusimetsää |
---|
321 | /*/ |
---|
322 | if (ch == " ") { return Tyhja; } |
---|
323 | if (ch == "M") { return Havumetsa; } |
---|
324 | if (ch == "V") { return Vuoristo; } |
---|
325 | if (ch == "K") { return Kuusimetsa; } |
---|
326 | try |
---|
327 | { |
---|
328 | //MessageBox.Show(TileOwnership[i, j].X + "x" + TileOwnership[i, j].Y + " " + DTile[i, j].X + "x" + DTile[i, j].Y + " Params: " + i + " " + j); |
---|
329 | int Playerstartloc; |
---|
330 | Playerstartloc = Convert.ToInt32(ch); |
---|
331 | AmountofPlayers = AmountofPlayers + 1; |
---|
332 | AddStartingCity(Playerstartloc, i, j); |
---|
333 | return (Playerstartloc + 10); |
---|
334 | } |
---|
335 | catch |
---|
336 | { |
---|
337 | } |
---|
338 | return Tyhja; |
---|
339 | } |
---|
340 | return 0; |
---|
341 | } |
---|
342 | |
---|
343 | private void DrawOwnership(int i, int j) |
---|
344 | { |
---|
345 | TileOwnership[i, j].Image = LoadImage(OwnershipColorPath + Rules.pCivs[OwnershipMap[i, j]].Color); |
---|
346 | Add(TileOwnership[i, j]); |
---|
347 | //MessageBox.Show(TileOwnership[i, j].X + "x" + TileOwnership[i, j].Y + " " + DTile[i, j].X + "x" + DTile[i, j].Y + " Params: " + i + " " + j); |
---|
348 | } |
---|
349 | |
---|
350 | private void AddStartingCity(int playernumber, int i, int j) |
---|
351 | { |
---|
352 | //MessageBox.Show(TileOwnership[i, j].X + "x" + TileOwnership[i, j].Y + " " + DTile[i, j].X + "x" + DTile[i, j].Y + " Params: " + i + " " + j); |
---|
353 | Rules.pCivs[playernumber].Production = Rules.pCivs[playernumber].Production + 10; |
---|
354 | Rules.pCivs[playernumber].NumberofCities = Rules.pCivs[playernumber].NumberofCities + 1; |
---|
355 | Rules.pCivs[playernumber].CityCoords[Rules.pCivs[playernumber].NumberofCities, 0] = i; |
---|
356 | Rules.pCivs[playernumber].CityCoords[Rules.pCivs[playernumber].NumberofCities, 1] = j; |
---|
357 | if (Rules.pCivs[playernumber].HumanPlayer == false) |
---|
358 | { |
---|
359 | Rules.pCivs[playernumber].Color = setAIOwnershipColor(playernumber); |
---|
360 | Rules.pCivs[playernumber].Enabled = true; |
---|
361 | Rules.pCivs[playernumber].Name = Rules.pCivs[playernumber].Color + " " + "Valtakunta"; |
---|
362 | } |
---|
363 | OwnershipMap[i, j] = playernumber; |
---|
364 | // 16. 6. 2010: Kutsutaanpa DrawOwnership sittenkin vasta kaupungin piirtämisen jälkeen (ks. InitMap ja DTilen asettaminen) |
---|
365 | //DrawOwnership(i, j); |
---|
366 | |
---|
367 | //DTile[i, j].Image = LoadImage("\\Content\\Textures\\cityancient"); |
---|
368 | } |
---|
369 | |
---|
370 | public string setAIOwnershipColor(int playernumber) |
---|
371 | { |
---|
372 | int c; |
---|
373 | int b; |
---|
374 | bool ColorInUse = false; |
---|
375 | for (b = 0; b <= 20; b++) |
---|
376 | { |
---|
377 | ColorInUse = false; |
---|
378 | for (c = 0; c <= 30; c++) |
---|
379 | { |
---|
380 | if (Rules.pCivs[c].Color == getOwnershipColor_fromInt(b)) |
---|
381 | { |
---|
382 | ColorInUse = true; |
---|
383 | } |
---|
384 | } |
---|
385 | if (ColorInUse == false) |
---|
386 | { |
---|
387 | return getOwnershipColor_fromInt(b); |
---|
388 | } |
---|
389 | } |
---|
390 | return getOwnershipColor_fromInt(0); |
---|
391 | } |
---|
392 | |
---|
393 | public string getOwnershipColor_fromInt(Int32 color) |
---|
394 | { |
---|
395 | if (color == 0) { return "aqua"; } |
---|
396 | if (color == 1) { return "beige"; } |
---|
397 | if (color == 2) { return "limegreen"; } |
---|
398 | if (color == 3) { return "orange"; } |
---|
399 | if (color == 4) { return "black"; } |
---|
400 | if (color == 5) { return "red"; } |
---|
401 | if (color == 6) { return "rustred"; } |
---|
402 | if (color == 7) { return "yellow"; } |
---|
403 | if (color == 8) { return "blue"; } |
---|
404 | if (color == 9) { return "darkblue"; } |
---|
405 | if (color == 10) { return "darkgreen"; } |
---|
406 | if (color == 11) { return "lightblue"; } |
---|
407 | if (color == 12) { return "purple"; } |
---|
408 | if (color == 13) { return "darkpurple"; } |
---|
409 | if (color == 14) { return "lightpurple"; } |
---|
410 | if (color == 15) { return "gold"; } |
---|
411 | if (color == 16) { return "silver"; } |
---|
412 | if (color == 17) { return "pink"; } |
---|
413 | if (color == 18) { return "teal"; } |
---|
414 | if (color == 19) { return "greenyellow"; } |
---|
415 | if (color == 20) { return "darkorange"; } |
---|
416 | if (color == 21) { return "white"; } |
---|
417 | if (color == 22) { return "darkgray"; } |
---|
418 | return "aqua"; |
---|
419 | } |
---|
420 | |
---|
421 | string getTexture_fromTerrainType(int terraintype, int terrainlayer, int i, int j) |
---|
422 | { |
---|
423 | if (terrainlayer == 0) |
---|
424 | { |
---|
425 | if (terraintype == Lehtimetsa) { return Application.StartupPath + "\\Content\\Textures\\grassland"; } |
---|
426 | if (terraintype == Vuoristo) { return Application.StartupPath + "\\Content\\Textures\\mountain"; } |
---|
427 | if (terraintype == Aavikko) { return Application.StartupPath + "\\Content\\Textures\\desert"; } |
---|
428 | if (terraintype == Tundra) { return Application.StartupPath + "\\Content\\Textures\\tundra"; } |
---|
429 | } |
---|
430 | else if (terrainlayer == 1) |
---|
431 | { |
---|
432 | if (terraintype == Tyhja) { return Application.StartupPath + "\\Content\\Textures\\nothing"; } |
---|
433 | if (terraintype == Vuoristo) { return Application.StartupPath + "\\Content\\Textures\\mountain"; } |
---|
434 | if (terraintype == Havumetsa) { return Application.StartupPath + "\\Content\\Textures\\forest"; } |
---|
435 | if (terraintype == Kuusimetsa) { return Application.StartupPath + "\\Content\\Textures\\spruceforest"; } |
---|
436 | // Jos terraintype on 10 tai enemmän, ruudussa on pelaajan kaupunki (ks. getTerrainType) |
---|
437 | if (terraintype >= 10) |
---|
438 | { |
---|
439 | if (TerrainMap[i, j] == Tundra) |
---|
440 | { |
---|
441 | return Application.StartupPath + "\\Content\\Textures\\cityancientTundra"; |
---|
442 | //DrawOwnership(i, j); |
---|
443 | } |
---|
444 | else |
---|
445 | { |
---|
446 | return Application.StartupPath + "\\Content\\Textures\\cityancient"; |
---|
447 | } |
---|
448 | } |
---|
449 | return Application.StartupPath + "\\Content\\Textures\\nothing"; |
---|
450 | } |
---|
451 | return Application.StartupPath + "\\Content\\Textures\\grassland.jpg"; |
---|
452 | } |
---|
453 | # endregion |
---|
454 | |
---|
455 | private void InitRules() |
---|
456 | { |
---|
457 | // Käytetään valmiiksi tehtyjä DLL-tiedostoja |
---|
458 | BaseRules.Rules.InitTechs(); |
---|
459 | BaseRules.Rules.InitUnits(); |
---|
460 | BaseRules.Rules.InitDifficulty(); |
---|
461 | BaseRules.Rules.InitCivs(); |
---|
462 | } |
---|
463 | |
---|
464 | protected override void Update(Time time) |
---|
465 | { |
---|
466 | base.Update(time); |
---|
467 | // Mouse.PositionOnScreen voisi olla vain positiivinen, eikä ruudun pitäisi jakautua keskeltä kahtia |
---|
468 | // negatiivisiin ja positiivisiin kokonaislukuihin |
---|
469 | |
---|
470 | if (gamestarted == true) |
---|
471 | { |
---|
472 | for (int i = 0; i <= (kartanKorkeus - 1); i++) |
---|
473 | { |
---|
474 | for (int j = 0; j <= (kartanLeveys - 1); j++) |
---|
475 | { |
---|
476 | if (Mouse.IsCursorOnGameObject(tile[i, j])) |
---|
477 | { |
---|
478 | TileDisp.Text = getTileInfo_forTileDisp(i, j); |
---|
479 | } |
---|
480 | //Mouse.ListenMovement(tile[i, j], showTileInfo_forTileDisp, null, i, j); |
---|
481 | // MessageBox.Show(Convert.ToString(TerrainMap[i, j])); |
---|
482 | } |
---|
483 | } |
---|
484 | //TileDisp.Text = getTileInfo_forTileDisp(Convert.ToInt32(Mouse.PositionOnWorld.X) / -48, Convert.ToInt32(Mouse.PositionOnWorld.Y) / 48); |
---|
485 | if (Mouse.PositionOnScreen.X > MouseScreenWidth) { MoveCamera(0); } |
---|
486 | else if (Mouse.PositionOnScreen.X < NegMouseScreenWidth) { MoveCamera(2); } |
---|
487 | else if (Mouse.PositionOnScreen.Y > MouseScreenHeight) { MoveCamera(1); } |
---|
488 | else if (Mouse.PositionOnScreen.Y < NegMouseScreenHeight) { MoveCamera(3); } |
---|
489 | } |
---|
490 | } |
---|
491 | |
---|
492 | public string getTileInfo_forTileDisp(int i, int j) |
---|
493 | { |
---|
494 | // Haetaan tiedot ruudulle |
---|
495 | string tileinfo; |
---|
496 | int Defensebonus = new int(); |
---|
497 | tileinfo = " "; |
---|
498 | //MessageBox.Show(i + " " + j); |
---|
499 | // Maaston perustiedot |
---|
500 | if (TerrainMap[i, j] == 0) |
---|
501 | { |
---|
502 | tileinfo = "Ruohotasankoa"; |
---|
503 | } |
---|
504 | else if (TerrainMap[i, j] == 1) |
---|
505 | { |
---|
506 | tileinfo = "Vuoristoa"; |
---|
507 | } |
---|
508 | else if (TerrainMap[i, j] == 2) |
---|
509 | { |
---|
510 | tileinfo = "Aavikkoa"; |
---|
511 | Defensebonus = Defensebonus - 25; |
---|
512 | } |
---|
513 | else if (TerrainMap[i, j] == 3) |
---|
514 | { |
---|
515 | tileinfo = "Tundraa"; |
---|
516 | Defensebonus = Defensebonus + 10; |
---|
517 | } |
---|
518 | |
---|
519 | // Erikoismaaston tiedot |
---|
520 | |
---|
521 | if (DTerrainMap[i, j] == 0) |
---|
522 | { |
---|
523 | } |
---|
524 | else if (DTerrainMap[i, j] == 1) |
---|
525 | { |
---|
526 | tileinfo = tileinfo + Environment.NewLine + "Vuoristoa" + Environment.NewLine + "Läpipääsemätön"; |
---|
527 | } |
---|
528 | else if (DTerrainMap[i, j] == 2) |
---|
529 | { |
---|
530 | tileinfo = tileinfo + Environment.NewLine + "Lehtimetsää"; |
---|
531 | Defensebonus = Defensebonus + 10; |
---|
532 | } |
---|
533 | else if (DTerrainMap[i, j] == 3) |
---|
534 | { |
---|
535 | tileinfo = tileinfo + Environment.NewLine + "Kuusimetsää"; |
---|
536 | Defensebonus = Defensebonus + 25; |
---|
537 | } |
---|
538 | if (Defensebonus != 0) |
---|
539 | { |
---|
540 | return tileinfo + Environment.NewLine + "Puolustusbonus: " + Defensebonus + "%"; |
---|
541 | } |
---|
542 | else |
---|
543 | { |
---|
544 | return tileinfo; |
---|
545 | } |
---|
546 | } |
---|
547 | |
---|
548 | private void InitControls() |
---|
549 | { |
---|
550 | Keyboard.Listen(Key.Right, Jypeli.ButtonState.Down, MoveCamera, null, 0); |
---|
551 | Keyboard.Listen(Key.Left, Jypeli.ButtonState.Down, MoveCamera, null, 2); |
---|
552 | Keyboard.Listen(Key.Up, Jypeli.ButtonState.Down, MoveCamera, null, 1); |
---|
553 | Keyboard.Listen(Key.Down, Jypeli.ButtonState.Down, MoveCamera, null, 3); |
---|
554 | Keyboard.Listen(Key.Tab, Jypeli.ButtonState.Down, ActivateDebug, null, 0); |
---|
555 | |
---|
556 | MouseScreenWidth = new int(); |
---|
557 | MouseScreenWidth = Convert.ToInt32(Peli.Screen.Width / 2) - 5; |
---|
558 | MouseScreenHeight = new int(); |
---|
559 | MouseScreenHeight = Convert.ToInt32(Peli.Screen.Height / 2) - 5; |
---|
560 | NegMouseScreenWidth = new int(); |
---|
561 | NegMouseScreenWidth = Convert.ToInt32(Peli.Screen.Width / -2) + 5; |
---|
562 | NegMouseScreenHeight = new int(); |
---|
563 | NegMouseScreenHeight = Convert.ToInt32(Peli.Screen.Height / -2) + 20; |
---|
564 | } |
---|
565 | |
---|
566 | private void ActivateDebug(int asd) |
---|
567 | { |
---|
568 | //Add(MessageDisplay); |
---|
569 | MessageDisplay.Add("DEBUG MODE ACTIVATED"); |
---|
570 | Keyboard.Listen(Key.A, Jypeli.ButtonState.Down, ShowColors, null); |
---|
571 | } |
---|
572 | |
---|
573 | private void ShowColors() |
---|
574 | { |
---|
575 | for (int a = 0; a <= (AmountofPlayers - 1); a++) |
---|
576 | { |
---|
577 | MessageDisplay.Add("Pelaaja: " + a + "; " + Rules.pCivs[a].Color); |
---|
578 | } |
---|
579 | } |
---|
580 | |
---|
581 | private void Mouse_Move() |
---|
582 | { |
---|
583 | // MessageBox.Show(Mouse.PositionOnScreen.X); |
---|
584 | } |
---|
585 | |
---|
586 | private void MoveCamera(Int32 dir) |
---|
587 | { |
---|
588 | if (gamestarted == false) { return; } |
---|
589 | if ((dir == 0) && (Camera.Position.X < (tile[kartanKorkeus - 1, kartanLeveys - 1].X) - (Peli.Screen.Width / 2))) |
---|
590 | { |
---|
591 | Camera.Move(CamSpeedEast); |
---|
592 | } |
---|
593 | if ((dir == 1) && (Camera.Position.Y < (tile[kartanKorkeus - 1, kartanLeveys - 1].Y) - ((Peli.Screen.Height / 2) - 12))) |
---|
594 | { |
---|
595 | Camera.Move(CamSpeedNorth); |
---|
596 | } |
---|
597 | if ((dir == 2) && (Camera.Position.X > (tile[0, 0].X) + (Peli.Screen.Width / 2))) |
---|
598 | { |
---|
599 | Camera.Move(CamSpeedWest); |
---|
600 | } |
---|
601 | if ((dir == 3) && (Camera.Position.Y > (tile[0, 0].Y) + (Peli.Screen.Height / 2))) |
---|
602 | { |
---|
603 | Camera.Move(CamSpeedSouth); |
---|
604 | } |
---|
605 | } |
---|
606 | } |
---|
607 | } |
---|