Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication2
- {
- class Program
- {
- static void Main(string[] args)
- {
- float step1 = 2f;
- int delay1 = 4;
- float currentDistance1 = 0;
- float step2 = 2.2f;
- int delay2 = 8;
- float currentDistance2 = 0;
- float maxDistance = 320f;
- int currentStep = 0;
- bool temp = false;
- bool temp2 = false;
- float trap1 = 100f;
- // Zapisz kto kogo wyprzedził i w jakim metrze; +
- // Wyścig kończy przebiegnięcie całego dystansu przez obu zawodników; +
- // Wypisz ile kroków musiał przebiec przegrany; +
- // Jakie zagrożenie stworzyłoby dla programu ustawienie wartości trap zmniejszenie wartości step o 0.5 miast pomniejszenie dwukrotne
- // Zastosowanie odejmowania w ciele warunku może spowodować nadanie zmiennej wartości ujemnej albo 0, co może spowodować, że pętla będzie trwać w nieskończoność
- while (currentDistance1 <= maxDistance || currentDistance2 <= maxDistance)
- {
- currentStep++;
- if (currentStep >= delay1)
- {
- currentDistance1 = currentDistance1 + step1;
- }
- if (currentStep >= delay2)
- {
- currentDistance2 = currentDistance2 + step2;
- }
- if (currentDistance2 > currentDistance1 && !temp && step1 < step2)
- {
- Console.WriteLine($"Gracz 2 wyprzedził 1 na dystansie {currentDistance2}");
- temp = true;
- temp2 = false;
- }
- else if (currentDistance1 > currentDistance2 && !temp2 && step2 < step1)
- {
- Console.WriteLine($"Gracz 1 wyprzedził 2 na dystansie {currentDistance1}");
- temp2 = true;
- temp = false;
- }
- if (currentDistance1 == trap1)
- {
- step1 = step1 / 2;
- Console.WriteLine("Gracz 1 wpadł w pułapkę!");
- }
- if (currentDistance2 == trap1)
- {
- step2 = step2 / 2;
- Console.WriteLine("Gracz 2 wpadł w pułapkę!");
- }
- }
- Console.WriteLine($"Gracz 1 przebiegł: {currentDistance1}");
- Console.WriteLine($"Gracz 2 przebiegł: {currentDistance2}");
- if (currentDistance1 < currentDistance2)
- {
- Console.WriteLine($"Przegrany gracz 1 przebiegł {currentStep - delay1} kroków.");
- }
- else
- {
- Console.WriteLine($"Przegrany gracz 2 przebiegł {currentStep - delay2} kroków");
- }
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment