Advertisement
Guest User

Untitled

a guest
Feb 14th, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstdlib>
  4. #include <string>
  5. #include<ctime>
  6. #include<vector>
  7. #include<conio.h>
  8. #include<algorithm>
  9.  
  10. using namespace std;
  11.  
  12. class Baza
  13. {
  14. public:
  15. int balance;
  16. vector<int>tab;
  17. int stake, type;
  18. void H_L();
  19. void ONE_SIX();
  20. string nick;
  21. void save(ofstream &file, string);
  22. void scores();
  23. };
  24.  
  25. void Baza::H_L()
  26. {
  27. cout<<"You chose high/low game"<<endl;
  28. cout<<"____________________________________________"<<endl;
  29. cout<<"What's your bet"<<endl;
  30. do
  31. {
  32. cin>>stake;
  33. if(stake>balance)
  34. cout<<"Not enough of money"<<endl;
  35. }
  36. while(stake>balance);
  37.  
  38. balance-=stake;
  39. cout<<"Press 1 if you want low or 2 if you want high"<<endl;
  40. do{
  41. cin>>type;
  42. if(type<1 || type>2)
  43. cout<<"Wrong value! Type 1 or 2"<<endl;
  44. }while(type<1 || type>2);
  45. int lossed = rand()%6+1;
  46. cout<<"Lossed number is: "<<lossed<<endl;
  47. if(type == 1)
  48. {
  49. if(lossed==1 || lossed==2 || lossed==3 )
  50. {
  51. cout<<"You won "<<stake*2<<"$!"<<endl;
  52. balance+=stake*2;
  53. }
  54. else
  55. cout<<"You lost :("<<endl;
  56. }
  57. else if(type == 2)
  58. {
  59. if(lossed==4 || lossed==5 || lossed==6 )
  60. {
  61. cout<<"You won "<<stake*2<<"$!"<<endl;
  62. balance+=stake*2;
  63. }
  64. else
  65. cout<<"You lost :("<<endl;
  66. }
  67.  
  68. }
  69.  
  70. void Baza::ONE_SIX()
  71. {
  72. cout<<"You chose ONE_SIX game"<<endl;
  73. cout<<"____________________________________________"<<endl;
  74. cout<<"What's your bet"<<endl;
  75. cin>>stake;
  76. if(stake>balance)
  77. cout<<"Not enough of money"<<endl;
  78. else{
  79. balance-=stake;
  80. cout<<"Choose a number between 1 and 6"<<endl;
  81. cin>>type;
  82. int lossed = rand()%6+1;
  83. cout<<"Lossed number is: "<<lossed<<endl;
  84. if(type == lossed)
  85. {
  86. cout<<"You won "<<stake*6<<"$!"<<endl;
  87. balance+=stake*6;
  88. }
  89. else
  90. cout<<"You lost :("<<endl;
  91. }
  92. cout<<"Current balance: "<<balance<<endl;
  93. }
  94.  
  95. void Baza::save(ofstream &file, string nick)
  96. {
  97. time_t now = time(0);
  98. char* dt = ctime(&now);
  99. char choice;
  100. cout<<"If you want to save your score, press Y"<<endl;
  101. cin>>choice;
  102. if(choice == 'Y' || choice == 'y')
  103. tab.push_back(balance);
  104. file<<tab[0]<<"$"<<"\t"<<nick<<"\t"<<dt;
  105. }
  106.  
  107. void Baza::scores()
  108. {
  109. ifstream file("scores.txt");
  110. string linia;
  111. cout<<"HIGHSCORES:"<<endl;
  112. while(!file.eof())
  113. {
  114. getline(file, linia);
  115. cout<<linia<<endl;
  116. }
  117. }
  118.  
  119. int main()
  120. {
  121. ofstream file;
  122. file.open("scores.txt", ios::app);
  123. srand(time(NULL));
  124. Baza p;
  125. p.balance = 1000;
  126. char game;
  127. cout<<"Enter your name"<<endl;
  128. cin>>p.nick;
  129. cout<<"Welcome to the casino "<<p.nick<<"! Every player has 1000$ at start. Try your luck! "<<endl;
  130. do
  131. {
  132. int option;
  133. cout<<"MENU: \n1) High/low \n2) One_six \n3) Highscores"<<endl;
  134. cout<<"BALANCE: "<<p.balance<<endl;
  135. cout<<"____________________________________________"<<endl;
  136. cout<<"Choose the option"<<endl;
  137. do
  138. {
  139. cin>>option;
  140. if(option<1 || option>3)
  141. cout<<"You chose option that does not exist. Look at the menu and try again"<<endl;
  142. }while(option<1 || option>3);
  143. switch(option)
  144. {
  145. case 1:
  146. p.H_L();
  147. break;
  148. case 2:
  149. p.ONE_SIX();
  150. break;
  151. case 3:
  152. system("cls");
  153. p.scores();
  154. break;
  155. }
  156. cout<<"If you want to play press Y, else press N"<<endl;
  157. cin>>game;
  158. system("cls");
  159. if(p.balance<1)
  160. {
  161. cout<<"You don't have enough of money to play"<<endl;
  162. getch();
  163. return 0;
  164. }
  165. }while(game=='y' || game=='Y');
  166. p.save(file, p.nick);
  167. file.close();
  168. return 0;
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement