Advertisement
Guest User

Untitled

a guest
Sep 14th, 2015
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 40.01 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. using System.Threading;
  7. using System.IO;
  8. using System.Text.RegularExpressions;
  9. using System.Xml;
  10. using System.Xml.Serialization;
  11.  
  12. namespace ConsoleApplication10
  13. {
  14.  
  15.  
  16. public class doxml
  17. {
  18. public string nazwa { get; set; }
  19. public int wynik { get; set; }
  20.  
  21. public doxml(string na, int wy)
  22. {
  23. nazwa = na;
  24. wynik = wy;
  25. }
  26. public doxml() { } // konstruktor domyslny konieczny dla serializacji
  27. }
  28. //-------------------------------------------------------------
  29. [XmlRoot("doxmlCollection")]
  30. public class doxmlContainer
  31. {
  32. [XmlArray("wyniki"), XmlArrayItem("doxml")]
  33. public doxml[] wyniki { get; set; }
  34.  
  35. public doxmlContainer(doxml[] tab)
  36. {
  37. wyniki = new doxml[tab.Length];
  38. for (int i = 0; i < tab.Length; i++)
  39. {
  40. wyniki[i] = tab[i];
  41. }
  42. }
  43. public doxmlContainer() { } // konstruktor domyslny konieczny dla serializacji
  44.  
  45. // Serializacja
  46. public void Save(string path)
  47. {
  48. var serializer = new XmlSerializer(typeof(doxmlContainer));
  49. using (var stream = new FileStream(path, FileMode.Create))
  50. {
  51. serializer.Serialize(stream, this);
  52. }
  53. }
  54.  
  55. // Deserializacja
  56. public static doxmlContainer Load(string path)
  57. {
  58. var serializer = new XmlSerializer(typeof(doxmlContainer));
  59. using (var stream = new FileStream(path, FileMode.Open))
  60. {
  61. return serializer.Deserialize(stream) as doxmlContainer;
  62. }
  63. }
  64.  
  65. //ladowanie xml na podstawie lancucha znakowego
  66. public static doxmlContainer LoadFromText(string text)
  67. {
  68. var serializer = new XmlSerializer(typeof(doxmlContainer));
  69. return serializer.Deserialize(new StringReader(text)) as doxmlContainer;
  70. }
  71. }
  72.  
  73. public class highscores : IComparable<highscores>
  74. {
  75. private int liczba;
  76. private string danegracza;
  77.  
  78. public int CompareTo(highscores probka)
  79. {
  80. return this.liczba.CompareTo(probka.liczba);
  81. }
  82.  
  83. public highscores(int l1, string d1)
  84. {
  85. this.liczba = l1;
  86. this.danegracza = d1;
  87. }
  88.  
  89. public override string ToString()
  90. {
  91. return liczba.ToString() + " " + danegracza;
  92. }
  93. }
  94.  
  95. class auto
  96. {
  97. //zmienne klasy
  98. private int bak { get; set; } //zmienna obslugiwana przez właściwość
  99. static int kasa; //zmienna statyczna
  100. public string marka;
  101. public string model;
  102. public float predkosc;
  103. public float osiagi;
  104. public int punkty;
  105. public int koniecgry;
  106.  
  107. static auto() //funkcja przypisująca zmiennej statycznej wartość
  108. {
  109. kasa = 500;
  110. }
  111.  
  112. public void kasap() //funkcja przypisująca zmiennej statycznej wartość
  113. {
  114. kasa = 500;
  115. }
  116.  
  117. public auto(string mar, string mod) // konstruktor
  118. {
  119. marka = mar;
  120. model = mod;
  121. }
  122.  
  123. public auto(string mar, string mod, //konstruktor złożony
  124. int ofiary)
  125. : this(mar, mod)
  126. {
  127. punkty = ofiary;
  128. }
  129.  
  130. public auto(auto poprzednieauto) //konstruktor kopiujący
  131. {
  132. marka = poprzednieauto.marka;
  133. model = poprzednieauto.model;
  134. punkty = poprzednieauto.punkty;
  135. }
  136.  
  137. public static double operator +(double a, auto B)
  138. {
  139. return (a + B.wyniki());
  140. }
  141.  
  142. //funkcje i metody programu
  143. public int wyniki()
  144. {
  145. return (punkty * kasa);
  146. }
  147.  
  148. public void jedz(int selectedlang)
  149. {
  150. predkosc = predkosc + 10;
  151. if (predkosc > osiagi)
  152. {
  153. if (selectedlang == 1) Console.WriteLine("Więcej nie pojedzie!");
  154. if (selectedlang == 2) Console.WriteLine("You can't get any faster!");
  155. predkosc = osiagi;
  156. }
  157. if (selectedlang == 1)
  158. {
  159. Console.WriteLine("Gaz do dechy!");
  160. Console.WriteLine("Twoja prędkosc wynosi " + predkosc + "km/h.");
  161. Console.WriteLine("Stan twojego baku wynosi " + stanbaku() + ".");
  162. }
  163. if (selectedlang == 2)
  164. {
  165. Console.WriteLine("You push the pedal to the limit!");
  166. Console.WriteLine("Your speed equals " + predkosc + "km/h.");
  167. Console.WriteLine("You have " + stanbaku() + " liters of petrol left.");
  168. }
  169. }
  170.  
  171. public void wprawo(int selectedlang)
  172. {
  173. predkosc = predkosc - (predkosc / 2);
  174. if (selectedlang == 1)
  175. {
  176. Console.WriteLine("Skręcasz w prawo.");
  177. Console.WriteLine("Twoja prędkość wynosi " + predkosc + "km/h.");
  178. Console.WriteLine("Stan twojego baku wynosi " + stanbaku() + ".");
  179. }
  180. if (selectedlang == 2)
  181. {
  182. Console.WriteLine("You turn right.");
  183. Console.WriteLine("Your speed equals " + predkosc + "km/h.");
  184. Console.WriteLine("You have " + stanbaku() + " liters of petrol left.");
  185. }
  186. }
  187.  
  188. public void wlewo(int selectedlang)
  189. {
  190. predkosc = predkosc - (predkosc / 2);
  191. if (selectedlang == 1)
  192. {
  193. Console.WriteLine("Skręcasz w lewo.");
  194. Console.WriteLine("Twoja prędkość wynosi " + predkosc + "km/h.");
  195. Console.WriteLine("Stan twojego baku wynosi " + stanbaku() + ".");
  196. }
  197. if (selectedlang == 2)
  198. {
  199. Console.WriteLine("You turn right.");
  200. Console.WriteLine("Your speed equals " + predkosc + "km/h.");
  201. Console.WriteLine("You have " + stanbaku() + " liters of petrol left.");
  202. }
  203. }
  204.  
  205. public int stankasy()
  206. {
  207. return kasa;
  208. }
  209.  
  210. public int stanbaku()
  211. {
  212. return bak;
  213. }
  214.  
  215. public void tankowanie(int litry, int selectedlang)
  216. {
  217. if (kasa >= litry * 5)
  218. {
  219. kasa = kasa - (litry * 5);
  220. bak = bak + litry;
  221. }
  222. else
  223. {
  224. if (selectedlang == 1) Console.WriteLine("Nie masz tyle kasy!");
  225. if (selectedlang == 2) Console.WriteLine("You don't have enough money!");
  226. }
  227. }
  228.  
  229. public void stanbakup()
  230. {
  231. bak = 40;
  232. }
  233.  
  234. public void spalanie()
  235. {
  236. if (predkosc > 0 && predkosc <= 30) bak = bak - 2;
  237. if (predkosc > 30 && predkosc <= 80) bak = bak - 4;
  238. if (predkosc > 80 && predkosc <= 130) bak = bak - 6;
  239. if (predkosc > 130 && predkosc <= 170) bak = bak - 8;
  240. if (predkosc > 170) bak = bak - 10;
  241. }
  242.  
  243.  
  244. public void sprawdzbak(int selectedlang)
  245. {
  246. if (bak <= 0)
  247. {
  248. bak = 0;
  249. if (selectedlang == 1) Console.WriteLine("Skończyło Ci się paliwo! KONIEC GRY!");
  250. if (selectedlang == 2) Console.WriteLine("You runned out of fuel! GAME OVER!");
  251. koniecgry = 1;
  252. // Environment.Exit(3);
  253. }
  254. }
  255.  
  256. public void zarabiaj()
  257. {
  258. int los2;
  259. Random rnd1 = new Random();
  260. los2 = rnd1.Next(5 + 1);
  261. kasa = kasa + (int)predkosc * los2;
  262. }
  263.  
  264. public void prezentuj()
  265. {
  266. Console.WriteLine("{0} {1} \t {2}", marka, model, punkty);
  267. }
  268. }
  269.  
  270. class Program
  271. {
  272. public static void graj(int selectedlang)
  273. {
  274. List<highscores> numlist = new List<highscores>(); //deklaracja listy do wyników globalnych
  275. string s2 = string.Empty; //zmienna przechowujaca liste jako string
  276. int los; //zmienne pomocnicze
  277. double wynikpom = 0; //zmienna pomocnicza do sumowania wyniku lokalnego
  278. int licznik = 0;
  279. int zmcatch = 0;
  280. int odp = 0;
  281. int odp2 = 0;
  282. int odp3 = 0;
  283. int wybor = 0;
  284. int litry = 0;
  285. string dolisty = string.Empty; //dolisty = czesc stringa wczytana z pliku txt ktora dodajemy do listy jako arg 2 konstruktora
  286.  
  287. FileStream fs12 = new FileStream(@"highscores.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite); //strumien
  288. StreamReader odczytwynikow = new StreamReader(fs12);
  289. fs12.Position = 0;
  290. while ((dolisty = odczytwynikow.ReadLine()) != null) //przejscie przez kazda linie pliku tekstowego
  291. {
  292. string liczbawyniku = dolisty.Substring(0, dolisty.IndexOf(" ")).Replace(" ", ""); //liczbawyniku = wyciecie z calej wczytanej linii jedynie liczby jako string
  293. dolisty = dolisty.Substring(dolisty.IndexOf(" ")); //wyciecie czesci wczytanej linii zaczynajac od znaku spacji
  294. dolisty = dolisty.Remove(0, 1); //usuniecie znaku spacji
  295. numlist.Add(new highscores(int.Parse(liczbawyniku), dolisty)); //wczytanie liczby jak i marki + modelu z wczytanej linii do konstruktowa listy
  296. }
  297.  
  298. odczytwynikow.Close(); //zamkniecie strumienia
  299. auto[] domyslne = new auto[1]; //domyslna tablica wynikow lokalnych
  300. domyslne[0] = new auto("--", "--", 0); //wartosci domyslne tablicy lokalnej
  301. auto[] wyniki = new auto[10];
  302. for (int i = 0; i < 10; i++) wyniki[i] = new auto(domyslne[0]); //wypelnienie lokalnej tablicy wynikow tymi samymi wartosciami
  303. do
  304. {
  305. int fragi = 0; //zerowanie zmiennej odp za liczbe przejechanych ludzi
  306. grafika(); //animacja samochodziku
  307. ekranstart(selectedlang); //ekran startowy opis gry
  308. string mar, mod; //marka, model
  309. if (selectedlang == 1) Console.WriteLine("Podaj markę swojego samochodu:");
  310. if (selectedlang == 2) Console.WriteLine("What brand is your car?");
  311. mar = (Console.ReadLine());
  312. if (selectedlang == 1) Console.WriteLine("Podaj model samochodu:");
  313. if (selectedlang == 2) Console.WriteLine("Please provide exact car model:");
  314. mod = (Console.ReadLine());
  315. auto gracz1 = new auto(mar, mod);
  316. gracz1.koniecgry = 0; //ustawienie wartosci koncagry dla gracza 1 na 0, czyli false
  317. int licznikprob = 0;
  318. do
  319. {
  320. do
  321. {
  322. if (selectedlang == 1) Console.WriteLine("Podaj maksymalną prędkość tego cuda:");
  323. if (selectedlang == 2) Console.WriteLine("And what is the max speed of it?:");
  324. try
  325. {
  326. gracz1.osiagi = int.Parse(Console.ReadLine());
  327. zmcatch = 1;
  328. }
  329. catch
  330. {
  331. zmcatch = 0;
  332. if (licznikprob > 1)
  333. {
  334. if (selectedlang == 1) Console.WriteLine("No co, nie rozumiesz? LICZBĘ!");
  335. if (selectedlang == 2) Console.WriteLine("What the... NUMBER! What don't you understand?!");
  336. }
  337. else
  338. if (selectedlang == 1)
  339. {
  340. Console.WriteLine("Prędkość musisz podać jako liczbę.");
  341. Console.Write("Więc spytam jeszcze raz, ");
  342. }
  343. if (selectedlang == 2)
  344. {
  345. Console.WriteLine("Speed must be given as number value.");
  346. Console.Write("So let me ask again, ");
  347. }
  348. }
  349. licznikprob += 1;
  350. } while (zmcatch == 0);
  351.  
  352. if (gracz1.osiagi > 250 && selectedlang == 1) Console.WriteLine("No chyba żartujesz? ");
  353. if (gracz1.osiagi > 250 && selectedlang == 2) Console.WriteLine("You are joking, right? ");
  354. } while (gracz1.osiagi > 250);
  355. grafika();
  356. if (selectedlang == 1)
  357. {
  358. Console.WriteLine("Marka: " + gracz1.marka);
  359. Console.WriteLine("Model: " + gracz1.model);
  360. Console.WriteLine("Prędkość maksymalna: " + gracz1.osiagi);
  361. Console.WriteLine("Czy chcesz zapisac dane o grze do pliku?");
  362. }
  363. if (selectedlang == 2)
  364. {
  365. Console.WriteLine("Brand: " + gracz1.marka);
  366. Console.WriteLine("Model: " + gracz1.model);
  367. Console.WriteLine("Max speed: " + gracz1.osiagi);
  368. Console.WriteLine("Do you want to export your track into txt?");
  369. }
  370.  
  371. do
  372. {
  373. taknie(selectedlang);
  374. try
  375. {
  376. odp = int.Parse(Console.ReadLine());
  377. }
  378. catch
  379. {
  380. }
  381. } while (odp != 1 && odp != 2);
  382. if (odp == 1 && !File.Exists("zapis.txt")) //sprawdzenie czy plik zapisu trasy istnieje
  383. {
  384. File.CreateText("zapis.txt"); //utworzenie pliku
  385. }
  386. if (odp == 1)
  387. {
  388. System.IO.File.AppendAllText(@"zapis.txt", "Marka: " + gracz1.marka + Environment.NewLine); //wpisanie podstawowych wartosci danego gracza do pliku z opisem trasy
  389. System.IO.File.AppendAllText(@"zapis.txt", "Model: " + gracz1.model + Environment.NewLine);
  390. System.IO.File.AppendAllText(@"zapis.txt", "Predkosc maksymalna: " + gracz1.osiagi + Environment.NewLine);
  391. }
  392. gracz1.stanbakup(); //wyzerowanie stanu baku
  393. gracz1.kasap(); //wyzerowanie stanu kasy
  394. informacje(selectedlang); //info o sterowaniu
  395. // GŁÓWNA PĘTLA GRY
  396. do
  397. {
  398. gracz1.sprawdzbak(selectedlang); //sprawdzenie czy mozna w ogole jechac
  399. if (gracz1.predkosc <= 0)
  400. {//zmuszenie do ruszania begin
  401. informacje(selectedlang);
  402. if (selectedlang == 1) Console.WriteLine("Musisz przyśpieszyć bo stoisz w miejscu!");
  403. if (selectedlang == 2) Console.WriteLine("You need to push some pedal first!");
  404. do
  405. {
  406. do
  407. {
  408. if (selectedlang == 1) Console.WriteLine("Wybierz opcję nr.1 by ruszyć!");
  409. if (selectedlang == 2) Console.WriteLine("Choose option number 1 to start!");
  410. try
  411. {
  412. wybor = int.Parse(Console.ReadLine());
  413. }
  414. catch
  415. {
  416. }
  417. } while (wybor != 1);
  418. if (wybor == 1)
  419. {
  420. gracz1.predkosc = 0;
  421. gracz1.jedz(selectedlang);
  422. gracz1.spalanie();
  423. }
  424. } while (wybor > 1);
  425. }//zmuszenie do ruszania end
  426.  
  427. Random rnd2 = new Random();
  428. los = rnd2.Next(5 + 1);
  429. if (los < 1 && gracz1.predkosc > 30)
  430. {
  431. if (selectedlang == 1) Console.WriteLine("WHOA! DZIKI PIESZY POJAWIŁ SIĘ NA DRODZE! Czy chcesz go przejechać?");
  432. if (selectedlang == 2) Console.WriteLine("WHOA! WILD HUMAN APPEARED! Do You want to drive through him?");
  433.  
  434. do
  435. {
  436. taknie(selectedlang);
  437. try
  438. {
  439. odp2 = int.Parse(Console.ReadLine());
  440. }
  441. catch
  442. {
  443. }
  444. } while (odp2 != 1 && odp2 != 2);
  445.  
  446. if (odp2 == 1)
  447. {
  448. gracz1.zarabiaj();
  449. if (selectedlang == 1) Console.WriteLine("Przejechałeś pieszego! Zdobywasz kasę! Masz juz " + gracz1.stankasy() + "! Co dalej?");
  450. if (selectedlang == 2) Console.WriteLine("You killed a pedestrian! You also grabbed his cash, now you have " + gracz1.stankasy() + "! What's next?");
  451. fragi = fragi + 1;
  452. if (odp == 1) System.IO.File.AppendAllText(@"zapis.txt", "Przejechano " + fragi + " z kolei piszego. Idzie Ci coraz lepiej!" + Environment.NewLine);
  453. }
  454. if (odp2 == 2)
  455. {
  456. if (selectedlang == 1) Console.WriteLine("Cienias! Jedziesz dalej czy się boisz?");
  457. if (selectedlang == 2) Console.WriteLine("Loser! Do you even continue or are you scared?");
  458. if (odp == 1) System.IO.File.AppendAllText(@"zapis.txt", "Ajj.. Powiedzmy że Ci uciekł.. Tym razem.." + Environment.NewLine);
  459. }
  460. }
  461. do
  462. {
  463. try
  464. {
  465. wybor = int.Parse(Console.ReadLine());
  466. }
  467. catch
  468. {
  469. }
  470. } while (wybor != 1 && wybor != 2 && wybor != 3 && wybor != 4 && wybor != 5);
  471. switch (wybor)
  472. {
  473. case 1: informacje(selectedlang);
  474. if (selectedlang == 1) Console.WriteLine("konto: " + gracz1.stankasy());
  475. if (selectedlang == 2) Console.WriteLine("Cash: " + gracz1.stankasy());
  476. gracz1.jedz(selectedlang);
  477. gracz1.spalanie();
  478. if (odp == 1)
  479. {
  480. System.IO.File.AppendAllText(@"zapis.txt", "Przyśpieszono, prędkosc wynosi: " + gracz1.predkosc + " a stan paliwa: " + gracz1.stanbaku() + Environment.NewLine);
  481. }
  482. break;
  483. case 2: informacje(selectedlang);
  484. if (selectedlang == 1) Console.WriteLine("konto: " + gracz1.stankasy());
  485. if (selectedlang == 2) Console.WriteLine("Cash: " + gracz1.stankasy());
  486. gracz1.wprawo(selectedlang);
  487. gracz1.spalanie();
  488. if (odp == 1)
  489. {
  490. System.IO.File.AppendAllText(@"zapis.txt", "Skręcono w prawo, prędkość wynosi: " + gracz1.predkosc + " a stan paliwa: " + gracz1.stanbaku() + Environment.NewLine);
  491. }
  492. break;
  493. case 3: informacje(selectedlang);
  494. if (selectedlang == 1) Console.WriteLine("konto: " + gracz1.stankasy());
  495. if (selectedlang == 2) Console.WriteLine("Cash: " + gracz1.stankasy());
  496. gracz1.wlewo(selectedlang);
  497. gracz1.spalanie();
  498. if (odp == 1)
  499. {
  500. System.IO.File.AppendAllText(@"zapis.txt", "Skręcono w lewo, prędkość wynosi: " + gracz1.predkosc + " a stan paliwa: " + gracz1.stanbaku() + Environment.NewLine);
  501. }
  502. break;
  503. case 4: informacje(selectedlang);
  504. if (selectedlang == 1)
  505. {
  506. Console.WriteLine("konto: " + gracz1.stankasy());
  507. Console.WriteLine("To ile tankujemy?");
  508. }
  509. if (selectedlang == 2)
  510. {
  511. Console.WriteLine("Cash: " + gracz1.stankasy());
  512. Console.WriteLine("So how much you want to tank?");
  513. }
  514.  
  515.  
  516.  
  517. do
  518. {
  519. if (selectedlang == 1) Console.WriteLine("Podaj liczbę litrów.");
  520. if (selectedlang == 2) Console.WriteLine("Input a number of litres.");
  521.  
  522. try
  523. {
  524. litry = int.Parse(Console.ReadLine());
  525. zmcatch = 1;
  526. }
  527. catch
  528. {
  529. zmcatch = 0;
  530. }
  531. } while (zmcatch == 0);
  532. //litry = int.Parse(Console.ReadLine());
  533. gracz1.tankowanie(litry, selectedlang);
  534. gracz1.stanbaku();
  535. if (selectedlang == 1) Console.WriteLine("Co dalej?");
  536. if (selectedlang == 2) Console.WriteLine("What's next?");
  537. if (odp == 1)
  538. {
  539. System.IO.File.AppendAllText(@"zapis.txt", "Zatankowano, stan paliwa wynosi: " + gracz1.stanbaku() + Environment.NewLine);
  540. }
  541. break;
  542. case 5:
  543. if (selectedlang == 1)
  544. {
  545. Console.WriteLine("Wychodzisz z samochodu");
  546. Console.WriteLine("Koniec gry!");
  547. }
  548. if (selectedlang == 2)
  549. {
  550. Console.WriteLine("You are leaving the car.");
  551. Console.WriteLine("GAME OVER!");
  552. }
  553. if (odp == 1)
  554. {
  555. System.IO.File.AppendAllText(@"zapis.txt", "Opuszczono samochod" + Environment.NewLine);
  556. }
  557. break;
  558. }
  559. } while (wybor < 5 && gracz1.koniecgry == 0);
  560. if (odp == 1)
  561. {
  562. System.IO.File.AppendAllText(@"zapis.txt", "Podczas calej podrozy przejechano " + fragi + " osob." + Environment.NewLine);
  563. }
  564. gracz1.punkty = fragi;
  565. wyniki[licznik] = new auto(gracz1.marka, gracz1.model, gracz1.wyniki());
  566. licznik = licznik + 1;
  567. if (selectedlang == 1) Console.WriteLine("TABLICA WYNIKÓW LOKALNYCH");
  568. if (selectedlang == 2) Console.WriteLine("LOCAL HIGHSCORES");
  569. foreach (auto x in wyniki)
  570. {
  571. x.prezentuj();
  572. }
  573. if (selectedlang == 1) Console.Write("Wynik Łączny: ");
  574. if (selectedlang == 2) Console.Write("Total score: ");
  575. wynikpom = wynikpom + gracz1;
  576. Console.WriteLine(wynikpom);
  577. numlist.Add(new highscores(gracz1.wyniki(), gracz1.marka + " " + gracz1.model));
  578. System.IO.File.AppendAllText(@"highscores.txt", (gracz1.wyniki() + " " + gracz1.marka + " " + gracz1.model) + Environment.NewLine);
  579. if (selectedlang == 1) Console.WriteLine("Czy chcesz grać dalej?");
  580. if (selectedlang == 2) Console.WriteLine("Do you want to play again?");
  581. do
  582. {
  583. taknie(selectedlang);
  584. try
  585. {
  586. odp3 = int.Parse(Console.ReadLine());
  587. }
  588. catch
  589. {
  590. }
  591. } while (odp3 != 1 && odp3 != 2);
  592. } while (odp3 == 1);
  593. //outro, czyszczenie konsoli + tablica wyników od najwyzszego do najnizszego.
  594. grafika();
  595. numlist.Sort();
  596. numlist.Reverse();
  597. s2 = string.Empty;
  598. foreach (highscores col in numlist)
  599. {
  600. s2 += col.ToString() + " " + Environment.NewLine;
  601. }
  602. System.Console.WriteLine("HIGHSCORES" + Environment.NewLine + "{0}", s2);
  603. if (selectedlang == 1) Console.WriteLine("Wciśnięcie dowolnego klawisza powraca do menu.");
  604. if (selectedlang == 2) Console.WriteLine("Press any key to return to main menu");
  605. Console.ReadKey();
  606. grafika();
  607. }
  608.  
  609. public static void intro(int selectedlang)
  610. {
  611. Random ladowanie = new Random();
  612. int procent = 0;
  613. string tekstladowania = String.Empty;
  614. string odstepprzedprocentem = String.Empty;
  615. for (int i = 0; i < 51; i++)
  616. {
  617. Console.Clear();
  618. Console.WriteLine(@" _____ __ __ ____ ___ __ ");
  619. Console.WriteLine(@" / ___// /_________ ___ / /_/ __ )____ _____ ____/ (_) /_");
  620. Console.WriteLine(@" \__ \/ __/ ___/ _ \/ _ \/ __/ __ / __ `/ __ \/ __ / / __/");
  621. Console.WriteLine(@" ___/ / /_/ / / __/ __/ /_/ /_/ / /_/ / / / / /_/ / / /_ ");
  622. Console.WriteLine(@"/____/\__/_/ \___/\___/\__/_____/\__,_/_/ /_/\__,_/_/\__/ " + Environment.NewLine);
  623. int czas = ladowanie.Next(1, 50);
  624. tekstladowania += "▓";
  625. if (i > 2)
  626. {
  627. odstepprzedprocentem += " ";
  628. }
  629. Console.WriteLine(tekstladowania);
  630. Console.Write(odstepprzedprocentem + procent + "%" + Environment.NewLine);
  631.  
  632. if (i < 50 && selectedlang == 1)
  633. {
  634. int wiadomosc = ladowanie.Next(1, 1000);
  635. if (wiadomosc < 100) Console.WriteLine("sprowadzanie samochodów z Niemiec...");
  636. if (wiadomosc > 100 && wiadomosc < 200) Console.WriteLine("Ustawianie pieszych...");
  637. if (wiadomosc > 200 && wiadomosc < 300) Console.WriteLine("Szukanie stacji radiowej Disco Polo...");
  638. if (wiadomosc > 300 && wiadomosc < 400) Console.WriteLine("Ustawianie wszystkich świateł na zielone...");
  639. if (wiadomosc > 400 && wiadomosc < 500) Console.WriteLine("Naprawa wcześniej uszkodzonych aut w garażu u Wieśka...");
  640. if (wiadomosc > 500 && wiadomosc < 600) Console.WriteLine("Casting statystów do roli pieszych...");
  641. if (wiadomosc > 600 && wiadomosc < 700) Console.WriteLine("Przekupowanie policji pączkami...");
  642. if (wiadomosc > 700 && wiadomosc < 800) Console.WriteLine("Tworzenie zmiennych i innych pierdół dla danych gry...");
  643. if (wiadomosc > 800 && wiadomosc < 900) Console.WriteLine("Ustawianie pułapek dla cykorów uciekających z samochodów...");
  644. if (wiadomosc > 900 && wiadomosc < 1000) Console.WriteLine("Okradanie banku by dać kasę ludziom i kierowcy...");
  645. }
  646. if (i < 50 && selectedlang == 2)
  647. {
  648. int wiadomosc = ladowanie.Next(1, 1000);
  649. if (wiadomosc < 100) Console.WriteLine("Getting used cars from Germany...");
  650. if (wiadomosc > 100 && wiadomosc < 200) Console.WriteLine("Placing pedestrians...");
  651. if (wiadomosc > 200 && wiadomosc < 300) Console.WriteLine("Searching for a country radiostation...");
  652. if (wiadomosc > 300 && wiadomosc < 400) Console.WriteLine("Setting all lights green...");
  653. if (wiadomosc > 400 && wiadomosc < 500) Console.WriteLine("Fixing damaged cars in suspicious garage...");
  654. if (wiadomosc > 500 && wiadomosc < 600) Console.WriteLine("Searching for people to play pedestrians role...");
  655. if (wiadomosc > 600 && wiadomosc < 700) Console.WriteLine("Bribing the police with doghnuts...");
  656. if (wiadomosc > 700 && wiadomosc < 800) Console.WriteLine("Creating variables and other game-data related crap...");
  657. if (wiadomosc > 800 && wiadomosc < 900) Console.WriteLine("Setting a traps for losers escaping from cars...");
  658. if (wiadomosc > 900 && wiadomosc < 1000) Console.WriteLine("Robbing a bank to get cash for pedestrians and driver...");
  659. }
  660. Thread.Sleep(czas);
  661. procent += 2;
  662. }
  663. if (selectedlang == 1) Console.Write("Wciśnij dowolny klawisz by kontynuować...");
  664. if (selectedlang == 2) Console.Write("Press any key to continue...");
  665.  
  666. Console.ReadKey();
  667. }
  668.  
  669. public static void autor()
  670. {
  671. for (int i = 0; i < 200; i++)
  672. {
  673. Random rand = new Random();
  674. int kolor = rand.Next(5);
  675. switch (kolor)
  676. {
  677. case 0: Console.ForegroundColor = ConsoleColor.Yellow; break;
  678. case 1: Console.ForegroundColor = ConsoleColor.Red; break;
  679. case 2: Console.ForegroundColor = ConsoleColor.Green; break;
  680. case 3: Console.ForegroundColor = ConsoleColor.Blue; break;
  681. case 4: Console.ForegroundColor = ConsoleColor.White; break;
  682. }
  683. Console.WriteLine("Dawid Poleszczuk");
  684. Console.ResetColor();
  685. Thread.Sleep(50);
  686. Console.Clear();
  687. }
  688. Console.WriteLine("Dobra, starczy tego. Wciśnij enter by kontynuować...");
  689. Console.ReadKey();
  690. Console.Clear();
  691. }
  692.  
  693. public static void taknie(int selectedlang)
  694. {
  695. if (selectedlang == 1) Console.WriteLine("1=TAK/2=NIE");
  696. if (selectedlang == 2) Console.WriteLine("1=YES/2=NO");
  697. }
  698.  
  699. public static void ekranstart(int selectedlang)
  700. {
  701. if (selectedlang == 1)
  702. {
  703. Console.WriteLine("Witaj w Symulatorze Pirata Drogowego!" + Environment.NewLine);
  704.  
  705. Console.WriteLine("Jak grać?:");
  706. Console.WriteLine("Klawisze 1-5 służą do kontroli pojazdu. Enter zatwierdza wybór opcji.");
  707. Console.WriteLine("Jednak uważaj! Na drodze pojawiają się piesi!");
  708. Console.WriteLine("Za przejechanie pieszego zdobywasz pieniądze, które mozesz wydać na benzynkę." + Environment.NewLine + "(A na co innego byś chciał?).");
  709. Console.WriteLine("Im wyższa jest twoja prędkość, tym więcej pieniędzy wyrzucają twoje ofiary!");
  710. Console.WriteLine("Gra kończy się, jeśli skończy Ci się paliwo lub UCIEKNIESZ z samochodu.");
  711. Console.WriteLine("Oczywiście im szybciej jedziesz, tym szybciej kończy się benzyna w baku. :-)");
  712. Console.WriteLine("Kazdy zakręt wytrąca połowę aktualnej prędkosci samochodu." + Environment.NewLine + "Tak, masz popsute hamulce :-)");
  713. Console.WriteLine("Powodzenia!" + Environment.NewLine);
  714. Console.WriteLine("Wciśnij enter by kontynuować...");
  715. }
  716. if (selectedlang == 2)
  717. {
  718. Console.WriteLine("Welcome in street bandit simulator!" + Environment.NewLine);
  719.  
  720. Console.WriteLine("How to play?:");
  721. Console.WriteLine("Use keys 1-5 to control your car.");
  722. Console.WriteLine("But beware! There will be pedestrians appearing on street!");
  723. Console.WriteLine("For driving through pedestrians you can get money, which you use to refuel." + Environment.NewLine + "(What else would you want??).");
  724. Console.WriteLine("The higher your speed is, the more cash your victims drops!");
  725. Console.WriteLine("Game ends if you run out of petrol, or if you ESCAPE from your car.");
  726. Console.WriteLine("The faster you drive, the faster your car runs out of petrol. :-)");
  727. Console.WriteLine("Every turn loses half of your current speed." + Environment.NewLine + "Yes, Your brakes are broken :-)");
  728. Console.WriteLine("Good Luck!" + Environment.NewLine);
  729. Console.WriteLine("Press the return key to continue...");
  730. }
  731. Console.ReadKey();
  732. Console.Clear();
  733. }
  734.  
  735. public static void informacje(int selectedlang) //animacja jadącego autka
  736. {
  737. Console.Clear();
  738. if (selectedlang == 1) Console.WriteLine(":: (1) gaz! :: (2) w prawo! :: (3) w lewo! :: (4) tankowanko :: (5) ucieknij ::");
  739. if (selectedlang == 2) Console.WriteLine(":: (1) Push it! :: (2) turn right! :: (3) left! :: (4) refuel :: (5) escape ::");
  740. }
  741.  
  742. public static void grafika() //animacja jadącego autka
  743. {
  744. string odstep;
  745. odstep = " ";
  746. for (int i = 0; i < 29; i++)
  747. {
  748. Console.WriteLine(odstep + @" _..-------++._");
  749. Console.WriteLine(odstep + @" _.-'/ | _|| \--._");
  750. Console.WriteLine(odstep + @" __.--'`._/_\j_____/_||___\ `----.");
  751. Console.WriteLine(odstep + @" _.--'_____ | \ _____ /");
  752. Console.WriteLine(odstep + @" _j /,---.\ | =o | /,---.\ |_");
  753. Console.WriteLine(odstep + @"[__]==// .-. \\==`===========/==// .-. \\=[__]");
  754. Console.WriteLine(odstep + @" `-._|\ `-' /|___\_________/___|\ `-' /|_.'");
  755. Console.WriteLine(odstep + @" `---' `---'");
  756. odstep = odstep.Remove(1, 1);
  757. Thread.Sleep(10);
  758. Console.Clear();
  759. }
  760. }
  761.  
  762. public static void serializacja()
  763. {
  764.  
  765. int licznik = 0;
  766. foreach (string line in File.ReadLines(@"highscores.txt"))
  767. {
  768. if (line != String.Empty) ++licznik;
  769. } //zliczanie liczby linii w pliku highscores
  770.  
  771. string path = @"wyniki.xml";
  772.  
  773. string dolisty = string.Empty;
  774. FileStream fs12 = new FileStream(@"highscores.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite); //strumien
  775. StreamReader odczytwynikow = new StreamReader(fs12);
  776. fs12.Position = 0;
  777.  
  778. doxml[] tab = new doxml[licznik];
  779. int licznik2 = 0;
  780. while ((dolisty = odczytwynikow.ReadLine()) != null) //przejscie przez kazda linie pliku tekstowego
  781. {
  782. string liczbawyniku = dolisty.Substring(0, dolisty.IndexOf(" ")).Replace(" ", ""); //liczbawyniku = wyciecie z calej wczytanej linii jedynie liczby jako string
  783. dolisty = dolisty.Substring(dolisty.IndexOf(" ")); //wyciecie czesci wczytanej linii zaczynajac od znaku spacji
  784. dolisty = dolisty.Remove(0, 1); //usuniecie znaku spacji
  785. tab[licznik2] = new doxml(dolisty, int.Parse(liczbawyniku));
  786. licznik2++;
  787. }
  788. doxmlContainer obj = new doxmlContainer(tab);
  789. obj.Save(path);
  790. odczytwynikow.Close(); //zamkniecie strumienia
  791. Console.WriteLine("Serializacja wyników przeprowadzona pomyślnie.");
  792. Console.WriteLine("Test deserializacji: ");
  793.  
  794. //test deserializacji
  795. var doxmlCollection1 = doxmlContainer.Load(path);
  796. foreach (var element in doxmlCollection1.wyniki)
  797. {
  798. Console.WriteLine("{0} {1}", element.nazwa, element.wynik);
  799. }
  800. Console.ReadKey();
  801. }
  802. static void Main(string[] args)
  803. {
  804. Console.BackgroundColor = ConsoleColor.Blue;
  805. Console.ForegroundColor = ConsoleColor.White;
  806. int menuster = 0;
  807. int wyborjezyka = 0;
  808.  
  809. grafika();
  810.  
  811. poczatek:
  812. Console.Clear();
  813. do //petla do wyboru opcji jezyka, zapobiega wpisaniu innej opcji niz te dostepne.
  814. {
  815. Console.Clear();
  816. Console.WriteLine("Choose language.");
  817. Console.WriteLine("1. Polski"); Console.WriteLine("2. English");
  818. try
  819. {
  820. wyborjezyka = int.Parse(Console.ReadLine());
  821. }
  822. catch
  823. {
  824. }
  825. } while (wyborjezyka != 1 && wyborjezyka != 2);
  826.  
  827. Console.Clear();
  828.  
  829. do //petla do wyboru opcji z menu, zapobiega wpisaniu innej opcji niz te dostepne.
  830. {
  831. Console.Clear();
  832. switch (wyborjezyka)
  833. {
  834. case 1:
  835. Console.WriteLine("MENU"); Console.WriteLine("1. Graj"); Console.WriteLine("2. Autor"); Console.WriteLine("3. Wyjscie"); Console.WriteLine("4. Serializacja danych");
  836. break;
  837. case 2:
  838. Console.WriteLine("MENU"); Console.WriteLine("1. New game"); Console.WriteLine("2. Author"); Console.WriteLine("3. Exit"); Console.WriteLine("4. Data serialisation");
  839. break;
  840. //case 3: - latwe dodanie menu w nast jezyku
  841. }
  842. try
  843. {
  844. menuster = int.Parse(Console.ReadLine());
  845. }
  846. catch
  847. {
  848. }
  849. } while (menuster != 1 && menuster != 2 && menuster != 3 && menuster != 4);
  850.  
  851. switch (menuster)
  852. {
  853. case 1:
  854. grafika();
  855. intro(wyborjezyka);
  856. graj(wyborjezyka);
  857. goto poczatek;
  858. break;
  859. case 2:
  860. autor();
  861. goto poczatek;
  862. break;
  863. case 3:
  864. grafika();
  865. Environment.Exit(0);
  866. break;
  867. case 4:
  868. serializacja();
  869. break;
  870. default:
  871. goto poczatek;
  872. }
  873.  
  874. }
  875. }
  876. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement