Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cstdlib>
- #include <string>
- #include<ctime>
- #include<vector>
- #include<conio.h>
- #include<algorithm>
- using namespace std;
- class Baza
- {
- public:
- int balance;
- vector<int>tab;
- int stake, type;
- void H_L();
- void ONE_SIX();
- string nick;
- void save(ofstream &file, string);
- void scores();
- };
- void Baza::H_L()
- {
- cout<<"You chose high/low game"<<endl;
- cout<<"____________________________________________"<<endl;
- cout<<"What's your bet"<<endl;
- do
- {
- cin>>stake;
- if(stake>balance)
- cout<<"Not enough of money"<<endl;
- }
- while(stake>balance);
- balance-=stake;
- cout<<"Press 1 if you want low or 2 if you want high"<<endl;
- do{
- cin>>type;
- if(type<1 || type>2)
- cout<<"Wrong value! Type 1 or 2"<<endl;
- }while(type<1 || type>2);
- int lossed = rand()%6+1;
- cout<<"Lossed number is: "<<lossed<<endl;
- if(type == 1)
- {
- if(lossed==1 || lossed==2 || lossed==3 )
- {
- cout<<"You won "<<stake*2<<"$!"<<endl;
- balance+=stake*2;
- }
- else
- cout<<"You lost :("<<endl;
- }
- else if(type == 2)
- {
- if(lossed==4 || lossed==5 || lossed==6 )
- {
- cout<<"You won "<<stake*2<<"$!"<<endl;
- balance+=stake*2;
- }
- else
- cout<<"You lost :("<<endl;
- }
- }
- void Baza::ONE_SIX()
- {
- cout<<"You chose ONE_SIX game"<<endl;
- cout<<"____________________________________________"<<endl;
- cout<<"What's your bet"<<endl;
- cin>>stake;
- if(stake>balance)
- cout<<"Not enough of money"<<endl;
- else{
- balance-=stake;
- cout<<"Choose a number between 1 and 6"<<endl;
- cin>>type;
- int lossed = rand()%6+1;
- cout<<"Lossed number is: "<<lossed<<endl;
- if(type == lossed)
- {
- cout<<"You won "<<stake*6<<"$!"<<endl;
- balance+=stake*6;
- }
- else
- cout<<"You lost :("<<endl;
- }
- cout<<"Current balance: "<<balance<<endl;
- }
- void Baza::save(ofstream &file, string nick)
- {
- time_t now = time(0);
- char* dt = ctime(&now);
- char choice;
- cout<<"If you want to save your score, press Y"<<endl;
- cin>>choice;
- if(choice == 'Y' || choice == 'y')
- tab.push_back(balance);
- file<<tab[0]<<"$"<<"\t"<<nick<<"\t"<<dt;
- }
- void Baza::scores()
- {
- ifstream file("scores.txt");
- string linia;
- cout<<"HIGHSCORES:"<<endl;
- while(!file.eof())
- {
- getline(file, linia);
- cout<<linia<<endl;
- }
- }
- int main()
- {
- ofstream file;
- file.open("scores.txt", ios::app);
- srand(time(NULL));
- Baza p;
- p.balance = 1000;
- char game;
- cout<<"Enter your name"<<endl;
- cin>>p.nick;
- cout<<"Welcome to the casino "<<p.nick<<"! Every player has 1000$ at start. Try your luck! "<<endl;
- do
- {
- int option;
- cout<<"MENU: \n1) High/low \n2) One_six \n3) Highscores"<<endl;
- cout<<"BALANCE: "<<p.balance<<endl;
- cout<<"____________________________________________"<<endl;
- cout<<"Choose the option"<<endl;
- do
- {
- cin>>option;
- if(option<1 || option>3)
- cout<<"You chose option that does not exist. Look at the menu and try again"<<endl;
- }while(option<1 || option>3);
- switch(option)
- {
- case 1:
- p.H_L();
- break;
- case 2:
- p.ONE_SIX();
- break;
- case 3:
- system("cls");
- p.scores();
- break;
- }
- cout<<"If you want to play press Y, else press N"<<endl;
- cin>>game;
- system("cls");
- if(p.balance<1)
- {
- cout<<"You don't have enough of money to play"<<endl;
- getch();
- return 0;
- }
- }while(game=='y' || game=='Y');
- p.save(file, p.nick);
- file.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement