Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- internal class Program
- {
- static string[] plansza;
- const char GRACZ = '^';
- const char PRZESZKODA = '#';
- private static void Main(string[] args)
- {
- // kolumna 0 - lewa, 1- środek , 2 prawa
- int pozycjaGracza = 1;
- bool czyUderzony = false;
- Random generator = new Random();
- NowaGra(10);
- UstawGracza(pozycjaGracza);
- WyswietlPlansze();
- while (!czyUderzony)
- {
- if (Console.KeyAvailable)
- {
- var nacisnietyKlawisz = Console.ReadKey(true);
- if (nacisnietyKlawisz.Key == ConsoleKey.D)
- {
- if (pozycjaGracza < 2)
- {
- pozycjaGracza++;
- }
- }
- if (nacisnietyKlawisz.Key == ConsoleKey.A)
- {
- if (pozycjaGracza > 0)
- {
- pozycjaGracza--;
- }
- }
- }
- int pozycjaPrzeszkody = generator.Next(3);
- string przeszkoda = UstawPrzeszkode(pozycjaPrzeszkody);
- for (int i = plansza.Length - 2; i > 0; i--)
- {
- plansza[i] = plansza[i - 1];
- }
- plansza[0] = przeszkoda;
- UstawGracza(pozycjaGracza);
- WyswietlPlansze();
- Thread.Sleep(600);
- }
- Console.Clear();
- System.Console.WriteLine("GAME OVER");
- }
- static string UstawPrzeszkode(int pozycjaPrzeszkody)
- {
- string linia = " ";
- linia = linia.Insert(pozycjaPrzeszkody, PRZESZKODA.ToString());
- return linia;
- }
- private static void NowaGra(int iloscWierszy)
- {
- plansza = new string[iloscWierszy];
- for (int i = 0; i < plansza.Length; i++)
- {
- plansza[i] = "";
- }
- }
- private static void UstawGracza(int pozycjaGracza)
- {
- string linia = " ";
- linia = linia.Insert(pozycjaGracza, GRACZ.ToString());
- plansza[plansza.Length - 1] = linia;
- }
- private static void WyswietlPlansze()
- {
- Console.Clear();
- for (int i = 0; i < plansza.Length; i++)
- {
- System.Console.WriteLine(plansza[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement