// The thread performs the task public void ThreadProc() { y = 0; x = random.Next(1, 600); while (true) { Application.Current.Dispatcher.Invoke((Action)(() => { booster.Fly(x, y); if (y > player.y && y < player.y + 50 && x > player.x && x < player.x + 50) { used = true; if (booster.improvementType == "armor") { player.armor += 10; // Add armor for player } Debug.WriteLine("Added 10 armor: " + player.armor); if (booster.improvementType == "life") { player.life += 10; // Add armor for player } Debug.WriteLine("Added 10 life: " + player.life); //player = new UpgradeArmor(player, 10); if (booster.improvementType == "gun") { player.gundmg += 10; // Add gunDmg for player } Debug.WriteLine("Boost: " + booster.improvementType); } })); y += 10; if (y > 600) { used = true; } if (used == true) { Application.Current.Dispatcher.Invoke((Action)(() => { booster.dynamicImage.Source = null; })); break; } Thread.Sleep(100); } }
// Wątek wykonuje zadanie public void ThreadProc() { y = 0; x = random.Next(1, 600); while (true) { Application.Current.Dispatcher.Invoke((Action)(() => { booster.Fly(x, y); //sprawdź czy dochodzi do kolizji z graczem if (y > player.y && y < player.y + 50 && x > player.x && x < player.x + 50) { used = true; if (booster.improvementType == "armor") player.armor += 10; // Dodaj pancerz dla gracza Debug.WriteLine("Added 10 armor: " + player.armor); if (booster.improvementType == "life") player.life += 10; // Dodaj życie dla gracza Debug.WriteLine("Added 10 life: " + player.life); if (booster.improvementType == "gun") player.gundmg += 10; // Dodaj zadawane obrażenia przez gracza Debug.WriteLine("Boost: " + booster.improvementType); } })); y += 10; if (y > 600) used = true; if (used == true) //znisz jeśli poza mapą { Application.Current.Dispatcher.Invoke((Action)(() => { booster.dynamicImage.Source = null; })); break; } Thread.Sleep(100); } }