Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: sagoky en 15 Septiembre 2010, 17:47 pm



Título: turbo c++ ayuda con el gato
Publicado por: sagoky en 15 Septiembre 2010, 17:47 pm
bueno pues no tengo mucho que empeze a usar el turbo c++ y quisiera saber si ay alguna funcion para hacer mas corto el juego del gato contra la computadora
tambien soy nuevo en el foro y esto es lo que yevo
Código
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int g;
  7. char r[100];
  8. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  9. cout<<"   |   |             |   |    "<<endl;
  10. cout<<" 1 | 2 | 3           |   |   "<<endl;
  11. cout<<"___|___|___       ___|___|___"<<endl;
  12. cout<<"   |   |             |   |   "<<endl;
  13. cout<<" 4 | 5 | 6           |   |   "<<endl;
  14. cout<<"___|___|___       ___|___|___ "<<endl;
  15. cout<<"   |   |             |   |  "<<endl;
  16. cout<<" 7 | 8 | 9           |   |  "<<endl;
  17. cout<<"   |   |             |   |  "<<endl;
  18. cin>>r[0];
  19. if(r[0]=='1' || r[0]=='2' || r[0]=='3' || r[0]=='4' || r[0]=='5' || r[0]=='6' || r[0]=='7' || r[0]=='8' || r[0]==9)
  20. {//ciclo del gato
  21. if(r[0]=='1')
  22. {//if del 1-1
  23. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  24. cout<<"   |   |             |   |    "<<endl;
  25. cout<<" 1 | 2 | 3         X |   |   "<<endl;
  26. cout<<"___|___|___       ___|___|___"<<endl;
  27. cout<<"   |   |             |   |   "<<endl;
  28. cout<<" 4 | 5 | 6           |   |   "<<endl;
  29. cout<<"___|___|___       ___|___|___ "<<endl;
  30. cout<<"   |   |             |   |  "<<endl;
  31. cout<<" 7 | 8 | 9           |   | O "<<endl;
  32. cout<<"   |   |             |   |  "<<endl;
  33. cin>>r[1];
  34. if(r[1]=='2')
  35. {
  36. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  37. cout<<"   |   |             |   |    "<<endl;
  38. cout<<" 1 | 2 | 3         X | X | O "<<endl;
  39. cout<<"___|___|___       ___|___|___"<<endl;
  40. cout<<"   |   |             |   |   "<<endl;
  41. cout<<" 4 | 5 | 6           |   |   "<<endl;
  42. cout<<"___|___|___       ___|___|___ "<<endl;
  43. cout<<"   |   |             |   |  "<<endl;
  44. cout<<" 7 | 8 | 9           |   | O"<<endl;
  45. cout<<"   |   |             |   |  "<<endl;
  46. cin>>r[2];
  47. if(r[2]=='4')
  48. {
  49. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  50. cout<<"   |   |             |   |    "<<endl;
  51. cout<<" 1 | 2 | 3         X | X | O "<<endl;
  52. cout<<"___|___|___       ___|___|___"<<endl;
  53. cout<<"   |   |             |   |   "<<endl;
  54. cout<<" 4 | 5 | 6         X |   | O "<<endl;
  55. cout<<"___|___|___       ___|___|___ "<<endl;
  56. cout<<"   |   |             |   |  "<<endl;
  57. cout<<" 7 | 8 | 9           |   | O "<<endl;
  58. cout<<"   |   |             |   |  "<<endl;
  59. cout<<"gane ^^ "<<endl;
  60. }
  61. if(r[2]=='5')
  62. {
  63. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  64. cout<<"   |   |             |   |    "<<endl;
  65. cout<<" 1 | 2 | 3         X | X | O "<<endl;
  66. cout<<"___|___|___       ___|___|___"<<endl;
  67. cout<<"   |   |             |   |   "<<endl;
  68. cout<<" 4 | 5 | 6           | X | O "<<endl;
  69. cout<<"___|___|___       ___|___|___ "<<endl;
  70. cout<<"   |   |             |   |  "<<endl;
  71. cout<<" 7 | 8 | 9           |   | O "<<endl;
  72. cout<<"   |   |             |   |  "<<endl;
  73. cout<<"gane "<<endl;
  74. }
  75. if(r[2]=='7')
  76. {
  77. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  78. cout<<"   |   |             |   |    "<<endl;
  79. cout<<" 1 | 2 | 3         X | X | O "<<endl;
  80. cout<<"___|___|___       ___|___|___"<<endl;
  81. cout<<"   |   |             |   |   "<<endl;
  82. cout<<" 4 | 5 | 6           |   | O"<<endl;
  83. cout<<"___|___|___       ___|___|___ "<<endl;
  84. cout<<"   |   |             |   |  "<<endl;
  85. cout<<" 7 | 8 | 9         X |   | O "<<endl;
  86. cout<<"   |   |             |   |  "<<endl;
  87. cout<<" gane "<<endl;
  88. }
  89. if(r[2]=='8')
  90. {
  91. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  92. cout<<"   |   |             |   |    "<<endl;
  93. cout<<" 1 | 2 | 3         X | X | O "<<endl;
  94. cout<<"___|___|___       ___|___|___"<<endl;
  95. cout<<"   |   |             |   |   "<<endl;
  96. cout<<" 4 | 5 | 6           |   | O "<<endl;
  97. cout<<"___|___|___       ___|___|___ "<<endl;
  98. cout<<"   |   |             |   |  "<<endl;
  99. cout<<" 7 | 8 | 9           | X | O "<<endl;
  100. cout<<"   |   |             |   |  "<<endl;
  101. cout<<" gane "<<endl;
  102. }
  103. if(r[2]=='6')
  104. {
  105. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  106. cout<<"   |   |             |   |    "<<endl;
  107. cout<<" 1 | 2 | 3         X | X | O "<<endl;
  108. cout<<"___|___|___       ___|___|___"<<endl;
  109. cout<<"   |   |             |   |   "<<endl;
  110. cout<<" 4 | 5 | 6           |   | X "<<endl;
  111. cout<<"___|___|___       ___|___|___ "<<endl;
  112. cout<<"   |   |             |   |  "<<endl;
  113. cout<<" 7 | 8 | 9         O |   | O "<<endl;
  114. cout<<"   |   |             |   |  "<<endl;
  115. cin>>r[3];
  116. if(r[3]=='5')
  117. {
  118. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  119. cout<<"   |   |             |   |    "<<endl;
  120. cout<<" 1 | 2 | 3         X | X | O "<<endl;
  121. cout<<"___|___|___       ___|___|___"<<endl;
  122. cout<<"   |   |             |   |   "<<endl;
  123. cout<<" 4 | 5 | 6           | X | X "<<endl;
  124. cout<<"___|___|___       ___|___|___ "<<endl;
  125. cout<<"   |   |             |   |  "<<endl;
  126. cout<<" 7 | 8 | 9         O | O | O "<<endl;
  127. cout<<"   |   |             |   |  "<<endl;
  128. cout<<" gane "<<endl;
  129. }
  130. if(r[3]=='8')
  131. {
  132. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  133. cout<<"   |   |             |   |    "<<endl;
  134. cout<<" 1 | 2 | 3         X | X | O "<<endl;
  135. cout<<"___|___|___       ___|___|___"<<endl;
  136. cout<<"   |   |             |   |   "<<endl;
  137. cout<<" 4 | 5 | 6           | O | X "<<endl;
  138. cout<<"___|___|___       ___|___|___ "<<endl;
  139. cout<<"   |   |             |   |  "<<endl;
  140. cout<<" 7 | 8 | 9         O | X | O "<<endl;
  141. cout<<"   |   |             |   |  "<<endl;
  142. cout<<" gane "<<endl;
  143. }
  144. if(r[3]=='4')
  145. {
  146. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  147. cout<<"   |   |             |   |    "<<endl;
  148. cout<<" 1 | 2 | 3         X | X | O "<<endl;
  149. cout<<"___|___|___       ___|___|___"<<endl;
  150. cout<<"   |   |             |   |   "<<endl;
  151. cout<<" 4 | 5 | 6         X | O | X "<<endl;
  152. cout<<"___|___|___       ___|___|___ "<<endl;
  153. cout<<"   |   |             |   |  "<<endl;
  154. cout<<" 7 | 8 | 9         O |   | O "<<endl;
  155. cout<<"   |   |             |   |  "<<endl;
  156. cout<<" gane "<<endl;
  157. }
  158. }
  159. }
  160. if(r[1]=='3')
  161. {//if del 1-3
  162. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  163. cout<<"   |   |             |   |    "<<endl;
  164. cout<<" 1 | 2 | 3         X | O | X   "<<endl;
  165. cout<<"___|___|___       ___|___|___"<<endl;
  166. cout<<"   |   |             |   |   "<<endl;
  167. cout<<" 4 | 5 | 6           |   |   "<<endl;
  168. cout<<"___|___|___       ___|___|___ "<<endl;
  169. cout<<"   |   |             |   |  "<<endl;
  170. cout<<" 7 | 8 | 9           |   | O "<<endl;
  171. cout<<"   |   |             |   |  "<<endl;
  172. cin>>r[2];
  173. if(r[2]=='8')
  174. {//if del 1-3-7
  175. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  176. cout<<"   |   |             |   |    "<<endl;
  177. cout<<" 1 | 2 | 3         X | O | X   "<<endl;
  178. cout<<"___|___|___       ___|___|___"<<endl;
  179. cout<<"   |   |             |   |   "<<endl;
  180. cout<<" 4 | 5 | 6           | O |     "<<endl;
  181. cout<<"___|___|___       ___|___|___ "<<endl;
  182. cout<<"   |   |             |   |  "<<endl;
  183. cout<<" 7 | 8 | 9           | X | O "<<endl;
  184. cout<<"   |   |             |   |  "<<endl;
  185. cin>>r[3];
  186. if(r[3]=='4')
  187. {
  188. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  189. cout<<"   |   |             |   |    "<<endl;
  190. cout<<" 1 | 2 | 3         X | O | X   "<<endl;
  191. cout<<"___|___|___       ___|___|___"<<endl;
  192. cout<<"   |   |             |   |   "<<endl;
  193. cout<<" 4 | 5 | 6         X | O |    "<<endl;
  194. cout<<"___|___|___       ___|___|___ "<<endl;
  195. cout<<"   |   |             |   |  "<<endl;
  196. cout<<" 7 | 8 | 9         O | X | O "<<endl;
  197. cout<<"   |   |             |   |  "<<endl;
  198. cout<<" empate "<<endl;
  199. }
  200. if(r[3]=='7')
  201. {
  202. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  203. cout<<"   |   |             |   |    "<<endl;
  204. cout<<" 1 | 2 | 3         X | O | X "<<endl;
  205. cout<<"___|___|___       ___|___|___"<<endl;
  206. cout<<"   |   |             |   |   "<<endl;
  207. cout<<" 4 | 5 | 6         O | O |  "<<endl;
  208. cout<<"___|___|___       ___|___|___ "<<endl;
  209. cout<<"   |   |             |   |  "<<endl;
  210. cout<<" 7 | 8 | 9         X | X | O "<<endl;
  211. cout<<"   |   |             |   |  "<<endl;
  212. cout<<" empate "<<endl;
  213. if(r[4]=='4')
  214. {
  215. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  216. cout<<"   |   |             |   |    "<<endl;
  217. cout<<" 1 | 2 | 3         X | O | X "<<endl;
  218. cout<<"___|___|___       ___|___|___"<<endl;
  219. cout<<"   |   |             |   |   "<<endl;
  220. cout<<" 4 | 5 | 6         X | O | O "<<endl;
  221. cout<<"___|___|___       ___|___|___ "<<endl;
  222. cout<<"   |   |             |   |  "<<endl;
  223. cout<<" 7 | 8 | 9         X | X | O "<<endl;
  224. cout<<"   |   |             |   |  "<<endl;
  225. }
  226. }
  227. if(r[3]=='6')
  228. {
  229. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  230. cout<<"   |   |             |   |    "<<endl;
  231. cout<<" 1 | 2 | 3         X | O | X "<<endl;
  232. cout<<"___|___|___       ___|___|___"<<endl;
  233. cout<<"   |   |             |   |   "<<endl;
  234. cout<<" 4 | 5 | 6         O | O | X  "<<endl;
  235. cout<<"___|___|___       ___|___|___ "<<endl;
  236. cout<<"   |   |             |   |  "<<endl;
  237. cout<<" 7 | 8 | 9           | X | O "<<endl;
  238. cout<<"   |   |             |   |  "<<endl;
  239. cout<<" empate "<<endl;
  240. }
  241. if(r[4]=='7')
  242. {
  243. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  244. cout<<"   |   |             |   |    "<<endl;
  245. cout<<" 1 | 2 | 3         X | O | X "<<endl;
  246. cout<<"___|___|___       ___|___|___"<<endl;
  247. cout<<"   |   |             |   |   "<<endl;
  248. cout<<" 4 | 5 | 6           | O | X  "<<endl;
  249. cout<<"___|___|___       ___|___|___ "<<endl;
  250. cout<<"   |   |             |   |  "<<endl;
  251. cout<<" 7 | 8 | 9         X | O | O "<<endl;
  252. cout<<"   |   |             |   |  "<<endl;
  253. cout<<" gane "<<endl;
  254. if(r[4]=='4')
  255. {
  256. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  257. cout<<"   |   |             |   |    "<<endl;
  258. cout<<" 1 | 2 | 3         X | O | X "<<endl;
  259. cout<<"___|___|___       ___|___|___"<<endl;
  260. cout<<"   |   |             |   |   "<<endl;
  261. cout<<" 4 | 5 | 6         X | O | X  "<<endl;
  262. cout<<"___|___|___       ___|___|___ "<<endl;
  263. cout<<"   |   |             |   |  "<<endl;
  264. cout<<" 7 | 8 | 9           | O | O "<<endl;
  265. cout<<"   |   |             |   |  "<<endl;
  266. cout<<" gane "<<endl;
  267. if(r[4]=='8')
  268. {
  269. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  270. cout<<"   |   |             |   |    "<<endl;
  271. cout<<" 1 | 2 | 3         X | O | X "<<endl;
  272. cout<<"___|___|___       ___|___|___"<<endl;
  273. cout<<"   |   |             |   |   "<<endl;
  274. cout<<" 4 | 5 | 6         O | O | X  "<<endl;
  275. cout<<"___|___|___       ___|___|___ "<<endl;
  276. cout<<"   |   |             |   |  "<<endl;
  277. cout<<" 7 | 8 | 9           | X | O "<<endl;
  278. cout<<"   |   |             |   |  "<<endl;
  279. cout<<" empate "<<endl;
  280. }
  281. }
  282. }
  283. }
  284. if(r[2]=='6')
  285. {//if del 1-3-7
  286. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  287. cout<<"   |   |             |   |    "<<endl;
  288. cout<<" 1 | 2 | 3         X | O | X   "<<endl;
  289. cout<<"___|___|___       ___|___|___"<<endl;
  290. cout<<"   |   |             |   |   "<<endl;
  291. cout<<" 4 | 5 | 6           |   | X   "<<endl;
  292. cout<<"___|___|___       ___|___|___ "<<endl;
  293. cout<<"   |   |             |   |  "<<endl;
  294. cout<<" 7 | 8 | 9         O |   | O "<<endl;
  295. cout<<"   |   |             |   |  "<<endl;
  296. cin>>r[3];
  297. if(r[3]=='5')
  298. {
  299. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  300. cout<<"   |   |             |   |    "<<endl;
  301. cout<<" 1 | 2 | 3         X | O | X   "<<endl;
  302. cout<<"___|___|___       ___|___|___"<<endl;
  303. cout<<"   |   |             |   |   "<<endl;
  304. cout<<" 4 | 5 | 6           | X | X  "<<endl;
  305. cout<<"___|___|___       ___|___|___ "<<endl;
  306. cout<<"   |   |             |   |  "<<endl;
  307. cout<<" 7 | 8 | 9         O | O | O "<<endl;
  308. cout<<"   |   |             |   |  "<<endl;
  309. cout<<" gane "<<endl;
  310. }
  311. if(r[3]=='4')
  312. {
  313. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  314. cout<<"   |   |             |   |    "<<endl;
  315. cout<<" 1 | 2 | 3         X | O | X "<<endl;
  316. cout<<"___|___|___       ___|___|___"<<endl;
  317. cout<<"   |   |             |   |   "<<endl;
  318. cout<<" 4 | 5 | 6         X |   | X "<<endl;
  319. cout<<"___|___|___       ___|___|___ "<<endl;
  320. cout<<"   |   |             |   |  "<<endl;
  321. cout<<" 7 | 8 | 9         O | O | O "<<endl;
  322. cout<<"   |   |             |   |  "<<endl;
  323. cout<<" Gane "<<endl;
  324. }
  325. if(r[3]=='8')
  326. {
  327. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  328. cout<<"   |   |             |   |    "<<endl;
  329. cout<<" 1 | 2 | 3         X | O | X "<<endl;
  330. cout<<"___|___|___       ___|___|___"<<endl;
  331. cout<<"   |   |             |   |   "<<endl;
  332. cout<<" 4 | 5 | 6           | O | X "<<endl;
  333. cout<<"___|___|___       ___|___|___ "<<endl;
  334. cout<<"   |   |             |   |  "<<endl;
  335. cout<<" 7 | 8 | 9         O | X | O "<<endl;
  336. cout<<"   |   |             |   |  "<<endl;
  337. cout<<" empate "<<endl;
  338. }
  339. }
  340. if(r[2]=='7')
  341. {//if del 1-3-7
  342. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  343. cout<<"   |   |             |   |    "<<endl;
  344. cout<<" 1 | 2 | 3         X | O | X   "<<endl;
  345. cout<<"___|___|___       ___|___|___"<<endl;
  346. cout<<"   |   |             |   |   "<<endl;
  347. cout<<" 4 | 5 | 6           | O |   "<<endl;
  348. cout<<"___|___|___       ___|___|___ "<<endl;
  349. cout<<"   |   |             |   |  "<<endl;
  350. cout<<" 7 | 8 | 9         X |   | O "<<endl;
  351. cout<<"   |   |             |   |  "<<endl;
  352. cin>>r[3];
  353. if(r[3]=='4')
  354. {//1-3-7-4
  355. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  356. cout<<"   |   |             |   |    "<<endl;
  357. cout<<" 1 | 2 | 3         X | O | X "<<endl;
  358. cout<<"___|___|___       ___|___|___"<<endl;
  359. cout<<"   |   |             |   |   "<<endl;
  360. cout<<" 4 | 5 | 6         X | O |   "<<endl;
  361. cout<<"___|___|___       ___|___|___ "<<endl;
  362. cout<<"   |   |             |   |  "<<endl;
  363. cout<<" 7 | 8 | 9         X |   | O "<<endl;
  364. cout<<"   |   |             |   |  "<<endl;
  365. cout<<"Felicidades ganaste "<<endl;
  366. }//1-3-7-4
  367. if(r[3]=='8')
  368. {//1-3-7-8
  369. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  370. cout<<"   |   |             |   |    "<<endl;
  371. cout<<" 1 | 2 | 3         X | O | X "<<endl;
  372. cout<<"___|___|___       ___|___|___"<<endl;
  373. cout<<"   |   |             |   |   "<<endl;
  374. cout<<" 4 | 5 | 6         O | O |  "<<endl;
  375. cout<<"___|___|___       ___|___|___ "<<endl;
  376. cout<<"   |   |             |   |  "<<endl;
  377. cout<<" 7 | 8 | 9         X | X | O "<<endl;
  378. cout<<"   |   |             |   |  "<<endl;
  379. cout<<"empate "<<endl;
  380. }//1-3-7-8
  381. if(r[3]=='6')
  382. {//1-3-7-6
  383. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  384. cout<<"   |   |             |   |    "<<endl;
  385. cout<<" 1 | 2 | 3         X | O | X "<<endl;
  386. cout<<"___|___|___       ___|___|___"<<endl;
  387. cout<<"   |   |             |   |   "<<endl;
  388. cout<<" 4 | 5 | 6         O | O | X "<<endl;
  389. cout<<"___|___|___       ___|___|___ "<<endl;
  390. cout<<"   |   |             |   |  "<<endl;
  391. cout<<" 7 | 8 | 9         X |   | O "<<endl;
  392. cout<<"   |   |             |   |  "<<endl;
  393. cout<<"empate "<<endl;
  394. }//1-3-7-6
  395. }//if del 1-3-7
  396. if(r[2]=='4')
  397. {
  398. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  399. cout<<"   |   |             |   |    "<<endl;
  400. cout<<" 1 | 2 | 3         X | O | X   "<<endl;
  401. cout<<"___|___|___       ___|___|___"<<endl;
  402. cout<<"   |   |             |   |   "<<endl;
  403. cout<<" 4 | 5 | 6         X |   |   "<<endl;
  404. cout<<"___|___|___       ___|___|___ "<<endl;
  405. cout<<"   |   |             |   |  "<<endl;
  406. cout<<" 7 | 8 | 9         O |   | O "<<endl;
  407. cout<<"   |   |             |   |  "<<endl;
  408. cin>>r[4];
  409. if(r[4]=='5')
  410. {
  411. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  412. cout<<"   |   |             |   |    "<<endl;
  413. cout<<" 1 | 2 | 3         X | O | X   "<<endl;
  414. cout<<"___|___|___       ___|___|___"<<endl;
  415. cout<<"   |   |             |   |   "<<endl;
  416. cout<<" 4 | 5 | 6         X | X |   "<<endl;
  417. cout<<"___|___|___       ___|___|___ "<<endl;
  418. cout<<"   |   |             |   |  "<<endl;
  419. cout<<" 7 | 8 | 9         O | O | O "<<endl;
  420. cout<<"   |   |             |   |  "<<endl;
  421. cout<<" gane "<<endl;
  422. }
  423. if(r[4]=='8')
  424. {
  425. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  426. cout<<"   |   |             |   |    "<<endl;
  427. cout<<" 1 | 2 | 3         X | O | X   "<<endl;
  428. cout<<"___|___|___       ___|___|___"<<endl;
  429. cout<<"   |   |             |   |   "<<endl;
  430. cout<<" 4 | 5 | 6         X | O |   "<<endl;
  431. cout<<"___|___|___       ___|___|___ "<<endl;
  432. cout<<"   |   |             |   |  "<<endl;
  433. cout<<" 7 | 8 | 9         O | X | O "<<endl;
  434. cout<<"   |   |             |   |  "<<endl;
  435. cout<<" empate "<<endl;
  436. }
  437. if(r[4]=='6')
  438. {
  439. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  440. cout<<"   |   |             |   |    "<<endl;
  441. cout<<" 1 | 2 | 3         X | O | X   "<<endl;
  442. cout<<"___|___|___       ___|___|___"<<endl;
  443. cout<<"   |   |             |   |   "<<endl;
  444. cout<<" 4 | 5 | 6         X |   | X  "<<endl;
  445. cout<<"___|___|___       ___|___|___ "<<endl;
  446. cout<<"   |   |             |   |  "<<endl;
  447. cout<<" 7 | 8 | 9         O | O | O "<<endl;
  448. cout<<"   |   |             |   |  "<<endl;
  449. cout<<"gane "<<endl;
  450. }
  451. }//if 1-3-4
  452. if(r[2]=='5')
  453. {//if del 1-3-7
  454. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  455. cout<<"   |   |             |   |    "<<endl;
  456. cout<<" 1 | 2 | 3         X | O | X   "<<endl;
  457. cout<<"___|___|___       ___|___|___"<<endl;
  458. cout<<"   |   |             |   |   "<<endl;
  459. cout<<" 4 | 5 | 6           | X |   "<<endl;
  460. cout<<"___|___|___       ___|___|___ "<<endl;
  461. cout<<"   |   |             |   |  "<<endl;
  462. cout<<" 7 | 8 | 9         O |   | O "<<endl;
  463. cout<<"   |   |             |   |  "<<endl;
  464. cin>>r[4];
  465. if(r[4]=='6')
  466. {
  467. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  468. cout<<"   |   |             |   |    "<<endl;
  469. cout<<" 1 | 2 | 3         X | O | X   "<<endl;
  470. cout<<"___|___|___       ___|___|___"<<endl;
  471. cout<<"   |   |             |   |   "<<endl;
  472. cout<<" 4 | 5 | 6           | X | X  "<<endl;
  473. cout<<"___|___|___       ___|___|___ "<<endl;
  474. cout<<"   |   |             |   |  "<<endl;
  475. cout<<" 7 | 8 | 9         O | O | O "<<endl;
  476. cout<<"   |   |             |   |  "<<endl;
  477. cout<<" gane "<<endl;
  478. }
  479. if(r[4]=='4')
  480. {
  481. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  482. cout<<"   |   |             |   |    "<<endl;
  483. cout<<" 1 | 2 | 3         X | O | X "<<endl;
  484. cout<<"___|___|___       ___|___|___"<<endl;
  485. cout<<"   |   |             |   |   "<<endl;
  486. cout<<" 4 | 5 | 6         X | X |  "<<endl;
  487. cout<<"___|___|___       ___|___|___ "<<endl;
  488. cout<<"   |   |             |   |  "<<endl;
  489. cout<<" 7 | 8 | 9         O | O | O "<<endl;
  490. cout<<"   |   |             |   |  "<<endl;
  491. cout<<" gane "<<endl;
  492. }
  493. if(r[4]=='8')
  494. {
  495. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  496. cout<<"   |   |             |   |    "<<endl;
  497. cout<<" 1 | 2 | 3         X | O | X "<<endl;
  498. cout<<"___|___|___       ___|___|___"<<endl;
  499. cout<<"   |   |             |   |   "<<endl;
  500. cout<<" 4 | 5 | 6           | X | O "<<endl;
  501. cout<<"___|___|___       ___|___|___ "<<endl;
  502. cout<<"   |   |             |   |  "<<endl;
  503. cout<<" 7 | 8 | 9         O | X | O "<<endl;
  504. cout<<"   |   |             |   |  "<<endl;
  505. cout<<" empate "<<endl;
  506. }
  507. }
  508. }//if del 1-3
  509. if(r[1]=='4')
  510. {//if del 1-4
  511. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  512. cout<<"   |   |             |   |    "<<endl;
  513. cout<<" 1 | 2 | 3         X |   |   "<<endl;
  514. cout<<"___|___|___       ___|___|___"<<endl;
  515. cout<<"   |   |             |   |   "<<endl;
  516. cout<<" 4 | 5 | 6         X |   |   "<<endl;
  517. cout<<"___|___|___       ___|___|___ "<<endl;
  518. cout<<"   |   |             |   |  "<<endl;
  519. cout<<" 7 | 8 | 9         O |   | O "<<endl;
  520. cout<<"   |   |             |   |  "<<endl;
  521. cin>>r[1];
  522. }//if del 1-4
  523. } //if del 1-1
  524. if(r[0]=='2')
  525. { //if del 2-1
  526. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  527. cout<<"   |   |             |   |    "<<endl;
  528. cout<<" 1 | 2 | 3           | X |   "<<endl;
  529. cout<<"___|___|___       ___|___|___"<<endl;
  530. cout<<"   |   |             |   |   "<<endl;
  531. cout<<" 4 | 5 | 6           |   |   "<<endl;
  532. cout<<"___|___|___       ___|___|___ "<<endl;
  533. cout<<"   |   |             |   |  "<<endl;
  534. cout<<" 7 | 8 | 9         O |   |  "<<endl;
  535. cout<<"   |   |             |   |  "<<endl;
  536. }  //if del 2-1
  537. if(r[0]=='3')
  538. {//if del 3-1
  539. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  540. cout<<"   |   |             |   |    "<<endl;
  541. cout<<" 1 | 2 | 3           |   | X   "<<endl;
  542. cout<<"___|___|___       ___|___|___"<<endl;
  543. cout<<"   |   |             |   |   "<<endl;
  544. cout<<" 4 | 5 | 6           |   |   "<<endl;
  545. cout<<"___|___|___       ___|___|___ "<<endl;
  546. cout<<"   |   |             |   |  "<<endl;
  547. cout<<" 7 | 8 | 9           |   | O "<<endl;
  548. cout<<"   |   |             |   |  "<<endl;
  549. }  //if del 3-1
  550. if(r[0]=='4')
  551. {//if del 4-1
  552. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  553. cout<<"   |   |             |   |    "<<endl;
  554. cout<<" 1 | 2 | 3           |   | O   "<<endl;
  555. cout<<"___|___|___       ___|___|___"<<endl;
  556. cout<<"   |   |             |   |   "<<endl;
  557. cout<<" 4 | 5 | 6         X |   |   "<<endl;
  558. cout<<"___|___|___       ___|___|___ "<<endl;
  559. cout<<"   |   |             |   |  "<<endl;
  560. cout<<" 7 | 8 | 9           |   |   "<<endl;
  561. cout<<"   |   |             |   |  "<<endl;
  562. }//if del 4-1
  563. if(r[0]=='5')
  564. {//if del 5-1
  565. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  566. cout<<"   |   |             |   |    "<<endl;
  567. cout<<" 1 | 2 | 3           |   | O   "<<endl;
  568. cout<<"___|___|___       ___|___|___"<<endl;
  569. cout<<"   |   |             |   |   "<<endl;
  570. cout<<" 4 | 5 | 6           | X |   "<<endl;
  571. cout<<"___|___|___       ___|___|___ "<<endl;
  572. cout<<"   |   |             |   |  "<<endl;
  573. cout<<" 7 | 8 | 9           |   |  "<<endl;
  574. cout<<"   |   |             |   |  "<<endl;
  575. }//if del 5-1
  576. if(r[0]=='6')
  577. {//if del 6-1
  578. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  579. cout<<"   |   |             |   |    "<<endl;
  580. cout<<" 1 | 2 | 3           |   |   "<<endl;
  581. cout<<"___|___|___       ___|___|___"<<endl;
  582. cout<<"   |   |             |   |   "<<endl;
  583. cout<<" 4 | 5 | 6           |   | X "<<endl;
  584. cout<<"___|___|___       ___|___|___ "<<endl;
  585. cout<<"   |   |             |   |  "<<endl;
  586. cout<<" 7 | 8 | 9         O |   |  "<<endl;
  587. cout<<"   |   |             |   |  "<<endl;
  588. }//if del 6-1
  589. if(r[0]=='7')
  590. {//if del 7-1
  591. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  592. cout<<"   |   |             |   |    "<<endl;
  593. cout<<" 1 | 2 | 3           |   | O   "<<endl;
  594. cout<<"___|___|___       ___|___|___"<<endl;
  595. cout<<"   |   |             |   |   "<<endl;
  596. cout<<" 4 | 5 | 6           |   |   "<<endl;
  597. cout<<"___|___|___       ___|___|___ "<<endl;
  598. cout<<"   |   |             |   |  "<<endl;
  599. cout<<" 7 | 8 | 9         X |   |   "<<endl;
  600. cout<<"   |   |             |   |  "<<endl;
  601. }//if del 7-1
  602. if(r[0]=='8')
  603. {//if del 8-1
  604. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  605. cout<<"   |   |             |   |    "<<endl;
  606. cout<<" 1 | 2 | 3         O |   |     "<<endl;
  607. cout<<"___|___|___       ___|___|___"<<endl;
  608. cout<<"   |   |             |   |   "<<endl;
  609. cout<<" 4 | 5 | 6           |   |   "<<endl;
  610. cout<<"___|___|___       ___|___|___ "<<endl;
  611. cout<<"   |   |             |   |  "<<endl;
  612. cout<<" 7 | 8 | 9           | X |   "<<endl;
  613. cout<<"   |   |             |   |  "<<endl;
  614. }//if del 8-1
  615. if (r[0]=='9')
  616. {//if del 9-1
  617. clrscr();cout<<"   teclas            juego "<<endl;cout<<" "<<endl;
  618. cout<<"   |   |             |   |    "<<endl;
  619. cout<<" 1 | 2 | 3         O |   |     "<<endl;
  620. cout<<"___|___|___       ___|___|___"<<endl;
  621. cout<<"   |   |             |   |   "<<endl;
  622. cout<<" 4 | 5 | 6           |   |   "<<endl;
  623. cout<<"___|___|___       ___|___|___ "<<endl;
  624. cout<<"   |   |             |   |  "<<endl;
  625. cout<<" 7 | 8 | 9           |   | X "<<endl;
  626. cout<<"   |   |             |   |  "<<endl;
  627. }//if del 9-1
  628.  
  629. }//ciclo del gato
  630. else
  631. {
  632. cout<<"porfavor vuelva a iniciar "<<endl;
  633. }
  634. }
