- Timestamp:
- 2011-06-30 14:20:12 (12 years ago)
- Location:
- 2011/26/JuhoK/SFN
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
2011/26/JuhoK/SFN/SFN/SFN/Auto.cs
r2353 r2362 12 12 public int moottori = 0; 13 13 public int renkaat = 0; 14 public int korinhinta = 0;15 14 16 public Auto(string korinnimi, int kori nhinta, int kori, int moottori, int renkaat)15 public Auto(string korinnimi, int kori, int moottori, int renkaat) 17 16 { 18 17 this.korinnimi = korinnimi; … … 20 19 this.moottori = moottori; 21 20 this.renkaat = renkaat; 22 this.korinhinta = korinhinta;23 21 } 24 22 } -
2011/26/JuhoK/SFN/SFN/SFN/Peli.cs
r2353 r2362 11 11 { 12 12 public class Peli : PhysicsGame 13 { List<Auto> autot = new List<Auto>(); 13 { 14 List<Auto> autot = new List<Auto>(); 14 15 List<Image> kuvat = new List<Image>(); 16 List<int> hinnat = new List<int>(); 17 String[] mallit = new String[4]; 18 Label[] autokuvat = new Label[4]; 15 19 int ID = 0, max_taso = 20; 16 20 double raha = 5000; … … 19 23 Image kuva = LoadImage("Blues\\Perus1"); 20 24 Label number, malli, moottori, renkaat, moottorin_hinta, renkaiden_hinta, sell_price, rahat; 21 Label auto1, auto2, auto3, auto4; 22 PushButton osta_auto1, osta_auto2, osta_auto3, osta_auto4; 25 23 26 int ChangeColor; 24 27 25 28 public override void Begin() 26 29 { 30 hinnat.Add(5000); 31 hinnat.Add(10000); 32 hinnat.Add(15000); 33 hinnat.Add(20000); 34 35 mallit[0] = "Model0"; 36 mallit[1] = "Model1"; 37 mallit[2] = "Model2"; 38 mallit[3] = "Model3"; 39 27 40 for (int i = 0; i < 4; i += 1) 28 41 { … … 34 47 } 35 48 36 autot.Add(new Auto("Model1", 1 5000, 1, 4, 5));37 autot.Add(new Auto("Model3", 17500,3, 9, 1));38 autot.Add(new Auto("Model2", 2 0000, 2, 9, 3));49 autot.Add(new Auto("Model1", 1, 4, 5)); 50 autot.Add(new Auto("Model3", 3, 9, 1)); 51 autot.Add(new Auto("Model2", 2, 9, 3)); 39 52 Keyboard.Listen(Key.Escape, ButtonState.Released, Exit, null); 40 53 Mouse.IsCursorVisible = true; … … 154 167 Add(rahat); 155 168 156 double hinta = (10000 + (autot[ID].kori * 100)* 0.75) + ((autot[ID].moottori * 100) / 2) + ((autot[ID].renkaat * 100) / 2);169 double hinta = (hinnat[autot[ID].kori] * 0.75) + ((autot[ID].moottori * 100) / 2) + ((autot[ID].renkaat * 100) / 2); 157 170 sell_price = new Label("Sell price: " + hinta); 158 171 sell_price.Position = new Vector(oikeareuna.X, Screen.Bottom * 0.28); … … 212 225 Add(valkoinen); 213 226 227 214 228 215 229 double kerroin = 0.85; … … 217 231 for (int i = 0; i < 4; i++) 218 232 { 219 Label autokuva = new Label(40, 20); 220 autokuva.Image = kuvat[i + kuvaindeksilaskuri]; 221 autokuva.Position = new Vector(Screen.Left * kerroin, alapalkki.Y + alapalkki.Height * 0.2); 222 Add(autokuva); 233 autokuvat[i] = new Label(40, 20); 234 autokuvat[i].Image = kuvat[0 + kuvaindeksilaskuri]; 235 autokuvat[i].Position = new Vector(Screen.Left * kerroin, alapalkki.Y + alapalkki.Height * 0.2); 236 Add(autokuvat[i]); 237 238 PushButton nappi = new PushButton("Buy " + i); 239 nappi.Position = new Vector(Screen.Left * kerroin, alapalkki.Y - alapalkki.Height * 0.2); 240 int temp = i; 241 nappi.Clicked += new Action(delegate { Osta(temp);}); 242 Add(nappi); 243 244 Label teksti = new Label("Price: "+hinnat[i].ToString()); 245 teksti.Position = new Vector(Screen.Left * kerroin, alapalkki.Y - alapalkki.Height * 0.05); 246 Add(teksti); 247 223 248 kuvaindeksilaskuri += 5; 224 }225 226 auto1 = new Label(40, 20);227 auto1.Position = new Vector(Screen.Left * 0.85, alapalkki.Y + alapalkki.Height * 0.20);228 auto1.Image = kuvat[0];229 Add(auto1);230 231 auto2 = new Label(40, 20);232 auto2.Position = new Vector(Screen.Left * 0.55, alapalkki.Y + alapalkki.Height * 0.20);233 auto2.Image = kuvat[5];234 Add(auto2);235 236 auto3 = new Label(40, 20);237 auto3.Position = new Vector(Screen.Left * 0.25, alapalkki.Y + alapalkki.Height * 0.20);238 auto3.Image = kuvat[10];239 Add(auto3);240 241 auto4 = new Label(40, 20);242 auto4.Position = new Vector(Screen.Left * -0.05, alapalkki.Y + alapalkki.Height * 0.20);243 auto4.Image = kuvat[15];244 Add(auto4);245 246 Label[] osta_auto_buttons = new Label[4];247 kerroin = 0.85;248 249 for (int i = 0; i < osta_auto_buttons.Length; i++)250 {251 osta_auto_buttons[i] = new PushButton("Buy");252 osta_auto_buttons[i].Position = new Vector(Screen.Left * kerroin, alapalkki.Y - alapalkki.Height * 0.2);253 Add(osta_auto_buttons[i]);254 249 kerroin -= 0.3; 255 } 256 257 /*osta_auto1 = new PushButton("Osta"); 258 osta_auto1.Position = new Vector(Screen.Left * 0.85, alapalkki.Y - alapalkki.Height * 0.20); 259 Add(osta_auto1); 260 261 osta_auto2 = new PushButton("Osta"); 262 osta_auto2.Position = new Vector(Screen.Left * 0.55, alapalkki.Y - alapalkki.Height * 0.20); 263 Add(osta_auto2); 264 265 osta_auto3 = new PushButton("Osta"); 266 osta_auto3.Position = new Vector(Screen.Left * 0.25, alapalkki.Y - alapalkki.Height * 0.20); 267 Add(osta_auto3); 268 269 osta_auto4 = new PushButton("Osta"); 270 osta_auto4.Position = new Vector(Screen.Left * -0.05, alapalkki.Y - alapalkki.Height * 0.20); 271 Add(osta_auto4);*/ 272 273 /*Label[] laabelit = new Label[4]; 274 double kerroin = 0.85; 275 for (int i = 0; i < laabelit.Length; i++) 276 { 277 String hintaTuhatErottimella = autot[i].korinhinta.ToString("0,0", CultureInfo.InvariantCulture); 278 laabelit[i] = new Label("Price: " + hintaTuhatErottimella); 279 laabelit[i].Position = new Vector(Screen.Left * kerroin, alapalkki.Y - alapalkki.Height * 0.05); 280 Add(laabelit[i]); 281 kerroin -= 0.3; 282 } */ 283 284 // Lisätään hintaan tuhaterotin 285 //int _hinta = (10000 + (0 * 100)); 286 287 288 /*Label hinta_auto1 = new Label("Price: "+hintaTuhatErottimella); 289 hinta_auto1.Position = new Vector(Screen.Left * 0.85, alapalkki.Y - alapalkki.Height * 0.05); 290 Add(hinta_auto1); 291 292 _hinta = int.Parse((10000 + (1 * 100)).ToString()); 293 hintaTuhatErottimella = _hinta.ToString("0,0", CultureInfo.InvariantCulture); 294 Label hinta_auto2 = new Label("Price: "+hintaTuhatErottimella); 295 hinta_auto2.Position = new Vector(Screen.Left * 0.55, alapalkki.Y - alapalkki.Height * 0.05); 296 Add(hinta_auto2); 297 298 _hinta = int.Parse((20000 + (2 * 100)).ToString()); 299 hintaTuhatErottimella = _hinta.ToString("0,0", CultureInfo.InvariantCulture); 300 Label hinta_auto3 = new Label("Price: "+hintaTuhatErottimella); 301 hinta_auto3.Position = new Vector(Screen.Left * 0.25, alapalkki.Y - alapalkki.Height * 0.05); 302 Add(hinta_auto3); 303 304 _hinta = int.Parse((20000 + (3 * 100)).ToString()); 305 hintaTuhatErottimella = _hinta.ToString("0,0", CultureInfo.InvariantCulture); 306 Label hinta_auto4 = new Label("Price: "+hintaTuhatErottimella); 307 hinta_auto4.Position = new Vector(Screen.Left * -0.05, alapalkki.Y - alapalkki.Height * 0.05); 308 Add(hinta_auto4);*/ 250 } 251 252 } 253 254 void Osta(int indeksi) 255 { 256 if (raha >= hinnat[indeksi]) 257 { 258 raha -= hinnat[indeksi]; 259 autot.Add(new Auto(mallit[indeksi], indeksi, 1, 1)); 260 ID = autot.Count - 1; 261 UpdateHUD(); 262 } 263 else 264 { 265 MessageDisplay.Add("No enought money."); 266 } 309 267 } 310 268 … … 346 304 void ChangeCarColor() 347 305 { 348 auto 1.Image = kuvat[ChangeColor];349 auto 2.Image = kuvat[ChangeColor + 5];350 auto 3.Image = kuvat[ChangeColor + 10];351 auto 4.Image = kuvat[ChangeColor + 15];306 autokuvat[0].Image = kuvat[ChangeColor]; 307 autokuvat[1].Image = kuvat[ChangeColor + 5]; 308 autokuvat[2].Image = kuvat[ChangeColor + 10]; 309 autokuvat[3].Image = kuvat[ChangeColor + 15]; 352 310 } 353 311 … … 356 314 if (autot.Count > 1) 357 315 { 358 double hinta = ( 10000 + (autot[ID].kori * 100)* 0.75) + ((autot[ID].moottori * 100) / 2) + ((autot[ID].renkaat * 100) / 2);316 double hinta = (hinnat[autot[ID].kori] * 0.75) + ((autot[ID].moottori * 100) / 2) + ((autot[ID].renkaat * 100) / 2); 359 317 autot.RemoveAt(ID); 360 318 raha = raha + hinta; … … 426 384 void UpdateHUD() 427 385 { 428 double hinta = ( 10000 + (autot[ID].kori * 100)* 0.75) + ((autot[ID].moottori * 100) / 2) + ((autot[ID].renkaat * 100) / 2);386 double hinta = (hinnat[autot[ID].kori] * 0.75) + ((autot[ID].moottori * 100) / 2) + ((autot[ID].renkaat * 100) / 2); 429 387 sell_price.Text = "Sell price: " + hinta.ToString(); 430 388 malli.Text = autot[ID].korinnimi.ToString(); … … 434 392 moottorin_hinta.Text = "Price: " + (autot[ID].moottori * 100).ToString(); 435 393 renkaiden_hinta.Text = "Price: " + (autot[ID].renkaat * 100).ToString(); 394 rahat.Text = "Money: " + raha.ToString(); 436 395 } 437 396 }
Note: See TracChangeset
for help on using the changeset viewer.