- Timestamp:
- 2010-08-05 14:55:54 (13 years ago)
- Location:
- 2010/31/mimakrja/SeaWar
- Files:
-
- 2 added
- 2 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
2010/31/mimakrja/SeaWar/Peli.cs
r1597 r1623 1 1 using System; 2 using System.Collections.Generic; 2 3 using Jypeli; 3 4 using Jypeli.Widgets; 4 5 using Jypeli.Assets; 5 6 7 public class LaivanPala : GameObject 8 { 9 public bool Ammuttu; 10 11 public LaivanPala(double leveys, double korkeus) 12 : base(leveys, korkeus) 13 { 14 Ammuttu = false; 15 } 16 17 public void Ammu() 18 { 19 this.Ammuttu = true; 20 this.Color = Color.Blue; 21 } 22 } 23 6 24 public class Peli : Game 7 25 { 26 const int ruudunLeveys = 50; 27 const int ruudunKorkeus = 50; 28 Vector kursorinAllaOlevaPiste; 29 GameObject kursori; 30 List<LaivanPala> pelaajan1Laivat; 31 List<LaivanPala> pelaajan2Laivat; 32 List<GameObject> pelaajan1AmmututPisteet; 33 List<GameObject> pelaajan2AmmututPisteet; 34 Level pelaaja1Kentta; 35 Level pelaaja2Kentta; 36 37 int vuorossaOlevaPelaaja = 1; 38 8 39 protected override void Begin() 9 40 { 10 41 LuoKentta(); 42 LisaaKontrollit(); 43 Camera.ZoomToLevel(); 44 } 45 46 void LisaaKontrollit() 47 { 48 kursori = new GameObject(10, 10); 49 kursori.Color = Color.Red; 50 Add(kursori, 1); 51 Mouse.IsCursorVisible = true; 52 Mouse.ListenMovement(0.1, LiikutaTahtainta, "Liikuta tähtäintä"); 53 Mouse.Listen(MouseButton.Left, ButtonState.Pressed, Ammu, "Ammu"); 54 } 55 56 void LiikutaTahtainta(AnalogState hiirenTila) 57 { 58 double jjX = (Level.Left + Mouse.PositionOnWorld.X) % ruudunLeveys; 59 double lahinX = jjX; 60 double jjY = (Mouse.PositionOnWorld.Y) % ruudunKorkeus; 61 double lahinY = jjY; 62 if (jjX < 25) lahinX = Mouse.PositionOnWorld.X - jjX; 63 if (jjX >= 25) lahinX = Mouse.PositionOnWorld.X + (ruudunLeveys - jjX); 64 if (jjY < 25) lahinY = Mouse.PositionOnWorld.Y - jjY; 65 if (jjY >= 25) lahinY = Mouse.PositionOnWorld.Y + (ruudunKorkeus - jjY); 66 kursori.X = lahinX - 25; 67 kursori.Y = lahinY - 25; 68 kursorinAllaOlevaPiste.X = kursori.X; 69 kursorinAllaOlevaPiste.Y = kursori.Y; 70 } 71 72 void PiilotaKentta(int vuorossaOlevaPelaaja) 73 { 74 switch (vuorossaOlevaPelaaja) 75 { 76 case 1: 77 foreach (LaivanPala pala in pelaajan1Laivat) 78 { 79 pala.IsVisible = false; 80 } 81 82 foreach (GameObject ammuttu in pelaajan1AmmututPisteet) 83 { 84 ammuttu.IsVisible = false; 85 } 86 87 88 break; 89 case 2: 90 foreach (LaivanPala pala in pelaajan2Laivat) 91 { 92 pala.IsVisible = false; 93 } 94 95 foreach (GameObject ammuttu in pelaajan2AmmututPisteet) 96 { 97 ammuttu.IsVisible = false; 98 } 99 100 break; 101 } 102 MessageDisplay.Add("Kenttä piilotettiin"); 103 104 } 105 106 void NaytaKentta(int vuorossaOlevaPelaaja) 107 { 108 switch (vuorossaOlevaPelaaja) 109 { 110 case 1: 111 foreach (LaivanPala pala in pelaajan1Laivat) 112 { 113 if (pala.Ammuttu) 114 pala.IsVisible = true; 115 } 116 117 foreach (GameObject ammuttu in pelaajan1AmmututPisteet) 118 { 119 ammuttu.IsVisible = true; 120 } 121 122 123 break; 124 case 2: 125 foreach (LaivanPala pala in pelaajan2Laivat) 126 { 127 if (pala.Ammuttu) 128 pala.IsVisible = true; 129 } 130 131 foreach (GameObject ammuttu in pelaajan2AmmututPisteet) 132 { 133 ammuttu.IsVisible = true; 134 } 135 136 break; 137 } 138 } 139 140 void Ammu() 141 { 142 List<LaivanPala> tutkittavatLaivat = pelaajan1Laivat; 143 List<GameObject> tutkittavatAmmututPisteet = pelaajan1AmmututPisteet; 144 145 if (vuorossaOlevaPelaaja == 2) 146 { 147 tutkittavatLaivat = pelaajan2Laivat; 148 tutkittavatAmmututPisteet = pelaajan2AmmututPisteet; 149 } 150 151 if (OnkoRuutuaAmmuttu(kursorinAllaOlevaPiste, tutkittavatAmmututPisteet, tutkittavatLaivat)) 152 return; 153 bool allaOliLaiva = false; 154 LaivanPala allaOlevaLaiva = tutkittavatLaivat[0]; 155 foreach (LaivanPala laiva in tutkittavatLaivat) 156 { 157 if (Vector.Distance(kursorinAllaOlevaPiste, laiva.Position) < ruudunKorkeus / 5) 158 { 159 MessageDisplay.Add("Osuma!"); 160 laiva.Ammu(); 161 allaOliLaiva = true; 162 laiva.IsVisible = true; 163 if (!OnkoLaivassaPalojaJaljella(laiva.Tag.ToString(), tutkittavatLaivat)) 164 MessageDisplay.Add("Laiva tuhottu!"); 165 return; 166 } 167 } 168 169 if (!allaOliLaiva) 170 { 171 GameObject tyhja = new GameObject(ruudunLeveys - 2, ruudunKorkeus - 2); 172 tyhja.Color = Color.Gray; 173 tyhja.Position = kursorinAllaOlevaPiste; 174 Add(tyhja); 175 tutkittavatAmmututPisteet.Add(tyhja); 176 MessageDisplay.Add("Tyhjä!"); 177 } 178 Timer.SingleShot(1.0, VuoroVaihtuu); 179 } 180 181 void VuoroVaihtuu() 182 { 183 MessageDisplay.Add("Vuoro vaihtuu"); 184 PiilotaKentta(vuorossaOlevaPelaaja); 185 186 switch (vuorossaOlevaPelaaja) 187 { 188 case 1: 189 vuorossaOlevaPelaaja = 2; 190 break; 191 case 2: 192 vuorossaOlevaPelaaja = 1; 193 break; 194 } 195 196 NaytaKentta(vuorossaOlevaPelaaja); 197 } 198 199 bool OnkoRuutuaAmmuttu(Vector piste, List<GameObject> tutkittavatAmmututPisteet, List<LaivanPala> tutkittavatLaivat) 200 { 201 foreach (GameObject ammuttuPiste in tutkittavatAmmututPisteet) 202 { 203 if (Vector.Distance(kursorinAllaOlevaPiste, ammuttuPiste.Position) < ruudunKorkeus / 5) 204 return true; 205 } 206 207 foreach (LaivanPala laiva in tutkittavatLaivat) 208 { 209 if (Vector.Distance(kursorinAllaOlevaPiste, laiva.Position) < ruudunKorkeus / 5) 210 { 211 if (laiva.Ammuttu) 212 { 213 MessageDisplay.Add("Laiva jo ammuttu"); 214 return true; 215 } 216 } 217 } 218 219 return false; 220 } 221 222 bool OnkoLaivassaPalojaJaljella(String tagi, List<LaivanPala> tutkittavatLaivat) 223 { 224 foreach (LaivanPala laiva in tutkittavatLaivat) 225 { 226 if (laiva.Tag.ToString() == tagi && laiva.IsVisible == false) 227 return true; 228 } 229 return false; 230 } 231 232 void LuoKentta() 233 { 234 pelaajan1Laivat = new List<LaivanPala>(); 235 pelaajan2Laivat = new List<LaivanPala>(); 236 pelaajan1AmmututPisteet = new List<GameObject>(); 237 pelaajan2AmmututPisteet = new List<GameObject>(); 238 kursorinAllaOlevaPiste = new Vector(0, 0); 239 240 int kentanNro = RandomGen.NextInt(1, 20); 241 TileMap ruudut = TileMap.FromFile("kentta"+kentanNro+".txt"); 242 LuoLaivat(ruudut); 243 ruudut.Insert(ruudunLeveys, ruudunKorkeus); 244 245 vuorossaOlevaPelaaja = 2; 246 kentanNro = RandomGen.NextInt(1, 20); 247 ruudut = TileMap.FromFile("kentta"+kentanNro+".txt"); 248 LuoLaivat(ruudut); 249 ruudut.Insert(ruudunLeveys, ruudunKorkeus); 250 251 vuorossaOlevaPelaaja = 1; 252 Level.CreateBorders(); 253 } 254 255 void LuoLaivat(TileMap ruudut) 256 { 257 ruudut['0'] = LuoLaiva0; 258 ruudut['1'] = LuoLaiva1; 259 ruudut['2'] = LuoLaiva2; 260 ruudut['3'] = LuoLaiva3; 261 ruudut['4'] = LuoLaiva4; 262 ruudut['5'] = LuoLaiva5; 263 ruudut['6'] = LuoLaiva6; 264 ruudut['7'] = LuoLaiva7; 265 ruudut['8'] = LuoLaiva8; 266 ruudut['9'] = LuoLaiva9; 267 } 268 269 GameObject LuoLaiva0() 270 { 271 return LuoLaiva("0"); 272 } 273 GameObject LuoLaiva1() 274 { 275 return LuoLaiva("1"); 276 } 277 GameObject LuoLaiva2() 278 { 279 return LuoLaiva("2"); 280 } 281 GameObject LuoLaiva3() 282 { 283 return LuoLaiva("3"); 284 } 285 GameObject LuoLaiva4() 286 { 287 return LuoLaiva("4"); 288 } 289 GameObject LuoLaiva5() 290 { 291 return LuoLaiva("5"); 292 } 293 GameObject LuoLaiva6() 294 { 295 return LuoLaiva("6"); 296 } 297 GameObject LuoLaiva7() 298 { 299 return LuoLaiva("7"); 300 } 301 GameObject LuoLaiva8() 302 { 303 return LuoLaiva("8"); 304 } 305 GameObject LuoLaiva9() 306 { 307 return LuoLaiva("9"); 308 } 309 310 GameObject LuoLaiva(String tagi) 311 { 312 LaivanPala laiva = new LaivanPala(ruudunLeveys - 2, ruudunKorkeus - 2); 313 laiva.IsVisible = false; 314 laiva.Tag = tagi; 315 switch (vuorossaOlevaPelaaja) 316 { 317 case 1: 318 pelaajan1Laivat.Add(laiva); 319 break; 320 case 2: 321 pelaajan2Laivat.Add(laiva); 322 break; 323 } 324 return laiva; 11 325 } 12 326 } -
2010/31/mimakrja/SeaWar/SeaWar.csproj
r1597 r1623 89 89 <Content Include="Game.ico" /> 90 90 <Content Include="GameThumbnail.png" /> 91 <Content Include="TextFile1.txt" /> 91 <Content Include="kentta1.txt"> 92 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> 93 </Content> 94 <Content Include="kentta10.txt"> 95 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> 96 </Content> 97 <Content Include="kentta11.txt"> 98 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> 99 </Content> 100 <Content Include="kentta12.txt"> 101 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> 102 </Content> 103 <Content Include="kentta13.txt"> 104 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> 105 </Content> 106 <Content Include="kentta14.txt"> 107 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> 108 </Content> 109 <Content Include="kentta15.txt"> 110 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> 111 </Content> 112 <Content Include="kentta16.txt"> 113 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> 114 </Content> 115 <Content Include="kentta17.txt"> 116 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> 117 </Content> 118 <Content Include="kentta18.txt"> 119 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> 120 </Content> 121 <Content Include="kentta19.txt"> 122 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> 123 </Content> 124 <Content Include="kentta2.txt"> 125 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> 126 </Content> 127 <Content Include="kentta20.txt"> 128 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> 129 </Content> 130 <Content Include="kentta3.txt"> 131 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> 132 </Content> 133 <Content Include="kentta4.txt"> 134 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> 135 </Content> 136 <Content Include="kentta5.txt"> 137 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> 138 </Content> 139 <Content Include="kentta6.txt"> 140 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> 141 </Content> 142 <Content Include="kentta7.txt"> 143 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> 144 </Content> 145 <Content Include="kentta8.txt"> 146 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> 147 </Content> 148 <Content Include="kentta9.txt"> 149 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> 150 </Content> 92 151 </ItemGroup> 93 152 <ItemGroup> -
2010/31/mimakrja/SeaWar/kentta2.txt
r1597 r1623 2 2 ......... 3 3 ..4...... 4 ..4.. 1..34 ..4..5..3 5 5 ..4.....3 6 6 ..4.....3 7 ..... 22..8 . 1.......9 ..... 333.10 22.....1.7 .....66.. 8 .7....... 9 .....888. 10 99.....0. -
2010/31/mimakrja/SeaWar/kentta3.txt
r1597 r1623 1 3.1......2 3...22..1 3 3........4 ....... 2.5 . 1.....2.1 2.1...... 2 2...33..4 3 2........ 4 .......5. 5 .6.....5. 6 6 ......... 7 .. 4444...8 . 1.......9 ........ 210 . 333....27 ..7777... 8 .8....... 9 ........9 10 .000....9 -
2010/31/mimakrja/SeaWar/kentta4.txt
r1597 r1623 1 1 1........ 2 .. 333.2..3 ...... 2..4 .. 22...1.5 1...2....6 .... 2....7 333...4..8 ...... 4..9 ... 1..4..10 ...... 4..2 ..222.3.. 3 ......3.. 4 ..44...5. 5 6...8.... 6 ....8.... 7 777...0.. 8 ......0.. 9 ...9..0.. 10 ......0.. -
2010/31/mimakrja/SeaWar/kentta5.txt
r1597 r1623 3 3 ..3.22..4 4 4 ........4 5 .. 333...46 ..1.. 22..5 ..555...4 6 ..1..66.. 7 7 ......... 8 . 1....2..9 ...... 2..10 ... 1....18 .7....8.. 9 ......8.. 10 ...0....9 -
2010/31/mimakrja/SeaWar/kentta6.txt
r1597 r1623 1 . 4444....1 .9999.... 2 2 .......1. 3 333......4 ... 1.....5 ....... 226 . 1...2...7 ..... 2...3 000...... 4 ...2..... 5 .......33 6 .5...4... 7 .....4... 8 8 ......... 9 . 333..2..10 . 1....2..9 .666..7.. 10 .8....7..
Note: See TracChangeset
for help on using the changeset viewer.