eso es lo que yevo y si siguo asi me saldra muy largo asi que por eso pido su ayuda


Título: Re: turbo c++ ayuda con el gato
Publicado por: Jaixon Jax en 16 Septiembre 2010, 05:14 am
  Pon el code en geshi  ;)


  PD se ve muy feo


Título: Re: turbo c++ ayuda con el gato
Publicado por: Littlehorse en 16 Septiembre 2010, 10:56 am
Primero, debido a algunos errores típicos vistos en el código, te diría que leas este hilo: Lo que no hay que hacer en C/C++ (http://foro.elhacker.net/programacion_cc/lo_que_no_hay_que_hacer_en_cc_nivel_basico-t277729.0.html)

En cuanto a la idea del algoritmo, te recomendaría que empieces con un buen libro de C/C++ para interiorizarte respecto de las herramientas que tienes disponibles en el lenguaje, ya que visto el acercamiento que intentas utilizar, esta claro que no estas aprovechando el potencial de C. Tenes un hilo en las chinchetas con varios para descarga.

Como ultima instancia, podes encontrar varios códigos tanto en Google como en el foro para que puedas analizarlos. Tic tac toe, ta te ti etc. son los nombres por los cuales podrás encontrarlos.

Saludos




Título: Re: turbo c++ ayuda con el gato
Publicado por: safkevin en 21 Septiembre 2010, 17:37 pm
Aqui tengo un code mas pequeño por si te interesa  ;D

Código:
#include <stdio.h>
int main ()
{
    int jugador(1),error,empate(0),ganar(0);
    char c1('1'),c2('2'),c3('3'),c4('4'),c5('5'),c6('6'),c7('7'),c8('8'),c9('9'),tiro,marca,respuesta('y');
      do{                                                    //Crea El Ciclo
      error=1;
      printf("\n %c | %c | %c\n",c1,c2,c3);                    //Imprime el Tablero
      printf("---+---+---\n");
      printf("\n %c | %c | %c\n",c4,c5,c6);
      printf("---+---+---\n");
      printf("\n %c | %c | %c\n\n",c7,c8,c9);
      if(jugador==1)                                        //Establece la marca del jugador
      {marca='X';}
      else
      {marca='O';}
      printf("En que Casilla Deseas Tirar Jugador %d:\n",jugador);
      fflush(stdin);
      scanf("%c",&tiro);
      if (tiro=='1' && c1=='1') {c1=marca;}                //Checa las Condiciones para poder tirar
      else if (tiro=='2' && c2=='2') {c2=marca;}
      else if (tiro=='3' && c3=='3') {c3=marca;}
      else if (tiro=='4' && c4=='4') {c4=marca;}
      else if (tiro=='5' && c5=='5') {c5=marca;}
      else if (tiro=='6' && c6=='6') {c6=marca;}
      else if (tiro=='7' && c7=='7') {c7=marca;}
      else if (tiro=='8' && c8=='8') {c8=marca;}
      else if (tiro=='9' && c9=='9') {c9=marca;}
      else {printf("Error! Movimiento No Valido\n"); error=2;}
      //Checa Si alguien gano
          if(c1=='X'||c1=='O')
      {
            if(c2==c1&&c3==c1)
             {ganar=1;}
            if(c4==c1&&c7==c1)
             {ganar=1;}
      }
      if(c5=='X'||c5=='O')
      {
           if (c1 == c5 && c9 == c5)
               {ganar=1;}
           if (c2 == c5 && c8 == c5)
               {ganar=1;}
           if (c4 == c5 && c6 == c5)
               {ganar=1;}
           if (c3 == c5 && c7 == c5)
               {ganar=1;}
      }
      if(c9=='X'||c9=='O')
      {
           if (c6 == c9 && c3 == c9)
               {ganar=1;}
           if (c7 == c9 && c8 == c9)
              {ganar=1;}
      }
    if (c1 != '1' && c2 != '2' && c3 != '3' &&
    c4 != '4' && c5 != '5' && c6 != '6' &&
    c7 != '7' && c8 != '8' && c9 != '9')
    {empate=1;}
      if (ganar==1||empate==1)
    {
      if (ganar==1)
      {
      printf("Jugador: %d Gana!\n\n",jugador);
      printf("\n %c | %c | %c\n",c1,c2,c3);                   
      printf("---+---+---\n");
      printf("\n %c | %c | %c\n",c4,c5,c6);
      printf("---+---+---\n");
      printf("\n %c | %c | %c\n\n",c7,c8,c9);
      }
      if (empate==1)
    {
      printf("Shit Nadie Gano!\n",jugador);
      printf("\n %c | %c | %c\n",c1,c2,c3);                   
      printf("---+---+---\n");
      printf("\n %c | %c | %c\n",c4,c5,c6);
      printf("---+---+---\n");
      printf("\n %c | %c | %c\n\n",c7,c8,c9);
    }
      printf("Deseas Jugar de Nuevo: Y/N ?\n");
      fflush(stdin);
      scanf("%c",&respuesta);
      if (respuesta=='y'||respuesta=='Y')
      {
          empate=0;
          jugador=2;
          ganar=0;
          c1='1';
          c2='2';
          c3='3';
          c4='4';
          c5='5';
          c6='6';
          c7='7';
          c8='8';
          c9='9';
      }
    }
      if(error==1)                                            //Si Hay un error jugador no cambia
      {
          if (jugador==1)
                {jugador=2;}
          else
                {jugador=1;}
      }
  }while(respuesta=='y'||respuesta=='Y');
}