Guest User

Untitled

a guest
Oct 16th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.86 KB | None | 0 0
  1. main.cpp
  2. #include "Game_Design.h"
  3. #include <ctime>
  4.  
  5. int main()
  6. {
  7. srand(time(NULL));
  8. Game_design game;
  9. game.addplayer();
  10. game.Gameplay();
  11. system("pause");
  12. return 0;
  13. }
  14.  
  15. Game_Desing.h
  16. #pragma once
  17. #include "Player.h"
  18. #include <ctime>
  19. using namespace std;
  20.  
  21. class Game_design
  22. {
  23.  
  24. private:
  25.  
  26. int card;
  27. Player player;
  28.  
  29. public:
  30.  
  31. Game_design()
  32. {
  33. this->card = 0;
  34. }
  35.  
  36. Game_design(int card)
  37. {
  38. this->card = card;
  39. }
  40.  
  41. void addplayer()
  42. {
  43. string name;
  44. string last_name;
  45. int money;
  46. int money_bank;
  47.  
  48. cout << "Please enter you name: ";
  49. cin >> name;
  50. player.setname(name);
  51. cout << "Please enter yor last_name: ";
  52. cin >> last_name;
  53. player.setlast_name(last_name);
  54. }
  55.  
  56. void Gameplay()
  57. {
  58. int money;
  59. int money_bank;
  60. cout << "Please enter you amount of money bank" << " $";
  61. cin >> money_bank;
  62. player.setmoney_bank(money_bank);
  63. while (true)
  64. {
  65. cout << "Please give you money" << " $";
  66. cin >> money;
  67. money_bank = money_bank - money;
  68. cout << "Now your bank" << money_bank << endl;
  69. cout << endl;
  70.  
  71. int p = 0;
  72. cout << "Player:" << endl;
  73. for (int i = 0; i < 2; i++)
  74. {
  75. card = rand() % 2 + 14;
  76. p += card;
  77. cout << "Card " << card << endl;
  78. }
  79.  
  80. cout << "Player have: " << p << " Points" << endl;
  81. if (p < 19)
  82. {
  83. int t = 1 + rand() % 3;
  84. for (int i = 0; i < t; i++)
  85. {
  86. if (p < 20)
  87. {
  88. card = rand() % 2 + 14;
  89. cout << "Card: " << card << endl;
  90. p += card;
  91. }
  92. }
  93. }
  94. cout << "Now player has: " << p << " Point" << endl;
  95. if (p > 21)
  96. {
  97. cout << "Player lose!" << endl;;
  98. player.ShowPlayer();
  99. cout << " computer win!" << endl;
  100. cout << "Your bank: " << money_bank << endl;
  101. cout << endl;
  102. }
  103. else if (p == 21)
  104. {
  105. cout << "Your have Black Jack, you win, computer lose!!!" << endl;
  106. money_bank = money_bank + (money * 3);
  107. cout << "Now your bank: " << money_bank << endl;
  108. }
  109.  
  110.  
  111.  
  112.  
  113. cout << "Computer have: " << endl;
  114. int pComputer = 0;
  115.  
  116. for (int i = 0; i < 2; i++)
  117. {
  118. card = rand() % 2 + 14;
  119. pComputer += card;
  120. cout << "Card " << card << endl;
  121. }
  122.  
  123. cout << endl;
  124.  
  125. cout << "Computer have " << pComputer << " points" << endl;
  126. if (pComputer < 19)
  127. {
  128. int tc = 1 + rand() % 3;
  129. for (int i = 0; i < tc; i++)
  130. {
  131. if (pComputer < 20)
  132. {
  133. card = rand() % 2 + 14;
  134. cout << "Card: " << card << endl;
  135. pComputer += card;
  136. }
  137. }
  138. }
  139.  
  140. cout << endl;
  141.  
  142. cout << "Now Computer has: " << pComputer << " Point" << endl;
  143. if (pComputer > 21)
  144. {
  145. cout << "Computer lose!";
  146. player.ShowPlayer();
  147. cout << " player win!" << endl;
  148. money_bank = money_bank + (money * 2);
  149. cout << "Now your bank: " << money_bank << endl;
  150. }
  151. else if (pComputer == 21)
  152. {
  153. cout << "Computer have Black Jack!!!" << endl;
  154. cout << "Now your bank: " << money_bank << endl;
  155.  
  156. }
  157.  
  158. if (pComputer <= 21 && p <= 21)
  159. {
  160. if (pComputer > p)
  161. {
  162. cout << "Your lose ";
  163. player.ShowPlayer();
  164. cout << "Now your bank: " << money_bank << endl;
  165. cout << " computer win!";
  166. player.ShowPlayer();
  167. }
  168. if (pComputer < p)
  169. {
  170. cout << "Computer lose!";
  171. player.ShowPlayer();
  172. cout << " you won" << endl;
  173. money_bank = money_bank + (money * 2);
  174. cout << "Now your bank: " << money_bank << endl;
  175. }
  176. }
  177. else
  178. {
  179.  
  180. /* if (pComputer > 21 && p > 21)
  181. {
  182. if (pComputer < p)
  183. {
  184. cout << "But on the computer the value is closer to 21, so he won" << endl;
  185.  
  186. cout << endl;
  187. cout << "Now your bank: " << money_bank << endl;
  188.  
  189. cout << endl;
  190. }
  191. if (pComputer > p)
  192. {
  193.  
  194. cout << "But on the player the value is closer to 21, so he won" << endl;
  195. money_bank = money_bank + (money * 2);
  196. cout << "Now your bank: " << money_bank << endl;
  197. cout << endl;
  198. }
  199. }
  200. }*/
  201. player.ShowPlayer();
  202. cout << " lose, Computer wins";
  203.  
  204. cout << endl;
  205. }
  206. }
  207. }
  208. };
  209.  
  210.  
  211. Player.h
  212. #pragma once
  213. #include <iostream>
  214. #include <string>
  215. #include <ctime>
  216.  
  217. using namespace std;
  218.  
  219. class Player
  220. {
  221.  
  222.  
  223. private:
  224. string name;
  225. string last_name;
  226. int money;
  227. int money_bank;
  228.  
  229. public:
  230.  
  231. Player() {}
  232.  
  233. Player(string name, string last_name, int money, int money_bank)
  234. {
  235. this->name = name;
  236. this->last_name;
  237. this->money = money;
  238. this->money_bank = money_bank;
  239. }
  240.  
  241. Player(const Player&obj)
  242. {
  243. this->name = obj.name;
  244. this->last_name = obj.last_name;
  245. this->money = obj.money;
  246. this->money_bank = obj.money_bank;
  247. }
  248.  
  249. string getname() { return this->name; }
  250. string getlast_name() { return this->last_name; }
  251. int getmoney() { return this->money; }
  252. int getmoney_bank() { return this->money_bank; }
  253.  
  254. void setname(string name) { this->name = name; }
  255. void setlast_name(string lasy_name) { this->last_name; }
  256. void setmoney(int money) { this->money = money; }
  257. void setmoney_bank(int money_bank) { this->money_bank = money_bank; }
  258.  
  259. void ShowPlayer()
  260. {
  261.  
  262. cout << this->getname() << " " << this->getlast_name();
  263.  
  264. }
  265.  
  266. void ShowMoney()
  267. {
  268.  
  269. cout << this->getmoney() << " $" << endl;
  270. cout << this->getmoney_bank() << " $" << endl;
  271. }
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280. };
Add Comment
Please, Sign In to add comment