Advertisement
Cassimus

BrickGame

Mar 8th, 2025 (edited)
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.37 KB | None | 0 0
  1. internal class Program
  2. {
  3.     static string[] plansza;
  4.     const char GRACZ = '^';
  5.     const char PRZESZKODA = '#';
  6.  
  7.     private static void Main(string[] args)
  8.     {
  9.         // kolumna 0 - lewa, 1- środek , 2 prawa
  10.         int pozycjaGracza = 1;
  11.         bool czyUderzony = false;
  12.         Random generator = new Random();
  13.  
  14.         NowaGra(10);
  15.         UstawGracza(pozycjaGracza);
  16.         WyswietlPlansze();
  17.  
  18.         while (!czyUderzony)
  19.         {
  20.             if (Console.KeyAvailable)
  21.             {
  22.                 var nacisnietyKlawisz = Console.ReadKey(true);
  23.  
  24.                 if (nacisnietyKlawisz.Key == ConsoleKey.D)
  25.                 {
  26.                     if (pozycjaGracza < 2)
  27.                     {
  28.                         pozycjaGracza++;
  29.                     }
  30.                 }
  31.  
  32.                 if (nacisnietyKlawisz.Key == ConsoleKey.A)
  33.                 {
  34.                     if (pozycjaGracza > 0)
  35.                     {
  36.                         pozycjaGracza--;
  37.                     }
  38.                 }
  39.             }
  40.            
  41.             int pozycjaPrzeszkody = generator.Next(3);
  42.             string przeszkoda = UstawPrzeszkode(pozycjaPrzeszkody);
  43.  
  44.             for (int i = plansza.Length - 2; i > 0; i--)
  45.             {
  46.                 plansza[i] = plansza[i - 1];
  47.             }
  48.             plansza[0] = przeszkoda;
  49.  
  50.  
  51.             UstawGracza(pozycjaGracza);
  52.             WyswietlPlansze();
  53.  
  54.             Thread.Sleep(600);
  55.         }
  56.  
  57.         Console.Clear();
  58.         System.Console.WriteLine("GAME OVER");
  59.  
  60.     }
  61.  
  62.     static string UstawPrzeszkode(int pozycjaPrzeszkody)
  63.     {
  64.         string linia = "   ";
  65.         linia = linia.Insert(pozycjaPrzeszkody, PRZESZKODA.ToString());
  66.         return linia;
  67.     }
  68.  
  69.     private static void NowaGra(int iloscWierszy)
  70.     {
  71.         plansza = new string[iloscWierszy];
  72.         for (int i = 0; i < plansza.Length; i++)
  73.         {
  74.             plansza[i] = "";
  75.         }
  76.     }
  77.  
  78.     private static void UstawGracza(int pozycjaGracza)
  79.     {
  80.         string linia = "   ";
  81.         linia = linia.Insert(pozycjaGracza, GRACZ.ToString());
  82.         plansza[plansza.Length - 1] = linia;
  83.     }
  84.  
  85.     private static void WyswietlPlansze()
  86.     {
  87.         Console.Clear();
  88.         for (int i = 0; i < plansza.Length; i++)
  89.         {
  90.             System.Console.WriteLine(plansza[i]);
  91.         }
  92.     }
  93. }
  94.  
  95.  
  96.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement