SHOW:
|
|
- or go back to the newest paste.
| 1 | using System; | |
| 2 | using System.Collections.Generic; | |
| 3 | using System.Linq; | |
| 4 | using System.Text; | |
| 5 | using System.Threading; | |
| 6 | ||
| 7 | namespace BrickGame | |
| 8 | {
| |
| 9 | class Program | |
| 10 | {
| |
| 11 | static string[] plansza; | |
| 12 | const string GRACZ = "^"; | |
| 13 | const string PRZESZKODA = "#"; | |
| 14 | const string NITRO = "N"; | |
| 15 | const string PUNKTY = "P"; | |
| 16 | static int punkty = 0; | |
| 17 | static int rekord = 0; | |
| 18 | static void Main(string[] args) | |
| 19 | {
| |
| 20 | string jeszczeRaz; | |
| 21 | do | |
| 22 | {
| |
| 23 | int pozycjaGracza = 1; | |
| 24 | Random generatorLosowy = new Random(); | |
| 25 | bool czyUderzony = false; | |
| 26 | int speed = 0; | |
| 27 | int czasNitro = -1; | |
| 28 | bool czyPaliwoNitro = false; | |
| 29 | NowaPlansza(10); | |
| 30 | UstawGracza(pozycjaGracza); | |
| 31 | PokazPlansze(); | |
| 32 | //Pętla | |
| 33 | while (!czyUderzony) | |
| 34 | {
| |
| 35 | //sterowanie | |
| 36 | if (Console.KeyAvailable) | |
| 37 | {
| |
| 38 | ConsoleKeyInfo nacisnietyKlawisz = Console.ReadKey(true); | |
| 39 | if (nacisnietyKlawisz.Key == ConsoleKey.RightArrow) | |
| 40 | {
| |
| 41 | if (pozycjaGracza < 2) | |
| 42 | {
| |
| 43 | pozycjaGracza++; | |
| 44 | } | |
| 45 | } | |
| 46 | if (nacisnietyKlawisz.Key == ConsoleKey.LeftArrow) | |
| 47 | {
| |
| 48 | if (pozycjaGracza > 0) | |
| 49 | {
| |
| 50 | pozycjaGracza--; | |
| 51 | } | |
| 52 | } | |
| 53 | if (nacisnietyKlawisz.Key == ConsoleKey.Spacebar && czyPaliwoNitro) | |
| 54 | {
| |
| 55 | if (czasNitro == -1) | |
| 56 | {
| |
| 57 | czasNitro = 10; | |
| 58 | czyPaliwoNitro = false; | |
| 59 | } | |
| 60 | } | |
| 61 | while (Console.KeyAvailable) | |
| 62 | {
| |
| 63 | Console.ReadKey(false); | |
| 64 | } | |
| 65 | } | |
| 66 | ||
| 67 | if (czasNitro == 10) | |
| 68 | {
| |
| 69 | speed += 200; | |
| 70 | czasNitro--; | |
| 71 | } | |
| 72 | else if (czasNitro > 0) | |
| 73 | {
| |
| 74 | czasNitro--; | |
| 75 | } | |
| 76 | else if (czasNitro == 0) | |
| 77 | {
| |
| 78 | speed -= 200; | |
| 79 | czasNitro = -1; | |
| 80 | } | |
| 81 | ||
| 82 | //sprawdzenie uderzenia | |
| 83 | int pozycjaNajblizszejPrzeszkody = plansza[plansza.Length - 2].IndexOf(PRZESZKODA); | |
| 84 | if (pozycjaGracza == pozycjaNajblizszejPrzeszkody) | |
| 85 | {
| |
| 86 | czyUderzony = true; | |
| 87 | } | |
| 88 | else | |
| 89 | {
| |
| 90 | punkty++; | |
| 91 | } | |
| 92 | ||
| 93 | int pozycjaNajblizszegoNitro = plansza[plansza.Length - 2].IndexOf(NITRO); | |
| 94 | if (pozycjaGracza == pozycjaNajblizszegoNitro) | |
| 95 | {
| |
| 96 | czyPaliwoNitro = true; | |
| 97 | } | |
| 98 | ||
| 99 | int pozycjaNajblizszegoPunktu = plansza[plansza.Length - 2].IndexOf(PUNKTY); | |
| 100 | if (pozycjaGracza == pozycjaNajblizszegoPunktu) | |
| 101 | {
| |
| 102 | punkty += 10; | |
| 103 | } | |
| 104 | ||
| 105 | //nowa przeszkoda | |
| 106 | int pozycjaPrzeszkody = generatorLosowy.Next(3); | |
| 107 | string przeszkoda = UstawPrzeszkode(pozycjaPrzeszkody); | |
| 108 | ||
| 109 | if (generatorLosowy.Next(20) == 0) | |
| 110 | {
| |
| 111 | int pozycjaNitro = generatorLosowy.Next(3); | |
| 112 | przeszkoda = UstawNitro(pozycjaNitro, przeszkoda); | |
| 113 | } | |
| 114 | ||
| 115 | ||
| 116 | if (generatorLosowy.Next(20) == 0) | |
| 117 | {
| |
| 118 | int pozycjaPunktow = generatorLosowy.Next(3); | |
| 119 | przeszkoda = UstawPunkty(pozycjaPunktow, przeszkoda); | |
| 120 | } | |
| 121 | ||
| 122 | //przesunięcie planszy w dół | |
| 123 | for (int i = plansza.Length - 2; i > 0; i--) | |
| 124 | {
| |
| 125 | plansza[i] = plansza[i - 1]; | |
| 126 | } | |
| 127 | plansza[0] = przeszkoda; | |
| 128 | ||
| 129 | UstawGracza(pozycjaGracza); | |
| 130 | PokazPlansze(); | |
| 131 | Console.WriteLine($"Nitro: {czyPaliwoNitro}");
| |
| 132 | speed++; | |
| 133 | if (speed > 600) | |
| 134 | {
| |
| 135 | Thread.Sleep(1); | |
| 136 | } | |
| 137 | else | |
| 138 | {
| |
| 139 | Thread.Sleep(600 - speed); | |
| 140 | } | |
| 141 | } | |
| 142 | ||
| 143 | ||
| 144 | Console.Clear(); | |
| 145 | Console.WriteLine("GAME OVER");
| |
| 146 | Console.WriteLine($"Zdobyłeś {punkty} punktów");
| |
| 147 | if(punkty > rekord) | |
| 148 | {
| |
| 149 | Console.WriteLine("NOWY REKORD!!!");
| |
| 150 | rekord = punkty; | |
| 151 | } | |
| 152 | Thread.Sleep(2000); | |
| 153 | Console.WriteLine("Chcesz zagrać jeszcze raz?");
| |
| 154 | jeszczeRaz = Console.ReadLine(); | |
| 155 | punkty = 0; | |
| 156 | } while (jeszczeRaz == "tak" || jeszczeRaz == "Tak"); | |
| 157 | Console.ReadKey(); | |
| 158 | } | |
| 159 | ||
| 160 | private static void NowaPlansza(int rozmiarPlanszy) | |
| 161 | {
| |
| 162 | plansza = new string[rozmiarPlanszy]; | |
| 163 | for (int i = 0; i < plansza.Length; i++) | |
| 164 | {
| |
| 165 | plansza[i] = ""; | |
| 166 | } | |
| 167 | } | |
| 168 | ||
| 169 | private static string UstawPrzeszkode(int pozycja) | |
| 170 | {
| |
| 171 | string linia = " "; | |
| 172 | linia = linia.Insert(pozycja, PRZESZKODA); | |
| 173 | return linia; | |
| 174 | } | |
| 175 | ||
| 176 | private static string UstawNitro(int pozycja, string linia) | |
| 177 | {
| |
| 178 | linia = linia.Remove(pozycja,1).Insert(pozycja, NITRO); | |
| 179 | return linia; | |
| 180 | } | |
| 181 | ||
| 182 | private static string UstawPunkty(int pozycja, string linia) | |
| 183 | {
| |
| 184 | linia = linia.Insert(pozycja, PUNKTY); | |
| 185 | return linia; | |
| 186 | } | |
| 187 | private static void UstawGracza(int pozycja) | |
| 188 | {
| |
| 189 | string linia = " "; //w cudzysłowie 3 spacje | |
| 190 | linia = linia.Insert(pozycja, GRACZ); | |
| 191 | plansza[plansza.Length - 1] = linia; | |
| 192 | } | |
| 193 | ||
| 194 | ||
| 195 | ||
| 196 | private static void PokazPlansze() | |
| 197 | {
| |
| 198 | Console.Clear(); | |
| 199 | for (int i = 0; i < plansza.Length; i++) | |
| 200 | {
| |
| 201 | Console.WriteLine(plansza[i]); | |
| 202 | } | |
| 203 | Console.WriteLine($"Punkty: {punkty}");
| |
| 204 | } | |
| 205 | } | |
| 206 | } | |
| 207 | ||
| 208 |