Eriziel

The Race

Jun 20th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.82 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 = 2.0f;
  14.             int delay1 = 0;
  15.             float currentDistance1 = 0;
  16.            
  17.  
  18.             float step2 = 3f;
  19.             int delay2 = 10;
  20.             float currentDistance2 = 0;
  21.  
  22.             float maxDistance = 32f;
  23.  
  24.             int currentStep = 0;
  25.             bool temp = false;
  26.             bool temp2 = false;
  27.            
  28.             float trap1 = 10f;
  29.             float trap2 = 21f;
  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.                
  51.                 if (currentDistance2 >= currentDistance1 && !temp && step2 >= step1 && currentDistance2 > delay2)
  52.                 {
  53.                     Console.WriteLine($"Gracz 2 wyprzedził Gracza 1 na dystansie {currentDistance2}");
  54.                     temp = true;
  55.                     temp2 = false;
  56.                 }
  57.                 else if (currentDistance1 >= currentDistance2 && !temp2 && step1 >= step2 && currentDistance1 > delay1)
  58.                 {
  59.                     Console.WriteLine($"Gracz 1 wyprzedził Gracza 2 na dystansie {currentDistance1}");
  60.                     temp2 = true;
  61.                     temp = false;
  62.                 }
  63.  
  64.  
  65.                 if (currentDistance1 == trap1)
  66.                 {
  67.                     step1 = step1 / 2;
  68.                     Console.WriteLine("Gracz 1 wpadł w pułapkę!");
  69.                 }
  70.                 if (currentDistance2 == trap1)
  71.                 {
  72.                     step2 = step2 / 2;
  73.                     Console.WriteLine("Gracz 2 wpadł w pułapkę!");
  74.                 }
  75.  
  76.                 if (currentDistance1 == trap2)
  77.                 {
  78.                     step1 = step1 / 1.5f;
  79.                     Console.WriteLine("Gracz 1 wpadł w pułapkę!");
  80.                 }
  81.                 if (currentDistance2 == trap2)
  82.                 {
  83.                     Console.WriteLine("Gracz 2 wpadł w pułapkę!");
  84.                     step2 = step2 / 1.5f;
  85.                 }
  86.             }
  87.             Console.WriteLine($"Gracz 1 przebiegł: {currentDistance1}");
  88.             Console.WriteLine($"Gracz 2 przebiegł: {currentDistance2}");
  89.  
  90.  
  91.             if (currentDistance1 < currentDistance2)
  92.             {
  93.                 Console.WriteLine($"Przegrany Gracz 1 przebiegł {currentStep - delay1} kroków.");
  94.             }
  95.             else if (currentDistance1 > currentDistance2)
  96.             {
  97.                 Console.WriteLine($"Przegrany Gracz 2 przebiegł {currentStep - delay2} kroków");
  98.             }
  99.             else if (currentDistance1 == currentDistance2)
  100.             {
  101.                 Console.WriteLine("REMIS");
  102.             }
  103.             Console.ReadLine();
  104.         }
  105.  
  106.     }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment