Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Threading;
- using System.IO;
- using System.Text.RegularExpressions;
- using System.Xml;
- using System.Xml.Serialization;
- namespace ConsoleApplication10
- {
- public class doxml
- {
- public string nazwa { get; set; }
- public int wynik { get; set; }
- public doxml(string na, int wy)
- {
- nazwa = na;
- wynik = wy;
- }
- public doxml() { } // konstruktor domyslny konieczny dla serializacji
- }
- //-------------------------------------------------------------
- [XmlRoot("doxmlCollection")]
- public class doxmlContainer
- {
- [XmlArray("wyniki"), XmlArrayItem("doxml")]
- public doxml[] wyniki { get; set; }
- public doxmlContainer(doxml[] tab)
- {
- wyniki = new doxml[tab.Length];
- for (int i = 0; i < tab.Length; i++)
- {
- wyniki[i] = tab[i];
- }
- }
- public doxmlContainer() { } // konstruktor domyslny konieczny dla serializacji
- // Serializacja
- public void Save(string path)
- {
- var serializer = new XmlSerializer(typeof(doxmlContainer));
- using (var stream = new FileStream(path, FileMode.Create))
- {
- serializer.Serialize(stream, this);
- }
- }
- // Deserializacja
- public static doxmlContainer Load(string path)
- {
- var serializer = new XmlSerializer(typeof(doxmlContainer));
- using (var stream = new FileStream(path, FileMode.Open))
- {
- return serializer.Deserialize(stream) as doxmlContainer;
- }
- }
- //ladowanie xml na podstawie lancucha znakowego
- public static doxmlContainer LoadFromText(string text)
- {
- var serializer = new XmlSerializer(typeof(doxmlContainer));
- return serializer.Deserialize(new StringReader(text)) as doxmlContainer;
- }
- }
- public class highscores : IComparable<highscores>
- {
- private int liczba;
- private string danegracza;
- public int CompareTo(highscores probka)
- {
- return this.liczba.CompareTo(probka.liczba);
- }
- public highscores(int l1, string d1)
- {
- this.liczba = l1;
- this.danegracza = d1;
- }
- public override string ToString()
- {
- return liczba.ToString() + " " + danegracza;
- }
- }
- class auto
- {
- //zmienne klasy
- private int bak { get; set; } //zmienna obslugiwana przez właściwość
- static int kasa; //zmienna statyczna
- public string marka;
- public string model;
- public float predkosc;
- public float osiagi;
- public int punkty;
- public int koniecgry;
- static auto() //funkcja przypisująca zmiennej statycznej wartość
- {
- kasa = 500;
- }
- public void kasap() //funkcja przypisująca zmiennej statycznej wartość
- {
- kasa = 500;
- }
- public auto(string mar, string mod) // konstruktor
- {
- marka = mar;
- model = mod;
- }
- public auto(string mar, string mod, //konstruktor złożony
- int ofiary)
- : this(mar, mod)
- {
- punkty = ofiary;
- }
- public auto(auto poprzednieauto) //konstruktor kopiujący
- {
- marka = poprzednieauto.marka;
- model = poprzednieauto.model;
- punkty = poprzednieauto.punkty;
- }
- public static double operator +(double a, auto B)
- {
- return (a + B.wyniki());
- }
- //funkcje i metody programu
- public int wyniki()
- {
- return (punkty * kasa);
- }
- public void jedz(int selectedlang)
- {
- predkosc = predkosc + 10;
- if (predkosc > osiagi)
- {
- if (selectedlang == 1) Console.WriteLine("Więcej nie pojedzie!");
- if (selectedlang == 2) Console.WriteLine("You can't get any faster!");
- predkosc = osiagi;
- }
- if (selectedlang == 1)
- {
- Console.WriteLine("Gaz do dechy!");
- Console.WriteLine("Twoja prędkosc wynosi " + predkosc + "km/h.");
- Console.WriteLine("Stan twojego baku wynosi " + stanbaku() + ".");
- }
- if (selectedlang == 2)
- {
- Console.WriteLine("You push the pedal to the limit!");
- Console.WriteLine("Your speed equals " + predkosc + "km/h.");
- Console.WriteLine("You have " + stanbaku() + " liters of petrol left.");
- }
- }
- public void wprawo(int selectedlang)
- {
- predkosc = predkosc - (predkosc / 2);
- if (selectedlang == 1)
- {
- Console.WriteLine("Skręcasz w prawo.");
- Console.WriteLine("Twoja prędkość wynosi " + predkosc + "km/h.");
- Console.WriteLine("Stan twojego baku wynosi " + stanbaku() + ".");
- }
- if (selectedlang == 2)
- {
- Console.WriteLine("You turn right.");
- Console.WriteLine("Your speed equals " + predkosc + "km/h.");
- Console.WriteLine("You have " + stanbaku() + " liters of petrol left.");
- }
- }
- public void wlewo(int selectedlang)
- {
- predkosc = predkosc - (predkosc / 2);
- if (selectedlang == 1)
- {
- Console.WriteLine("Skręcasz w lewo.");
- Console.WriteLine("Twoja prędkość wynosi " + predkosc + "km/h.");
- Console.WriteLine("Stan twojego baku wynosi " + stanbaku() + ".");
- }
- if (selectedlang == 2)
- {
- Console.WriteLine("You turn right.");
- Console.WriteLine("Your speed equals " + predkosc + "km/h.");
- Console.WriteLine("You have " + stanbaku() + " liters of petrol left.");
- }
- }
- public int stankasy()
- {
- return kasa;
- }
- public int stanbaku()
- {
- return bak;
- }
- public void tankowanie(int litry, int selectedlang)
- {
- if (kasa >= litry * 5)
- {
- kasa = kasa - (litry * 5);
- bak = bak + litry;
- }
- else
- {
- if (selectedlang == 1) Console.WriteLine("Nie masz tyle kasy!");
- if (selectedlang == 2) Console.WriteLine("You don't have enough money!");
- }
- }
- public void stanbakup()
- {
- bak = 40;
- }
- public void spalanie()
- {
- if (predkosc > 0 && predkosc <= 30) bak = bak - 2;
- if (predkosc > 30 && predkosc <= 80) bak = bak - 4;
- if (predkosc > 80 && predkosc <= 130) bak = bak - 6;
- if (predkosc > 130 && predkosc <= 170) bak = bak - 8;
- if (predkosc > 170) bak = bak - 10;
- }
- public void sprawdzbak(int selectedlang)
- {
- if (bak <= 0)
- {
- bak = 0;
- if (selectedlang == 1) Console.WriteLine("Skończyło Ci się paliwo! KONIEC GRY!");
- if (selectedlang == 2) Console.WriteLine("You runned out of fuel! GAME OVER!");
- koniecgry = 1;
- // Environment.Exit(3);
- }
- }
- public void zarabiaj()
- {
- int los2;
- Random rnd1 = new Random();
- los2 = rnd1.Next(5 + 1);
- kasa = kasa + (int)predkosc * los2;
- }
- public void prezentuj()
- {
- Console.WriteLine("{0} {1} \t {2}", marka, model, punkty);
- }
- }
- class Program
- {
- public static void graj(int selectedlang)
- {
- List<highscores> numlist = new List<highscores>(); //deklaracja listy do wyników globalnych
- string s2 = string.Empty; //zmienna przechowujaca liste jako string
- int los; //zmienne pomocnicze
- double wynikpom = 0; //zmienna pomocnicza do sumowania wyniku lokalnego
- int licznik = 0;
- int zmcatch = 0;
- int odp = 0;
- int odp2 = 0;
- int odp3 = 0;
- int wybor = 0;
- int litry = 0;
- string dolisty = string.Empty; //dolisty = czesc stringa wczytana z pliku txt ktora dodajemy do listy jako arg 2 konstruktora
- FileStream fs12 = new FileStream(@"highscores.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite); //strumien
- StreamReader odczytwynikow = new StreamReader(fs12);
- fs12.Position = 0;
- while ((dolisty = odczytwynikow.ReadLine()) != null) //przejscie przez kazda linie pliku tekstowego
- {
- string liczbawyniku = dolisty.Substring(0, dolisty.IndexOf(" ")).Replace(" ", ""); //liczbawyniku = wyciecie z calej wczytanej linii jedynie liczby jako string
- dolisty = dolisty.Substring(dolisty.IndexOf(" ")); //wyciecie czesci wczytanej linii zaczynajac od znaku spacji
- dolisty = dolisty.Remove(0, 1); //usuniecie znaku spacji
- numlist.Add(new highscores(int.Parse(liczbawyniku), dolisty)); //wczytanie liczby jak i marki + modelu z wczytanej linii do konstruktowa listy
- }
- odczytwynikow.Close(); //zamkniecie strumienia
- auto[] domyslne = new auto[1]; //domyslna tablica wynikow lokalnych
- domyslne[0] = new auto("--", "--", 0); //wartosci domyslne tablicy lokalnej
- auto[] wyniki = new auto[10];
- for (int i = 0; i < 10; i++) wyniki[i] = new auto(domyslne[0]); //wypelnienie lokalnej tablicy wynikow tymi samymi wartosciami
- do
- {
- int fragi = 0; //zerowanie zmiennej odp za liczbe przejechanych ludzi
- grafika(); //animacja samochodziku
- ekranstart(selectedlang); //ekran startowy opis gry
- string mar, mod; //marka, model
- if (selectedlang == 1) Console.WriteLine("Podaj markę swojego samochodu:");
- if (selectedlang == 2) Console.WriteLine("What brand is your car?");
- mar = (Console.ReadLine());
- if (selectedlang == 1) Console.WriteLine("Podaj model samochodu:");
- if (selectedlang == 2) Console.WriteLine("Please provide exact car model:");
- mod = (Console.ReadLine());
- auto gracz1 = new auto(mar, mod);
- gracz1.koniecgry = 0; //ustawienie wartosci koncagry dla gracza 1 na 0, czyli false
- int licznikprob = 0;
- do
- {
- do
- {
- if (selectedlang == 1) Console.WriteLine("Podaj maksymalną prędkość tego cuda:");
- if (selectedlang == 2) Console.WriteLine("And what is the max speed of it?:");
- try
- {
- gracz1.osiagi = int.Parse(Console.ReadLine());
- zmcatch = 1;
- }
- catch
- {
- zmcatch = 0;
- if (licznikprob > 1)
- {
- if (selectedlang == 1) Console.WriteLine("No co, nie rozumiesz? LICZBĘ!");
- if (selectedlang == 2) Console.WriteLine("What the... NUMBER! What don't you understand?!");
- }
- else
- if (selectedlang == 1)
- {
- Console.WriteLine("Prędkość musisz podać jako liczbę.");
- Console.Write("Więc spytam jeszcze raz, ");
- }
- if (selectedlang == 2)
- {
- Console.WriteLine("Speed must be given as number value.");
- Console.Write("So let me ask again, ");
- }
- }
- licznikprob += 1;
- } while (zmcatch == 0);
- if (gracz1.osiagi > 250 && selectedlang == 1) Console.WriteLine("No chyba żartujesz? ");
- if (gracz1.osiagi > 250 && selectedlang == 2) Console.WriteLine("You are joking, right? ");
- } while (gracz1.osiagi > 250);
- grafika();
- if (selectedlang == 1)
- {
- Console.WriteLine("Marka: " + gracz1.marka);
- Console.WriteLine("Model: " + gracz1.model);
- Console.WriteLine("Prędkość maksymalna: " + gracz1.osiagi);
- Console.WriteLine("Czy chcesz zapisac dane o grze do pliku?");
- }
- if (selectedlang == 2)
- {
- Console.WriteLine("Brand: " + gracz1.marka);
- Console.WriteLine("Model: " + gracz1.model);
- Console.WriteLine("Max speed: " + gracz1.osiagi);
- Console.WriteLine("Do you want to export your track into txt?");
- }
- do
- {
- taknie(selectedlang);
- try
- {
- odp = int.Parse(Console.ReadLine());
- }
- catch
- {
- }
- } while (odp != 1 && odp != 2);
- if (odp == 1 && !File.Exists("zapis.txt")) //sprawdzenie czy plik zapisu trasy istnieje
- {
- File.CreateText("zapis.txt"); //utworzenie pliku
- }
- if (odp == 1)
- {
- System.IO.File.AppendAllText(@"zapis.txt", "Marka: " + gracz1.marka + Environment.NewLine); //wpisanie podstawowych wartosci danego gracza do pliku z opisem trasy
- System.IO.File.AppendAllText(@"zapis.txt", "Model: " + gracz1.model + Environment.NewLine);
- System.IO.File.AppendAllText(@"zapis.txt", "Predkosc maksymalna: " + gracz1.osiagi + Environment.NewLine);
- }
- gracz1.stanbakup(); //wyzerowanie stanu baku
- gracz1.kasap(); //wyzerowanie stanu kasy
- informacje(selectedlang); //info o sterowaniu
- // GŁÓWNA PĘTLA GRY
- do
- {
- gracz1.sprawdzbak(selectedlang); //sprawdzenie czy mozna w ogole jechac
- if (gracz1.predkosc <= 0)
- {//zmuszenie do ruszania begin
- informacje(selectedlang);
- if (selectedlang == 1) Console.WriteLine("Musisz przyśpieszyć bo stoisz w miejscu!");
- if (selectedlang == 2) Console.WriteLine("You need to push some pedal first!");
- do
- {
- do
- {
- if (selectedlang == 1) Console.WriteLine("Wybierz opcję nr.1 by ruszyć!");
- if (selectedlang == 2) Console.WriteLine("Choose option number 1 to start!");
- try
- {
- wybor = int.Parse(Console.ReadLine());
- }
- catch
- {
- }
- } while (wybor != 1);
- if (wybor == 1)
- {
- gracz1.predkosc = 0;
- gracz1.jedz(selectedlang);
- gracz1.spalanie();
- }
- } while (wybor > 1);
- }//zmuszenie do ruszania end
- Random rnd2 = new Random();
- los = rnd2.Next(5 + 1);
- if (los < 1 && gracz1.predkosc > 30)
- {
- if (selectedlang == 1) Console.WriteLine("WHOA! DZIKI PIESZY POJAWIŁ SIĘ NA DRODZE! Czy chcesz go przejechać?");
- if (selectedlang == 2) Console.WriteLine("WHOA! WILD HUMAN APPEARED! Do You want to drive through him?");
- do
- {
- taknie(selectedlang);
- try
- {
- odp2 = int.Parse(Console.ReadLine());
- }
- catch
- {
- }
- } while (odp2 != 1 && odp2 != 2);
- if (odp2 == 1)
- {
- gracz1.zarabiaj();
- if (selectedlang == 1) Console.WriteLine("Przejechałeś pieszego! Zdobywasz kasę! Masz juz " + gracz1.stankasy() + "! Co dalej?");
- if (selectedlang == 2) Console.WriteLine("You killed a pedestrian! You also grabbed his cash, now you have " + gracz1.stankasy() + "! What's next?");
- fragi = fragi + 1;
- if (odp == 1) System.IO.File.AppendAllText(@"zapis.txt", "Przejechano " + fragi + " z kolei piszego. Idzie Ci coraz lepiej!" + Environment.NewLine);
- }
- if (odp2 == 2)
- {
- if (selectedlang == 1) Console.WriteLine("Cienias! Jedziesz dalej czy się boisz?");
- if (selectedlang == 2) Console.WriteLine("Loser! Do you even continue or are you scared?");
- if (odp == 1) System.IO.File.AppendAllText(@"zapis.txt", "Ajj.. Powiedzmy że Ci uciekł.. Tym razem.." + Environment.NewLine);
- }
- }
- do
- {
- try
- {
- wybor = int.Parse(Console.ReadLine());
- }
- catch
- {
- }
- } while (wybor != 1 && wybor != 2 && wybor != 3 && wybor != 4 && wybor != 5);
- switch (wybor)
- {
- case 1: informacje(selectedlang);
- if (selectedlang == 1) Console.WriteLine("konto: " + gracz1.stankasy());
- if (selectedlang == 2) Console.WriteLine("Cash: " + gracz1.stankasy());
- gracz1.jedz(selectedlang);
- gracz1.spalanie();
- if (odp == 1)
- {
- System.IO.File.AppendAllText(@"zapis.txt", "Przyśpieszono, prędkosc wynosi: " + gracz1.predkosc + " a stan paliwa: " + gracz1.stanbaku() + Environment.NewLine);
- }
- break;
- case 2: informacje(selectedlang);
- if (selectedlang == 1) Console.WriteLine("konto: " + gracz1.stankasy());
- if (selectedlang == 2) Console.WriteLine("Cash: " + gracz1.stankasy());
- gracz1.wprawo(selectedlang);
- gracz1.spalanie();
- if (odp == 1)
- {
- System.IO.File.AppendAllText(@"zapis.txt", "Skręcono w prawo, prędkość wynosi: " + gracz1.predkosc + " a stan paliwa: " + gracz1.stanbaku() + Environment.NewLine);
- }
- break;
- case 3: informacje(selectedlang);
- if (selectedlang == 1) Console.WriteLine("konto: " + gracz1.stankasy());
- if (selectedlang == 2) Console.WriteLine("Cash: " + gracz1.stankasy());
- gracz1.wlewo(selectedlang);
- gracz1.spalanie();
- if (odp == 1)
- {
- System.IO.File.AppendAllText(@"zapis.txt", "Skręcono w lewo, prędkość wynosi: " + gracz1.predkosc + " a stan paliwa: " + gracz1.stanbaku() + Environment.NewLine);
- }
- break;
- case 4: informacje(selectedlang);
- if (selectedlang == 1)
- {
- Console.WriteLine("konto: " + gracz1.stankasy());
- Console.WriteLine("To ile tankujemy?");
- }
- if (selectedlang == 2)
- {
- Console.WriteLine("Cash: " + gracz1.stankasy());
- Console.WriteLine("So how much you want to tank?");
- }
- do
- {
- if (selectedlang == 1) Console.WriteLine("Podaj liczbę litrów.");
- if (selectedlang == 2) Console.WriteLine("Input a number of litres.");
- try
- {
- litry = int.Parse(Console.ReadLine());
- zmcatch = 1;
- }
- catch
- {
- zmcatch = 0;
- }
- } while (zmcatch == 0);
- //litry = int.Parse(Console.ReadLine());
- gracz1.tankowanie(litry, selectedlang);
- gracz1.stanbaku();
- if (selectedlang == 1) Console.WriteLine("Co dalej?");
- if (selectedlang == 2) Console.WriteLine("What's next?");
- if (odp == 1)
- {
- System.IO.File.AppendAllText(@"zapis.txt", "Zatankowano, stan paliwa wynosi: " + gracz1.stanbaku() + Environment.NewLine);
- }
- break;
- case 5:
- if (selectedlang == 1)
- {
- Console.WriteLine("Wychodzisz z samochodu");
- Console.WriteLine("Koniec gry!");
- }
- if (selectedlang == 2)
- {
- Console.WriteLine("You are leaving the car.");
- Console.WriteLine("GAME OVER!");
- }
- if (odp == 1)
- {
- System.IO.File.AppendAllText(@"zapis.txt", "Opuszczono samochod" + Environment.NewLine);
- }
- break;
- }
- } while (wybor < 5 && gracz1.koniecgry == 0);
- if (odp == 1)
- {
- System.IO.File.AppendAllText(@"zapis.txt", "Podczas calej podrozy przejechano " + fragi + " osob." + Environment.NewLine);
- }
- gracz1.punkty = fragi;
- wyniki[licznik] = new auto(gracz1.marka, gracz1.model, gracz1.wyniki());
- licznik = licznik + 1;
- if (selectedlang == 1) Console.WriteLine("TABLICA WYNIKÓW LOKALNYCH");
- if (selectedlang == 2) Console.WriteLine("LOCAL HIGHSCORES");
- foreach (auto x in wyniki)
- {
- x.prezentuj();
- }
- if (selectedlang == 1) Console.Write("Wynik Łączny: ");
- if (selectedlang == 2) Console.Write("Total score: ");
- wynikpom = wynikpom + gracz1;
- Console.WriteLine(wynikpom);
- numlist.Add(new highscores(gracz1.wyniki(), gracz1.marka + " " + gracz1.model));
- System.IO.File.AppendAllText(@"highscores.txt", (gracz1.wyniki() + " " + gracz1.marka + " " + gracz1.model) + Environment.NewLine);
- if (selectedlang == 1) Console.WriteLine("Czy chcesz grać dalej?");
- if (selectedlang == 2) Console.WriteLine("Do you want to play again?");
- do
- {
- taknie(selectedlang);
- try
- {
- odp3 = int.Parse(Console.ReadLine());
- }
- catch
- {
- }
- } while (odp3 != 1 && odp3 != 2);
- } while (odp3 == 1);
- //outro, czyszczenie konsoli + tablica wyników od najwyzszego do najnizszego.
- grafika();
- numlist.Sort();
- numlist.Reverse();
- s2 = string.Empty;
- foreach (highscores col in numlist)
- {
- s2 += col.ToString() + " " + Environment.NewLine;
- }
- System.Console.WriteLine("HIGHSCORES" + Environment.NewLine + "{0}", s2);
- if (selectedlang == 1) Console.WriteLine("Wciśnięcie dowolnego klawisza powraca do menu.");
- if (selectedlang == 2) Console.WriteLine("Press any key to return to main menu");
- Console.ReadKey();
- grafika();
- }
- public static void intro(int selectedlang)
- {
- Random ladowanie = new Random();
- int procent = 0;
- string tekstladowania = String.Empty;
- string odstepprzedprocentem = String.Empty;
- for (int i = 0; i < 51; i++)
- {
- Console.Clear();
- Console.WriteLine(@" _____ __ __ ____ ___ __ ");
- Console.WriteLine(@" / ___// /_________ ___ / /_/ __ )____ _____ ____/ (_) /_");
- Console.WriteLine(@" \__ \/ __/ ___/ _ \/ _ \/ __/ __ / __ `/ __ \/ __ / / __/");
- Console.WriteLine(@" ___/ / /_/ / / __/ __/ /_/ /_/ / /_/ / / / / /_/ / / /_ ");
- Console.WriteLine(@"/____/\__/_/ \___/\___/\__/_____/\__,_/_/ /_/\__,_/_/\__/ " + Environment.NewLine);
- int czas = ladowanie.Next(1, 50);
- tekstladowania += "▓";
- if (i > 2)
- {
- odstepprzedprocentem += " ";
- }
- Console.WriteLine(tekstladowania);
- Console.Write(odstepprzedprocentem + procent + "%" + Environment.NewLine);
- if (i < 50 && selectedlang == 1)
- {
- int wiadomosc = ladowanie.Next(1, 1000);
- if (wiadomosc < 100) Console.WriteLine("sprowadzanie samochodów z Niemiec...");
- if (wiadomosc > 100 && wiadomosc < 200) Console.WriteLine("Ustawianie pieszych...");
- if (wiadomosc > 200 && wiadomosc < 300) Console.WriteLine("Szukanie stacji radiowej Disco Polo...");
- if (wiadomosc > 300 && wiadomosc < 400) Console.WriteLine("Ustawianie wszystkich świateł na zielone...");
- if (wiadomosc > 400 && wiadomosc < 500) Console.WriteLine("Naprawa wcześniej uszkodzonych aut w garażu u Wieśka...");
- if (wiadomosc > 500 && wiadomosc < 600) Console.WriteLine("Casting statystów do roli pieszych...");
- if (wiadomosc > 600 && wiadomosc < 700) Console.WriteLine("Przekupowanie policji pączkami...");
- if (wiadomosc > 700 && wiadomosc < 800) Console.WriteLine("Tworzenie zmiennych i innych pierdół dla danych gry...");
- if (wiadomosc > 800 && wiadomosc < 900) Console.WriteLine("Ustawianie pułapek dla cykorów uciekających z samochodów...");
- if (wiadomosc > 900 && wiadomosc < 1000) Console.WriteLine("Okradanie banku by dać kasę ludziom i kierowcy...");
- }
- if (i < 50 && selectedlang == 2)
- {
- int wiadomosc = ladowanie.Next(1, 1000);
- if (wiadomosc < 100) Console.WriteLine("Getting used cars from Germany...");
- if (wiadomosc > 100 && wiadomosc < 200) Console.WriteLine("Placing pedestrians...");
- if (wiadomosc > 200 && wiadomosc < 300) Console.WriteLine("Searching for a country radiostation...");
- if (wiadomosc > 300 && wiadomosc < 400) Console.WriteLine("Setting all lights green...");
- if (wiadomosc > 400 && wiadomosc < 500) Console.WriteLine("Fixing damaged cars in suspicious garage...");
- if (wiadomosc > 500 && wiadomosc < 600) Console.WriteLine("Searching for people to play pedestrians role...");
- if (wiadomosc > 600 && wiadomosc < 700) Console.WriteLine("Bribing the police with doghnuts...");
- if (wiadomosc > 700 && wiadomosc < 800) Console.WriteLine("Creating variables and other game-data related crap...");
- if (wiadomosc > 800 && wiadomosc < 900) Console.WriteLine("Setting a traps for losers escaping from cars...");
- if (wiadomosc > 900 && wiadomosc < 1000) Console.WriteLine("Robbing a bank to get cash for pedestrians and driver...");
- }
- Thread.Sleep(czas);
- procent += 2;
- }
- if (selectedlang == 1) Console.Write("Wciśnij dowolny klawisz by kontynuować...");
- if (selectedlang == 2) Console.Write("Press any key to continue...");
- Console.ReadKey();
- }
- public static void autor()
- {
- for (int i = 0; i < 200; i++)
- {
- Random rand = new Random();
- int kolor = rand.Next(5);
- switch (kolor)
- {
- case 0: Console.ForegroundColor = ConsoleColor.Yellow; break;
- case 1: Console.ForegroundColor = ConsoleColor.Red; break;
- case 2: Console.ForegroundColor = ConsoleColor.Green; break;
- case 3: Console.ForegroundColor = ConsoleColor.Blue; break;
- case 4: Console.ForegroundColor = ConsoleColor.White; break;
- }
- Console.WriteLine("Dawid Poleszczuk");
- Console.ResetColor();
- Thread.Sleep(50);
- Console.Clear();
- }
- Console.WriteLine("Dobra, starczy tego. Wciśnij enter by kontynuować...");
- Console.ReadKey();
- Console.Clear();
- }
- public static void taknie(int selectedlang)
- {
- if (selectedlang == 1) Console.WriteLine("1=TAK/2=NIE");
- if (selectedlang == 2) Console.WriteLine("1=YES/2=NO");
- }
- public static void ekranstart(int selectedlang)
- {
- if (selectedlang == 1)
- {
- Console.WriteLine("Witaj w Symulatorze Pirata Drogowego!" + Environment.NewLine);
- Console.WriteLine("Jak grać?:");
- Console.WriteLine("Klawisze 1-5 służą do kontroli pojazdu. Enter zatwierdza wybór opcji.");
- Console.WriteLine("Jednak uważaj! Na drodze pojawiają się piesi!");
- Console.WriteLine("Za przejechanie pieszego zdobywasz pieniądze, które mozesz wydać na benzynkę." + Environment.NewLine + "(A na co innego byś chciał?).");
- Console.WriteLine("Im wyższa jest twoja prędkość, tym więcej pieniędzy wyrzucają twoje ofiary!");
- Console.WriteLine("Gra kończy się, jeśli skończy Ci się paliwo lub UCIEKNIESZ z samochodu.");
- Console.WriteLine("Oczywiście im szybciej jedziesz, tym szybciej kończy się benzyna w baku. :-)");
- Console.WriteLine("Kazdy zakręt wytrąca połowę aktualnej prędkosci samochodu." + Environment.NewLine + "Tak, masz popsute hamulce :-)");
- Console.WriteLine("Powodzenia!" + Environment.NewLine);
- Console.WriteLine("Wciśnij enter by kontynuować...");
- }
- if (selectedlang == 2)
- {
- Console.WriteLine("Welcome in street bandit simulator!" + Environment.NewLine);
- Console.WriteLine("How to play?:");
- Console.WriteLine("Use keys 1-5 to control your car.");
- Console.WriteLine("But beware! There will be pedestrians appearing on street!");
- Console.WriteLine("For driving through pedestrians you can get money, which you use to refuel." + Environment.NewLine + "(What else would you want??).");
- Console.WriteLine("The higher your speed is, the more cash your victims drops!");
- Console.WriteLine("Game ends if you run out of petrol, or if you ESCAPE from your car.");
- Console.WriteLine("The faster you drive, the faster your car runs out of petrol. :-)");
- Console.WriteLine("Every turn loses half of your current speed." + Environment.NewLine + "Yes, Your brakes are broken :-)");
- Console.WriteLine("Good Luck!" + Environment.NewLine);
- Console.WriteLine("Press the return key to continue...");
- }
- Console.ReadKey();
- Console.Clear();
- }
- public static void informacje(int selectedlang) //animacja jadącego autka
- {
- Console.Clear();
- if (selectedlang == 1) Console.WriteLine(":: (1) gaz! :: (2) w prawo! :: (3) w lewo! :: (4) tankowanko :: (5) ucieknij ::");
- if (selectedlang == 2) Console.WriteLine(":: (1) Push it! :: (2) turn right! :: (3) left! :: (4) refuel :: (5) escape ::");
- }
- public static void grafika() //animacja jadącego autka
- {
- string odstep;
- odstep = " ";
- for (int i = 0; i < 29; i++)
- {
- Console.WriteLine(odstep + @" _..-------++._");
- Console.WriteLine(odstep + @" _.-'/ | _|| \--._");
- Console.WriteLine(odstep + @" __.--'`._/_\j_____/_||___\ `----.");
- Console.WriteLine(odstep + @" _.--'_____ | \ _____ /");
- Console.WriteLine(odstep + @" _j /,---.\ | =o | /,---.\ |_");
- Console.WriteLine(odstep + @"[__]==// .-. \\==`===========/==// .-. \\=[__]");
- Console.WriteLine(odstep + @" `-._|\ `-' /|___\_________/___|\ `-' /|_.'");
- Console.WriteLine(odstep + @" `---' `---'");
- odstep = odstep.Remove(1, 1);
- Thread.Sleep(10);
- Console.Clear();
- }
- }
- public static void serializacja()
- {
- int licznik = 0;
- foreach (string line in File.ReadLines(@"highscores.txt"))
- {
- if (line != String.Empty) ++licznik;
- } //zliczanie liczby linii w pliku highscores
- string path = @"wyniki.xml";
- string dolisty = string.Empty;
- FileStream fs12 = new FileStream(@"highscores.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite); //strumien
- StreamReader odczytwynikow = new StreamReader(fs12);
- fs12.Position = 0;
- doxml[] tab = new doxml[licznik];
- int licznik2 = 0;
- while ((dolisty = odczytwynikow.ReadLine()) != null) //przejscie przez kazda linie pliku tekstowego
- {
- string liczbawyniku = dolisty.Substring(0, dolisty.IndexOf(" ")).Replace(" ", ""); //liczbawyniku = wyciecie z calej wczytanej linii jedynie liczby jako string
- dolisty = dolisty.Substring(dolisty.IndexOf(" ")); //wyciecie czesci wczytanej linii zaczynajac od znaku spacji
- dolisty = dolisty.Remove(0, 1); //usuniecie znaku spacji
- tab[licznik2] = new doxml(dolisty, int.Parse(liczbawyniku));
- licznik2++;
- }
- doxmlContainer obj = new doxmlContainer(tab);
- obj.Save(path);
- odczytwynikow.Close(); //zamkniecie strumienia
- Console.WriteLine("Serializacja wyników przeprowadzona pomyślnie.");
- Console.WriteLine("Test deserializacji: ");
- //test deserializacji
- var doxmlCollection1 = doxmlContainer.Load(path);
- foreach (var element in doxmlCollection1.wyniki)
- {
- Console.WriteLine("{0} {1}", element.nazwa, element.wynik);
- }
- Console.ReadKey();
- }
- static void Main(string[] args)
- {
- Console.BackgroundColor = ConsoleColor.Blue;
- Console.ForegroundColor = ConsoleColor.White;
- int menuster = 0;
- int wyborjezyka = 0;
- grafika();
- poczatek:
- Console.Clear();
- do //petla do wyboru opcji jezyka, zapobiega wpisaniu innej opcji niz te dostepne.
- {
- Console.Clear();
- Console.WriteLine("Choose language.");
- Console.WriteLine("1. Polski"); Console.WriteLine("2. English");
- try
- {
- wyborjezyka = int.Parse(Console.ReadLine());
- }
- catch
- {
- }
- } while (wyborjezyka != 1 && wyborjezyka != 2);
- Console.Clear();
- do //petla do wyboru opcji z menu, zapobiega wpisaniu innej opcji niz te dostepne.
- {
- Console.Clear();
- switch (wyborjezyka)
- {
- case 1:
- Console.WriteLine("MENU"); Console.WriteLine("1. Graj"); Console.WriteLine("2. Autor"); Console.WriteLine("3. Wyjscie"); Console.WriteLine("4. Serializacja danych");
- break;
- case 2:
- Console.WriteLine("MENU"); Console.WriteLine("1. New game"); Console.WriteLine("2. Author"); Console.WriteLine("3. Exit"); Console.WriteLine("4. Data serialisation");
- break;
- //case 3: - latwe dodanie menu w nast jezyku
- }
- try
- {
- menuster = int.Parse(Console.ReadLine());
- }
- catch
- {
- }
- } while (menuster != 1 && menuster != 2 && menuster != 3 && menuster != 4);
- switch (menuster)
- {
- case 1:
- grafika();
- intro(wyborjezyka);
- graj(wyborjezyka);
- goto poczatek;
- break;
- case 2:
- autor();
- goto poczatek;
- break;
- case 3:
- grafika();
- Environment.Exit(0);
- break;
- case 4:
- serializacja();
- break;
- default:
- goto poczatek;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement