Advertisement
Stinsfire

C++ seminar Poker

Jun 6th, 2012
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.49 KB | None | 0 0
  1. #include<iostream> //igra poker - pokušaj
  2. #include<cstdlib>
  3. #include<string>
  4. #include<ctime>
  5.  
  6.  
  7. using namespace std;
  8. int main()
  9. {
  10. srand (time(0));
  11. int spil[52];
  12. int i, a, m;
  13. string vrstaime[4]={"Srca", "Pika", "Karoa", "Trefa"}; //vrsta karata
  14. string brojime[13]={" A", " 2", " 3", " 4", " 5"," 6"," 7"," 8"," 9"," 10"," J"," Q"," K"}; //broj karata
  15.  
  16. cout<<" "<<endl;
  17. cout<<" $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"<<endl;
  18. cout<<" $$$ $$$$$ $$$$ $$$$$ $$ $$$ $$$$$"<<endl;
  19. cout<<" $$$ $$$$$ $$$ $$$$$ $$$ $$$$ $$$ $$$$$$$$ $$$$$ $$$$"<<endl;
  20. cout<<" $$$ $$$$$ $$$ $$$$$ $$$ $$$ $$$$ $$$$$$$$ $$$$$ $$$$"<<endl;
  21. cout<<" $$$ $$$$ $$$$$ $$$ $$ $$$$$ $$$$$$$$ $$$$$"<<endl;
  22. cout<<" $$$ $$$$$$$$$ $$$$$ $$$ $$$$$$ $$$ $$$$$$$$$"<<endl;
  23. cout<<" $$$ $$$$$$$$$ $$$$$ $$$ $$ $$$$$ $$$$$$$$ $ $$$$$$$$"<<endl;
  24. cout<<" $$$ $$$$$$$$$ $$$$$ $$$ $$$ $$$$ $$$$$$$$ $$ $$$$$$$"<<endl;
  25. cout<<" $$$ $$$$$$$$$ $$$$$ $$$ $$$$ $$$ $$$$$$$$ $$$$ $$$$$"<<endl;
  26. cout<<" $$$ $$$$$$$$$$ $$$$ $$$$$ $$ $$$ $$$$$ $$$$"<<endl;
  27. cout<<" $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n"<<endl;
  28.  
  29. while (a<1 || a>2) {
  30.  
  31. cout<<" Odaberite da li zelite sami unijeti vrijednost karata ili ce karte biti"<<endl;
  32. cout<<" nasumicno izgenerirane( 1=Sami unesite 2=Nasumicno regeneriranje):";
  33. cin>>a;
  34. cout<<endl;
  35. }
  36.  
  37. for (i=0; i<52; i++) //napravljeni novi spil
  38. {
  39. spil[i]=i;
  40. }
  41.  
  42. for (i=0; i<52; i++) //promijesane karte i napravljeni novi promjesan spil
  43. {
  44. int j=rand()%52;
  45. int temp=spil[i];
  46. spil[i]=spil[j];
  47. spil[j]=temp;
  48. }
  49.  
  50. for (i=0; i<52; i++) //promjesan spil i ispisane karte
  51. {
  52. int vrstabroj = spil[i]/13;
  53. int brojk = spil[i]%13;
  54. }
  55.  
  56. int R[5]; //dobivanje broja karata
  57. int S[5]; //dobivanje boje karata
  58.  
  59. //korisnik odabire mogucnost vlastitog unosa karata
  60. if (a == 1)
  61. {
  62. cout<<"Vrijednosti karata su sljedece:A=0"<<endl;
  63. cout<<" 2=1"<<endl;
  64. cout<<" 3=2"<<endl;
  65. cout<<" 4=3"<<endl;
  66. cout<<" 5=4"<<endl;
  67. cout<<" 6=5"<<endl;
  68. cout<<" 7=6"<<endl;
  69. cout<<" 8=7"<<endl;
  70. cout<<" 9=8"<<endl;
  71. cout<<" 10=9"<<endl;
  72. cout<<" J=10"<<endl;
  73. cout<<" Q=11"<<endl;
  74. cout<<" K=12"<<endl;
  75. cout<<""<<endl;
  76.  
  77.  
  78. while (R[0]<0 || R[0]>13) {
  79. cout<<" Unesite vrijednost prve karte:";
  80.  
  81. cin>> R[0];
  82. }
  83.  
  84. while (R[1]<0 || R[1]>13) {
  85. cout<<" Unesite vrijednost druge karte:";
  86. cin>> R[1];
  87. }
  88.  
  89. while (R[2]<0 || R[2]>13) {
  90.  
  91. cout<<" Unesite vrijednost trece karte:";
  92. cin>> R[2];
  93. }
  94.  
  95. while (R[3]<0 || R[3]>13) {
  96. cout<<" Unesite vrijednost cetvrte karte:";
  97. cin>> R[3];
  98. }
  99.  
  100. while (R[4]<0 || R[4]>13) {
  101. cout<<" Unesite vrijednost pete karte:";
  102. cin>> R[4];
  103. cout<<""<<endl;
  104. }
  105.  
  106.  
  107. cout<<"Vrijednosti boja su sljedece:Srce=0"<<endl;
  108. cout<<" Pik=1"<<endl;
  109. cout<<" Karo=2"<<endl;
  110. cout<<" Tref=3"<<endl;
  111. cout<<""<<endl;
  112.  
  113. while (S[0]<0 || S[0]>3) {
  114. cout<<" Unesite boju prve karte:";
  115. cin>> S[0];
  116. }
  117.  
  118. while (S[1]<0 || S[1]>3) {
  119. cout<<" Unesite boju druge karte:";
  120. cin>> S[1];
  121. }
  122.  
  123. while (S[2]<0 || S[2]>3) {
  124. cout<<" Unesite boju trece karte:";
  125. cin>> S[2];
  126. }
  127.  
  128. while (S[3]<0 || S[3]>3) {
  129. cout<<" Unesite boju cetvrte karte:";
  130. cin>> S[3];
  131. }
  132.  
  133. while (S[4]<0 || S[4]>3) {
  134. cout<<" Unesite boju pete karte:";
  135. cin>> S[4];
  136. }
  137.  
  138. cout<<""<<endl;
  139. }
  140. else
  141.  
  142. for (i=0; i<5; i++)
  143. {
  144. R[i] = spil[i]%13;
  145. S[i] = spil[i]/13;
  146. }
  147.  
  148.  
  149.  
  150.  
  151. bool swapped = false;
  152. do
  153. {
  154. //prolaz kroz bubble petlju
  155. swapped = false;
  156. for(int i=0; i<4; i++)
  157. {
  158. if(R[i] > R[i+1])
  159. {
  160. int temp = R[i];
  161. R[i] = R[i+1];
  162. R[i+1] = temp;
  163. swapped = true;
  164. }
  165. }
  166. }
  167. while(swapped == true);
  168.  
  169.  
  170.  
  171. for (i=0; i<5; i++) //ispisivanje prvih 5 dobivenih karata
  172. {
  173. cout<<brojime[R[i]] << " od " << vrstaime[S[i]] <<endl;
  174. }
  175. cout<<endl;
  176.  
  177.  
  178. //ispitivanje Royal Flush-a
  179. if((R[0] == 0 && R[1] == 9 && R[2] == 10 && R[3] == 11 && R[4] == 12 ) &&
  180. (S[0] == S[1] && S[2]==S[3] && S[0]==S[4]))
  181. {
  182. cout<<"Dobili ste Royal Flush!"<<endl;
  183. }
  184. else
  185.  
  186.  
  187. //ispitivanje Skale u boji
  188. if((R[1]==R[0]+1 && R[2]==R[1]+1 && R[3]==R[2]+1 && R[4]==R[3]+1) && (S[0] == S[1] && S[2]==S[3] && S[4]==S[0]))
  189. {
  190. cout<<"Dobili ste Skalu u Boji!"<<endl;
  191. }
  192. else
  193.  
  194.  
  195. //ispitivanje Cetri iste
  196. if((R[0] == R[1] && R[2] == R[3] && R[0] == R[3]) ||
  197. (R[0] == R[1] && R[2] == R[4] && R[0] == R[4]) ||
  198. (R[0] == R[2] && R[3] == R[4] && R[0] == R[3]) ||
  199. (R[1] == R[2] && R[3] == R[4] && R[1] == R[4]))
  200. {
  201. cout<<"Dobili ste Cetiri Iste!"<<endl;
  202. }
  203. else
  204.  
  205.  
  206. //ispitivanje Full House
  207. if((R[0] == R[1] && R[2] == R[3] && R[3] == R[4]) ||
  208. (R[0] == R[2] && R[3] == R[4] && R[4] == R[1]) ||
  209. (R[0] == R[3] && R[1] == R[2] && R[2] == R[4]) ||
  210. (R[0] == R[4] && R[1] == R[2] && R[2] == R[3]) ||
  211. (R[1] == R[2] && R[0] == R[4] && R[4] == R[3]) ||
  212. (R[1] == R[3] && R[2] == R[4] && R[4] == R[0]) ||
  213. (R[1] == R[4] && R[0] == R[3] && R[3] == R[2]) ||
  214. (R[2] == R[3] && R[4] == R[1] && R[4] == R[0]) ||
  215. (R[3] == R[4] && R[1] == R[2] && R[2] == R[0]) ||
  216. (R[2] == R[4] && R[3] == R[1] && R[1] == R[0]))
  217. {
  218. cout<<"Dobili ste Full House!"<<endl;
  219. }
  220. else
  221.  
  222.  
  223. //ispitivanje Boje
  224. if(S[0] == S[1] && S[2]==S[3] && S[4]==S[0])
  225. {
  226. cout<<"Dobili ste Boju!"<<endl;
  227. }
  228. else
  229.  
  230.  
  231. //ispititvanje Skale
  232. if ((R[0] == 0 && R[1] == 9 && R[2] == 10 && R[3] == 11 && R[4] == 12 ) ||
  233. (R[1]==0 && R[2]==R[1]+1 && R[3]==R[2]+1 && R[4]==R[3]+1))
  234. {
  235. cout<<"Dobili ste Skalu!"<<endl;
  236. }
  237. else
  238.  
  239.  
  240. //ispitivanje Trisa
  241. if(R[0] == R[1] && R[1] == R[2] || R[1] == R[2] && R[2] == R[3] || R[2] == R[3] && R[3]== R[4])
  242. {
  243. cout<<"Dobili ste Tris!"<<endl;
  244. }
  245. else
  246.  
  247.  
  248. //ispitivanje Dva Para
  249. if((R[0] == R[1] && R[2] == R[3]) || (R[1] == R[2] && R[3] == R[4]) || (R[0] == R[1] && R[3] == R[4]))
  250. {
  251. cout<<"Dobili ste Dva Para!"<<endl;
  252. }
  253. else
  254.  
  255.  
  256. //ispitivanje Para
  257. if(R[0] == R[1] || R[1] == R[2] || R[2] == R[3] || R[3] == R[4])
  258. {
  259. cout<<"Dobili ste Par!"<<endl;
  260. }
  261. else
  262.  
  263. //ispis
  264. cout<<"Niste dobili nista!"<<endl;
  265.  
  266.  
  267.  
  268. cout<<endl;
  269. cout<<endl;
  270. system("pause");
  271. return 0;
  272. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement