Eriziel

Untitled

Jun 11th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.09 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication2
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             float step1 = 2f;
  14.             int delay1 = 4;
  15.             float currentDistance1 = 0;
  16.  
  17.             float step2 = 2.2f;
  18.             int delay2 = 8;
  19.             float currentDistance2 = 0;
  20.  
  21.             float maxDistance = 320f;
  22.  
  23.             int currentStep = 0;
  24.             bool temp = false;
  25.             bool temp2 = false;
  26.  
  27.             float trap1 = 100f;
  28.  
  29.            
  30.  
  31.             // Zapisz kto kogo wyprzedził i w jakim metrze; +
  32.             // Wyścig kończy przebiegnięcie całego dystansu przez obu zawodników; +
  33.             // Wypisz ile kroków musiał przebiec przegrany; +
  34.             // Jakie zagrożenie stworzyłoby dla programu ustawienie wartości trap zmniejszenie wartości step o 0.5 miast pomniejszenie dwukrotne
  35.             // 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ść
  36.  
  37.             while (currentDistance1 <= maxDistance || currentDistance2 <= maxDistance)
  38.             {
  39.  
  40.                 currentStep++;
  41.  
  42.                 if (currentStep >= delay1)
  43.                 {
  44.                     currentDistance1 = currentDistance1 + step1;
  45.                 }
  46.                 if (currentStep >= delay2)
  47.                 {
  48.                     currentDistance2 = currentDistance2 + step2;
  49.                 }
  50.                 if (currentDistance2 > currentDistance1 && !temp && step1 < step2)
  51.                 {
  52.                     Console.WriteLine($"Gracz 2 wyprzedził 1 na dystansie {currentDistance2}");
  53.                     temp = true;
  54.                     temp2 = false;
  55.                 }
  56.                 else if (currentDistance1 > currentDistance2 && !temp2 && step2 < step1)
  57.                 {
  58.                     Console.WriteLine($"Gracz 1 wyprzedził 2 na dystansie {currentDistance1}");
  59.                     temp2 = true;
  60.                     temp = false;
  61.                 }
  62.  
  63.  
  64.                 if (currentDistance1 == trap1)
  65.                 {
  66.                     step1 = step1 / 2;
  67.                     Console.WriteLine("Gracz 1 wpadł w pułapkę!");
  68.                 }
  69.                 if (currentDistance2 == trap1)
  70.                 {
  71.                     step2 = step2 / 2;
  72.                     Console.WriteLine("Gracz 2 wpadł w pułapkę!");
  73.                 }
  74.             }
  75.             Console.WriteLine($"Gracz 1 przebiegł: {currentDistance1}");
  76.             Console.WriteLine($"Gracz 2 przebiegł: {currentDistance2}");
  77.  
  78.  
  79.             if (currentDistance1 < currentDistance2)
  80.             {
  81.                 Console.WriteLine($"Przegrany gracz 1 przebiegł {currentStep - delay1} kroków.");
  82.             }
  83.             else
  84.             {
  85.                 Console.WriteLine($"Przegrany gracz 2 przebiegł {currentStep - delay2} kroków");
  86.             }
  87.             Console.ReadLine();
  88.         }
  89.  
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment