Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cstdlib>
- #include <time.h>
- #include <stdio.h>
- #include <windows.h>
- #include <time.h>
- #include <conio.h>
- using namespace std;
- int liczba, strzal, ile_prob=0;
- int monety, XP, poziom=1;
- int wybor, wybor_sklep;
- int podpowiedz;
- bool ulepszenie[3];
- string linia;
- int nr_linii=1;
- void zapisz()
- {
- fstream plik;
- plik.open("save.txt",ios::out);
- plik<<monety<<endl;
- plik<<XP<<endl;
- plik<<poziom<<endl;
- plik<<ulepszenie[1]<<endl;
- plik<<ulepszenie[2]<<endl;
- plik<<ulepszenie[3]<<endl;
- plik.close();
- }
- void wczytaj()
- {
- fstream plik;
- plik.open("save.txt", ios::in);
- if(plik.good()==false) cout<<"Nie mozna otworzyc pliku!";
- while (getline(plik, linia))
- {
- switch (nr_linii)
- {
- case 1:
- monety=atoi(linia.c_str());
- break;
- case 2:
- XP=atoi(linia.c_str());
- break;
- case 3:
- poziom=atoi(linia.c_str());
- break;
- case 4:
- ulepszenie[1]=atoi(linia.c_str());
- break;
- case 5:
- ulepszenie[2]=atoi(linia.c_str());
- break;
- case 6:
- ulepszenie[3]=atoi(linia.c_str());
- break;
- }
- nr_linii++;
- }
- plik.close();
- }
- int main()
- {
- HANDLE hOut;
- hOut = GetStdHandle( STD_OUTPUT_HANDLE );
- while(true)
- {
- if(XP>=1000)
- {
- system("cls");
- poziom++;
- SetConsoleTextAttribute( hOut, 0x0030 );
- cout<<"BRAWO! Zdobywasz "<<poziom<<" poziom"<<endl;
- cout<<"Dostajesz +150 monet!"<<endl;
- monety = monety + 150;
- XP = XP - 1000;
- Sleep(1500);
- }
- wczytaj();
- SetConsoleTextAttribute( hOut, 0x0003 );
- cout<<"----Menu----"<<endl;
- SetConsoleTextAttribute( hOut, 0x0009 );
- cout<<"1.Graj"<<endl;
- cout<<"2.Wyzwania"<<endl;
- cout<<"3.Sklep"<<endl;
- cout<<"4.Wyjdz z gry"<<endl;
- SetConsoleTextAttribute( hOut, 0x0006 );
- cout<<"-------"<<endl;
- SetConsoleTextAttribute( hOut, 0x0004 );
- cout<<"Monety: "<<monety<<endl;
- cout<<"XP: "<<XP<<endl;
- cout<<"Poziom: "<<poziom<<endl;
- SetConsoleTextAttribute( hOut, 0x0006 );
- cout<<"-------"<<endl;
- SetConsoleTextAttribute( hOut, 0x0002 );
- cout << "Ulepszenie 1: " <<boolalpha << ulepszenie[1] << endl;
- cout << "Ulepszenie 2: " <<boolalpha << ulepszenie[2] << endl;
- cout << "Ulepszenie 3: " <<boolalpha << ulepszenie[3] << endl;
- SetConsoleTextAttribute( hOut, 0x0006 );
- cout<<"Twoj wybor: ";
- cin>>wybor;
- zapisz();
- switch(wybor)
- {
- //kody
- case 12321:
- monety = monety + 50000;
- XP = XP + 999;
- zapisz();
- system("cls");
- break;
- case 32123:
- monety=0;
- XP=0;
- poziom=1;
- ulepszenie[1]=false;
- ulepszenie[2]=false;
- ulepszenie[3]=false;
- zapisz();
- system("cls");
- break;
- case 4:
- zapisz();
- cout<<"Zapisywanie..."<<endl;
- Sleep(700);
- cout<<"Zapisywanie.."<<endl;
- Sleep(600);
- cout<<"Zapisywanie."<<endl;
- exit(0);
- break;
- case 1:
- system("cls");
- SetConsoleTextAttribute( hOut, 0x0003 );
- cout<<"Witaj! Pomyslalem sobie liczbe 1..100"<<endl;
- srand(time(NULL));
- liczba = rand()%100+1;
- ile_prob=0;
- while(strzal!=liczba)
- {
- ile_prob++;
- SetConsoleTextAttribute( hOut, 0x0001 );
- cout<<"Zgadnij jaka (to Twoja "<<ile_prob<<" proba): ";
- cout<<liczba<<endl;
- cin>>strzal;
- SetConsoleTextAttribute( hOut, 0x0044 );
- if(strzal>99)
- cout<<"Liczba to max 100!"<<endl;
- if(strzal==liczba)
- {
- SetConsoleTextAttribute( hOut, 0x0003 );
- cout<<"Udalo sie! Wygrywasz w "<<ile_prob<<" probie"<<endl;
- cout<<"+15 monet!"<<endl;
- cout<<"+300 XP!"<<endl;
- if(ile_prob==1)
- {
- SetConsoleTextAttribute( hOut, 0x0001 );
- cout<<"Brawo! Wygrales w pierwszej probie! Zdobywasz 30 dodatkowych monet"<<endl;
- monety = monety + 30;
- }
- if(ile_prob<5 && ile_prob>1)
- {
- SetConsoleTextAttribute( hOut, 0x0002 );
- cout<<"Wygrales w mniej niz 5 probach! Zdobywasz 20 dodatkowych monet" << endl;
- monety = monety + 20;
- }
- if(ile_prob<7 && ile_prob>5)
- {
- SetConsoleTextAttribute( hOut, 0x0004 );
- cout<<"Wygrales w mniej niz 7 probach! Zdobywasz 10 dodatkowych monet" << endl;
- monety = monety + 10;
- }
- if(ulepszenie[1]==true)
- {
- SetConsoleTextAttribute( hOut, 0x0006 );
- cout<<"Masz kupione ulepszenie! Dostajesz 300 XP wiecej"<<endl;
- XP = XP + 300;
- }
- if(ulepszenie[2]==true)
- {
- SetConsoleTextAttribute( hOut, 0x0006 );
- cout<<"Masz kupione ulepszenie! Dostajesz 15 monet wiecej"<<endl;
- XP = XP + 300;
- }
- monety = monety + 15;
- XP = XP + 300;
- SetConsoleTextAttribute( hOut, 0x0005 );
- zapisz();
- cout<<"Kliknij dowolny klawisz i poczekaj 3 sekundy";
- Sleep(3000);
- system("cls");
- }
- if(strzal<liczba)
- {
- SetConsoleTextAttribute( hOut, 0x0006 );
- if(ulepszenie[3]==true)
- {
- if(strzal<liczba)
- {
- podpowiedz = liczba - strzal;
- if(podpowiedz<=25)
- cout<<"Liczba jest o "<< podpowiedz << " wieksza!"<<endl;
- }
- }
- SetConsoleTextAttribute( hOut, 0x0004 );
- cout<<"To za malo"<<endl;
- }
- if(strzal>liczba)
- {
- SetConsoleTextAttribute( hOut, 0x0006 );
- if(ulepszenie[3]==true)
- {
- if(strzal>liczba)
- {
- podpowiedz = strzal - liczba;
- if(podpowiedz<=25)
- cout<<"Liczba jest o "<< podpowiedz << " mniejsza!"<<endl;
- }
- }
- SetConsoleTextAttribute( hOut, 0x0002 );
- cout<<"To za duzo"<<endl;
- }
- }
- getchar();
- getchar(); //dla pewnosci 2 razy
- break;
- case 3:
- SetConsoleTextAttribute( hOut, 0x0004 );
- cout<<"Ulepszenia zapisuj¹ siê! Ulepszenia nie dzia³aj¹ w trybie challange" << endl;
- SetConsoleTextAttribute( hOut, 0x0003 );
- cout<<"1.Dodatkowy exp! 120$"<<endl;
- cout<<"2.Dodatkowe monety! 150$"<<endl;
- cout<<"3.Podpowiedz z dokladnoscia do 25! 250$"<<endl;
- cin>>wybor_sklep;
- switch(wybor_sklep)
- {
- case 1:
- if(monety>=120)
- {
- ulepszenie[1]=true;
- monety = monety - 120;
- SetConsoleTextAttribute( hOut, 0x0002 );
- cout << "Ulepszenie kupione!" <<endl;
- zapisz();
- }
- SetConsoleTextAttribute( hOut, 0x0004 );
- if(monety<120)
- cout<<"Nie stac Cie!" <<endl;
- Sleep(1000);
- system("cls");
- break;
- case 3:
- if(monety>=250)
- {
- ulepszenie[3]=true;
- SetConsoleTextAttribute( hOut, 0x0002 );
- monety = monety - 250;
- cout << "Ulepszenie kupione!" <<endl;
- zapisz();
- }
- SetConsoleTextAttribute( hOut, 0x0004 );
- if(monety<250)
- cout<<"Nie stac Cie!" <<endl;
- Sleep(1000);
- system("cls");
- break;
- case 2:
- if(monety>=150)
- {
- ulepszenie[2]=true;
- monety = monety - 150;
- SetConsoleTextAttribute( hOut, 0x0002 );
- cout << "Ulepszenie kupione!" <<endl;
- zapisz();
- }
- SetConsoleTextAttribute( hOut, 0x0002 );
- if(monety<150)
- cout<<"Nie stac Cie!" <<endl;
- Sleep(1000);
- system("cls");
- break;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement