Advertisement
Guest User

Untitled

a guest
Nov 24th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <windows.h>
  4. #include <cstdlib>
  5. #include <time.h>
  6.  
  7. using namespace std;
  8.  
  9. int clr=7,v2,bal=250,bal2;
  10. int game2=false;
  11. int x=0,y=0;
  12.  
  13. char keygame,keyclr,keymenu,keyshop,keyagree,game2key;
  14.  
  15. char cuv[]="Hello";
  16. char bet;
  17.  
  18. void setcolor (unsigned short color)
  19. {
  20. HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
  21. SetConsoleTextAttribute(hcon,color);
  22. }
  23.  
  24. void color ()
  25. {
  26. setcolor(clr);
  27. }
  28.  
  29. void menu ()
  30. {
  31. system("cls");
  32. setcolor(14); cout<<"1."; color(); cout<<" Start a new game"<<endl;
  33. setcolor(14); cout<<"2."; color(); cout<<" Settings"<<endl;
  34. setcolor(14); cout<<"3."; color(); cout<<" Shop"<<endl<<endl;
  35. if(game2==false)
  36. {
  37. setcolor(14); cout<<"4."; setcolor(8); cout<<" Mini-game #2 (locked)"<<endl<<endl;
  38. }
  39. color();
  40. if(game2==true)
  41. {
  42. setcolor(14); cout<<"4."; color(); cout<<" Mini-game #2"<<endl<<endl;
  43. }
  44. setcolor(14); cout<<"9."; color(); cout<<" Quit game"<<endl<<endl;
  45. setcolor(13);
  46. cout<<"Balance: ";
  47. color();
  48. cout<<bal<<endl<<endl;
  49. keymenu=getch();
  50. }
  51.  
  52. void settings ()
  53. {
  54. cout<<"Press 1 for red color."<<endl;
  55. cout<<"Press 2 for green color."<<endl;
  56. cout<<"Press 3 for blue color."<<endl;
  57. cout<<"Press 4 for yellow color."<<endl;
  58. cout<<"Press 5 for light blue color."<<endl;
  59. cout<<"Press 6 for pink color."<<endl;
  60. cout<<"Press 7 for grey color."<<endl;
  61. cout<<"Press 8 for white color."<<endl<<endl;
  62. cout<<"M = Main Menu"<<endl<<endl;
  63. keyclr=getch();
  64. if(keyclr=='1')
  65. {
  66. clr=12;
  67. }
  68. if(keyclr=='2')
  69. {
  70. clr=10;
  71. }
  72. if(keyclr=='3')
  73. {
  74. clr=9;
  75. }
  76. if(keyclr=='4')
  77. {
  78. clr=14;
  79. }
  80. if(keyclr=='5')
  81. clr=3;
  82. if(keyclr=='6')
  83. clr=13;
  84. if(keyclr=='7')
  85. clr=8;
  86. if(keyclr=='8')
  87. clr=7;
  88. if(keyclr=='m')
  89. {
  90. system("cls");
  91. menu();
  92. }
  93. }
  94.  
  95. void spaces (int x)
  96. {
  97. for(int j=0;j<x;j++)
  98. cout<<" ";
  99. }
  100.  
  101. void lines (int y)
  102. {
  103. for(int j=0;j<y;j++)
  104. cout<<endl;
  105. }
  106.  
  107. void word ()
  108. {
  109. cout<<cuv;
  110. }
  111.  
  112. int main()
  113. {
  114. color();
  115. menu();
  116. while(true and keymenu!=9)
  117. {
  118. color();
  119. if(keymenu!='9' and keymenu!='1' and keymenu!='2' and keymenu!='3' and keymenu!='m' and keymenu!='4')
  120. {
  121. menu();
  122. }
  123. if(keymenu=='1') // GAME
  124. {
  125. system("cls");
  126.  
  127. if(bal==0)
  128. {
  129. cout<<"You have 0 credits. Press any key to receive 100 credits. . .";
  130. keygame=getch();
  131. bal=100;
  132. }
  133. system("cls");
  134.  
  135. setcolor(11);
  136. cout<<"** DOUBLE GAME **"<<endl<<endl;
  137. setcolor(12);
  138. cout<<"Red";
  139. color();
  140. cout<<" is between 1-7 and multiplies your balance by 2."<<endl;
  141. setcolor(15);
  142. cout<<"White";
  143. color();
  144. cout<<" is between 8-14 and multiplies your balance by 2."<<endl;
  145. setcolor(10);
  146. cout<<"Green";
  147. color();
  148. cout<<" is 0 and multiplies your balance by 14."<<endl<<endl;
  149. system("pause");
  150.  
  151. do
  152. {
  153. srand(time(NULL));
  154. v2=rand()%15;
  155. system("cls");
  156. cout<<"You have "<<bal<<" credit(s)."<<endl<<endl;
  157. cout<<"Place a bet: ";
  158. cin>>bal2;
  159. if(bal2<1 or bal2>bal)
  160. {
  161. do
  162. {
  163. system("cls");
  164. cout<<"Insufficient credits. Try again: ";
  165. cin>>bal2;
  166. }
  167. while(bal2<1 or bal2>bal);
  168. }
  169. system("cls");
  170. cout<<"You have bet "<<bal2<<" credit(s)."<<endl<<endl;
  171. cout<<"Press any key if you want to proceed."<<endl;
  172. cout<<"Press 2 if you want to modify your bet."<<endl<<endl;
  173. keygame=getch();
  174. if(keygame=='2')
  175. {
  176. system("cls");
  177. cout<<"You have "<<bal<<" credit(s)."<<endl<<endl;
  178. cout<<"Place a bet: ";
  179. cin>>bal2;
  180. }
  181. system("cls");
  182.  
  183. cout<<"Choose a color (r = ";
  184. setcolor(12);
  185. cout<<"red";
  186. color();
  187. cout<<" , w = ";
  188. setcolor(15);
  189. cout<<"white";
  190. color();
  191. cout<<" , g = ";
  192. setcolor(10);
  193. cout<<"green";
  194. color();
  195. cout<<"): ";
  196. cin>>bet;
  197. cout<<endl;
  198. if(bet!='r' and bet!='w' and bet!='g')
  199. {
  200. do
  201. {
  202. system("cls");
  203. cout<<"Undefined bet. Try again: ";
  204. cin>>bet;
  205. cout<<endl;
  206. }
  207. while(bet!='r' and bet!='w' and bet!='g');
  208. }
  209. if(bet=='r')
  210. {
  211. if(v2>=1 and v2<=7)
  212. {
  213. cout<<"Congratulations! System rolled color ";
  214. setcolor(12);
  215. cout<<"red";
  216. color();
  217. cout<<" with number ";
  218. setcolor(12);
  219. cout<<v2;
  220. color();
  221. cout<<endl;
  222. bal+=bal2;
  223. }
  224. if(v2==0)
  225. {
  226. cout<<"Bad luck! System rolled color ";
  227. setcolor(10);
  228. cout<<"green";
  229. color();
  230. cout<<" with number ";
  231. setcolor(10);
  232. cout<<v2<<endl;
  233. color();
  234. bal-=bal2;
  235. }
  236. if(v2>=8 and v2<=14)
  237. {
  238. cout<<"Bad luck! System rolled color ";
  239. setcolor(15);
  240. cout<<"white";
  241. color();
  242. cout<<" with number ";
  243. setcolor(15);
  244. cout<<v2<<endl;
  245. color();
  246. bal-=bal2;
  247. }
  248. }
  249.  
  250. if(bet=='g')
  251. {
  252. if(v2>=1 and v2<=7)
  253. {
  254. cout<<"Bad luck! System rolled color ";
  255. setcolor(12);
  256. cout<<"red";
  257. color();
  258. cout<<" with number ";
  259. setcolor(12);
  260. cout<<v2<<endl;
  261. color();
  262. bal-=bal2;
  263. }
  264. if(v2==0)
  265. {
  266. cout<<"Congratulations! System rolled color ";
  267. setcolor(10);
  268. cout<<"green";
  269. color();
  270. cout<<" with number ";
  271. setcolor(10);
  272. cout<<v2<<endl;
  273. color();
  274. bal+=bal2*14;
  275. }
  276. if(v2>=8 and v2<=14)
  277. {
  278. cout<<"Bad luck!! System rolled color ";
  279. setcolor(15);
  280. cout<<"white";
  281. color();
  282. cout<<" with number ";
  283. setcolor(15);
  284. cout<<v2<<endl;
  285. color();
  286. bal-=bal2;
  287. }
  288. }
  289.  
  290. if(bet=='w')
  291. {
  292. if(v2>=1 and v2<=7)
  293. {
  294. cout<<"Bad luck! System rolled color ";
  295. setcolor(12);
  296. cout<<"red";
  297. color();
  298. cout<<" with number ";
  299. setcolor(12);
  300. cout<<v2<<endl;
  301. color();
  302. bal-=bal2;
  303. }
  304. if(v2==0)
  305. {
  306. cout<<"Bad luck! System rolled color ";
  307. setcolor(10);
  308. cout<<"green";
  309. color();
  310. cout<<" with number ";
  311. setcolor(10);
  312. cout<<v2<<endl;
  313. color();
  314. bal-=bal2*14;
  315. }
  316. if(v2>=8 and v2<=14)
  317. {
  318. cout<<"Congratulations! System rolled color ";
  319. setcolor(15);
  320. cout<<"white";
  321. color();
  322. cout<<" with number ";
  323. setcolor(15);
  324. cout<<v2<<endl;
  325. color();
  326. bal+=bal2;
  327. }
  328. }
  329. Sleep(1300);
  330. system("cls");
  331. if(bal==0)
  332. {
  333. system("cls");
  334. cout<<"You lost all your credits.";
  335. Sleep(1300);
  336. menu();
  337. }
  338. else
  339. {
  340. cout<<"Press any key to continue"<<endl<<"Press m to get to the main menu"<<endl<<endl;
  341. keygame=getch();
  342.  
  343. if(keygame=='m')
  344. {
  345. system("cls");
  346. menu();
  347. }
  348. }
  349.  
  350.  
  351. }
  352. while(bal and keygame!='m');
  353. }
  354.  
  355.  
  356.  
  357.  
  358. else if(keymenu=='2') // SETTINGS
  359. {
  360. system("cls");
  361. settings();
  362. }
  363. else if(keymenu=='3') // SHOP
  364. {
  365. system("cls");
  366. cout<<"Welcome to the shop!"<<endl<<endl;
  367. cout<<"1. Mini-game #2 - 250 credits";
  368. keyshop=getch();
  369. if(keyshop!='1')
  370. {
  371. cout<<endl<<endl;
  372. cout<<"Invalid value. Try again: ";
  373. do
  374. {
  375. keyshop=getch();
  376. }while(keyshop!='1');
  377. }
  378. if(keyshop!='1' and keyshop!='m')
  379. {
  380. do
  381. {
  382. system("cls");
  383. cout<<"Invalid key. Try again: ";
  384. }while(keyshop!='1' and keyshop!='m');
  385. }
  386. if(keyshop=='1')
  387. {
  388. if(bal<250)
  389. {
  390. system("cls");
  391. cout<<"Insufficient credits. Press any key to get to the main menu. . .";
  392. keygame=getch();
  393. menu();
  394. }
  395. else
  396. {
  397. system("cls");
  398. cout<<"You currently have "; setcolor(12); cout<<bal; color(); cout<<" credits. Do you want to spend "; setcolor(12); cout<<"250"; color(); cout<<" credits on Mini-game #2? (y/n)";
  399. keyagree=getch();
  400. if(keyagree='y')
  401. {
  402. system("cls");
  403. game2=true;
  404. cout<<"Item purchased.";
  405. bal-=250;
  406. Sleep(1300);
  407. menu();
  408. }
  409.  
  410. }
  411. }
  412. if(keyshop=='m')
  413. menu();
  414. }
  415. else if(keymenu=='4') // MINI-GAME #2
  416. {
  417. x=0;
  418. y=0;
  419. if(game2==false)
  420. {
  421. system("cls");
  422. cout<<"You must buy this item from the shop!";
  423. Sleep(1300);
  424. menu();
  425. }
  426. if(game2==true)
  427. {
  428. system("cls");
  429. cout<<"Controls: W A S D and M";
  430. while(true and game2key!='m')
  431. {
  432. game2key=getch();
  433. if(game2key==97)
  434. x--;
  435. if(game2key==100)
  436. x++;
  437. if(game2key==115)
  438. y++;
  439. if(game2key==119)
  440. y--;
  441. system("cls");
  442. lines(y);
  443. spaces(x);
  444. word();
  445. if(game2key=='m')
  446. menu();
  447. }
  448. }
  449. }
  450. else if(keymenu=='9') // QUIT
  451. {
  452. system("cls");
  453. cout<<"Are you sure? (y/n) ";
  454. keyagree=getch();
  455. if(keyagree=='y')
  456. break;
  457. else
  458. menu();
  459. }
  460.  
  461. else if(keymenu=='m') // MENIU
  462. {
  463. system("cls");
  464. menu();
  465. }
  466. system("cls");
  467.  
  468. }
  469.  
  470. return 0;
  471. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement