milardovich

Tateti

Nov 23rd, 2011
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.69 KB | None | 0 0
  1. {
  2. **********************************************************************************************************************
  3. * Juego de Tateti V3.5 *
  4. * Desarrollado por Damián Cardona <[email protected]> y Sergio Milardovich <[email protected]> *
  5. * Nota: este programa usa caracteres de código ASCII extendidos, por lo que es posible que en algunas computadoras *
  6. * no se vea correctamente. Para más info vistar: http://es.wikipedia.org/wiki/ASCII_extendido *
  7. **********************************************************************************************************************
  8. }
  9. program tateti (input, output);
  10. uses
  11. Crt;
  12. type
  13. treg=record nom:string;
  14. pjug,pgan,pgcon:integer;
  15. est:boolean; end;
  16. tarchivo= file of treg;
  17. var
  18. N1,N2:string;
  19. u:real;
  20. rta:char;
  21. tat: array[1..3,1..3]of real;
  22. k1,k2,z,g,t,c,b,l,n,i,x,y,jug,j,f:integer;
  23. a:tarchivo;
  24. aux1, aux2:treg;
  25.  
  26. procedure inicio;
  27. begin
  28. assign (a,'C:\Users\milardo\est.dat');
  29. {$I-}
  30. reset(a);
  31. if ioresult = 2
  32. then rewrite (a);
  33. {$I+};
  34. end;
  35. procedure busca(var aux1,aux2:treg; n1,n2:string;var k1,k2:integer);
  36. var
  37. z:integer;
  38.  
  39. begin
  40. aux1.nom:='';aux2.nom:='';
  41. z:=0; k1:=0; k2:= 0;
  42. while (not eof(a)) and ((aux1.nom <> n1) or (aux2.nom <> n2)) do
  43. begin
  44. if n1<>aux1.nom
  45. then
  46. begin
  47. seek (a,z);
  48. read(a,aux1);
  49. if aux1.nom=n1
  50. then k1:=filepos(a)-1;
  51. end;
  52. if n2<>aux2.nom
  53. then
  54. begin
  55. seek (a,z);
  56. read (a,aux2);
  57. if aux2.nom=n2
  58. then k2:=filepos(a)-1
  59. end;
  60. z:=z+1;
  61. end;
  62. if k1=0
  63. then begin
  64. aux1.nom:=n1;
  65. aux1.pjug:=0;
  66. aux1.pgan:=0;
  67. aux1.est:=false;
  68. seek(a,filesize(a));
  69. write(a,aux1)
  70. end;
  71. if k2=0
  72. then begin
  73. aux2.nom:=n2;
  74. aux2.pjug:=0;
  75. aux2.pgan:=0;
  76. aux2.est:=false;
  77. seek(a,filesize(a));
  78. write(a,aux2)
  79. end;
  80.  
  81. end;
  82. begin
  83. rta:='n';
  84. repeat
  85. inicio;
  86. clrscr;
  87. randomize;
  88. repeat
  89. u:=Random;
  90. if u<0.5
  91. then
  92. jug:=1
  93. else
  94. if u>0.5
  95. then jug:=2;
  96. until u<>0.5;
  97. Textcolor(11);
  98. {empieza el titulo}
  99. gotoxy(15,4);
  100. write (chr(218),chr(196),chr(196),chr(196),chr(196),chr(196),chr(196),chr(196),chr(191));
  101. write (chr(218),chr(196),chr(196),chr(196),chr(196),chr(196),chr(196),chr(191));
  102. write (' ',chr(218),chr(196),chr(196),chr(196),chr(196),chr(196),chr(196),chr(196),chr(191));
  103. write (chr(218),chr(196),chr(196),chr(196),chr(196),chr(196),chr(191));
  104. write (' ',chr(218),chr(196),chr(196),chr(196),chr(196),chr(196),chr(196),chr(196),chr(191));
  105. writeln (chr(218),chr(196),chr(191));
  106. gotoxy(15,5);
  107. write (chr(192),chr(196),chr(196),chr(191),' ',chr(218),chr(196),chr(196),chr(217));
  108. write (chr(179),' ',chr(218),chr(196),chr(196),chr(191),' ',chr(179));
  109. write (' ',chr(192),chr(196),chr(196),chr(191),' ',chr(218),chr(196),chr(196),chr(217));
  110. write (chr(179),' ',chr(218),chr(196),chr(196),chr(196),chr(217),' ');
  111. write (chr(192),chr(196),chr(196),chr(191),' ',chr(218),chr(196),chr(196),chr(217));
  112. writeln (chr(192),chr(196),chr(217));
  113. gotoxy(15,6);
  114. write (' ',chr(179),' ',chr(179),' ');
  115. write (chr(179),' ',chr(192),chr(196),chr(196),chr(217),' ',chr(179));
  116. write (chr(218),chr(196),chr(196),chr(191),chr(179),' ',chr(179),' ');
  117. write (chr(179),' ',chr(192),chr(196),chr(191),' ');
  118. write (chr(218),chr(196),chr(196),chr(191),chr(179),' ',chr(179),' ');
  119. writeln (chr(218),chr(196),chr(191));
  120. gotoxy(15,7);
  121. write (' ',chr(179),' ',chr(179),' ');
  122. write (chr(179),' ',chr(218),chr(196),chr(196),chr(191),' ',chr(179));
  123. write (chr(192),chr(196),chr(196),chr(217),chr(179),' ',chr(179),' ');
  124. write (chr(179),' ',chr(218),chr(196),chr(217),' ');
  125. write (chr(192),chr(196),chr(196),chr(217),chr(179),' ',chr(179),' ');
  126. writeln (chr(179),' ',chr(179));
  127. gotoxy(15,8);
  128. write (' ',chr(179),' ',chr(179),' ');
  129. write (chr(179),' ',chr(179),' ',chr(179),' ',chr(179));
  130. write (' ',chr(179),' ',chr(179),' ');
  131. write (chr(179),' ',chr(192),chr(196),chr(196),chr(196),chr(191));
  132. write (' ',chr(179),' ',chr(179),' ');
  133. writeln (chr(179),' ',chr(179));
  134. gotoxy(15,9);
  135. write (' ',chr(192),chr(196),chr(217),' ');
  136. write (chr(192),chr(196),chr(217),' ',chr(192),chr(196),chr(217));
  137. write (' ',chr(192),chr(196),chr(217),' ');
  138. write (chr(192),chr(196),chr(196),chr(196),chr(196),chr(196),chr(217));
  139. write (' ',chr(192),chr(196),chr(217),' ');
  140. writeln (chr(192),chr(196),chr(217));
  141. {termina el titulo}
  142. if rta='n'
  143. then begin
  144. textcolor(15);
  145. writeln;
  146. write ('Ingrese el nombre del jugador Nro 1: ');
  147. textcolor(5); readln(N1);
  148. writeln (N1,' jugara con las X'); textcolor(15);
  149. write ('Ingrese el nombre del jugador Nro 2: ');
  150. textcolor(2); readln(N2);writeln (N2,' jugara con las O'); textcolor(15);
  151. delay(1500);
  152. clrscr;
  153. gotoxy(10,5);
  154. busca(aux1,aux2,n1,n2,k1,k2);
  155. delay(0);
  156. {empiezan INSTRUCCIONES}
  157. writeln('INSTRUCCIONES');
  158. writeln('el juego se juega por turnos');
  159. writeln(' empieza un jugador seleccionado al azar por el ordenador');
  160. writeln('para seleccionar donde colocar la ficha, ingresar:');
  161. writeln(' el numero de la casilla');
  162. writeln('el ojetivo del juego es lograr colocar 3 fichas en linea');
  163. writeln('ya sea vertical, horizontal o diagonal)');
  164. writeln('gana el jugador que coloque 3 fichas en linea');
  165. writeln('QUE SE DIVIERTAN');writeln;
  166. write ('presione enter');
  167. repeat until keypressed; readln;
  168. end
  169. else begin
  170. textcolor(5); writeln (N1,' jugara con las X');
  171. textcolor(2) ;writeln (N2,' jugara con las O'); textcolor(15);
  172. repeat until keypressed; readln;
  173. end;
  174. {Terminan INSTRUCCIONES}
  175. ClrScr;
  176. {Empieza GRILLA TATETI}
  177. for i:=6 to 36 do
  178. begin
  179. Gotoxy(3,i);
  180. write(chr(179));
  181. gotoxy (23,i);
  182. write (chr(179));
  183. gotoxy (43,i);
  184. write (chr(179));
  185. Gotoxy(64,i);
  186. write(chr(179));
  187. end;
  188. GotoXY(3,5);
  189. write(chr(218));
  190. for i:=1 to 60 do
  191. write(chr(196));
  192. write(chr(191));
  193. gotoxy (3,16);
  194. for i:= 1 to 61 do
  195. write (chr(196));
  196. write(chr(180));
  197. gotoxy (3,26);
  198. for i:= 1 to 61 do
  199. write (chr(196));
  200. write (chr(180));
  201. GotoXY(3,36);
  202. write(chr(192));
  203. for i:=1 to 60 do
  204. write(chr(196));
  205. {Empieza numeración de la grilla}
  206. write(chr(217));
  207. gotoxy(23,5); write (chr(194));
  208. gotoxy(43,5); write (chr(194));
  209. gotoxy(3,16); write (chr(195));
  210. gotoxy(3,26); write (chr(195));
  211. gotoxy(23,16); write (chr(197));
  212. gotoxy(23,26); write (chr(197));
  213. gotoxy(43,16); write (chr(197));
  214. gotoxy(43,26); write (chr(197));
  215. gotoxy(23,36); write (chr(193));
  216. gotoxy(43,36); write (chr(193));
  217. gotoxy(13,11);writeln(7);
  218. gotoxy(33,11);writeln(8);
  219. gotoxy(53,11);writeln(9);
  220. gotoxy(13,21);writeln(4);
  221. gotoxy(33,21);writeln(5);
  222. gotoxy(53,21);writeln(6);
  223. gotoxy(13,31);writeln(1);
  224. gotoxy(33,31);writeln(2);
  225. gotoxy(53,31);writeln(3);
  226. {termina la numeración de la grilla}
  227. {Termina GRILLA TATETI}
  228. {EMPIEZA PARTIDA-----------------------------------------------------------}
  229. g:=0;
  230. t:=0;
  231. l:=0;
  232. b:=0;
  233. t:=37;
  234. for n:= 1 to 3 do
  235. for j:=1 to 3 do
  236. tat[n,j]:=0;
  237. j:=0;
  238. repeat
  239. if jug=1
  240. then
  241. {JUGADOR 1------------------------------------------------}
  242. begin
  243. repeat
  244. repeat
  245. gotoxy (5,t);
  246. write('turno jugador '); textcolor(5);Write(aux1.nom);
  247. textcolor(15); write(', ingrese ubicacion: ');
  248. read (l);
  249. until ((l>=1)and(l<=9));
  250. case l of
  251. 7:begin y:=7; x:=9; f:=1; c:=1 end;
  252. 8:begin y:=7; x:=29; f:=1; c:=2 end;
  253. 9:begin y:=7; x:=49; f:=1; c:=3 end;
  254. 4:begin y:=17; x:=9; f:=2; c:=1 end;
  255. 5:begin y:=17; x:=29; f:=2; c:=2 end;
  256. 6:begin y:=17; x:=49; f:=2; c:=3 end;
  257. 1:begin y:=27; x:=9; f:=3; c:=1 end;
  258. 2:begin y:=27; x:=29; f:=3; c:=2 end;
  259. 3:begin y:=27; x:=49; f:=3; c:=3 end
  260. end;
  261. until tat[f,c]=0;
  262. textcolor(5);
  263. gotoxy(x,y);writeln('** **');y:=y+1;
  264. gotoxy(x,y);writeln(' ** ** ');y:=y+1;
  265. gotoxy(x,y);writeln(' **** ');y:=y+1;
  266. gotoxy(x,y);writeln(' ** ');y:=y+1;
  267. gotoxy(x,y);writeln(' **** ');y:=y+1;
  268. gotoxy(x,y);writeln(' ** ** ');y:=y+1;
  269. gotoxy(x,y);writeln('** **');
  270. tat[f,c]:=1;
  271. textcolor(15);
  272. j:=j+1; jug:=2; t:=t+1
  273. end
  274. else
  275. {JUGADOR 2--------------------------------------------------}
  276. begin
  277. repeat
  278. repeat
  279. gotoxy (5,t);
  280. write('turno jugador '); textcolor(2);Write(aux2.nom);
  281. textcolor(15); write(', ingrese ubicacion: ');
  282. read (l);
  283. until ((l>=1)and(l<=9));
  284. case l of
  285. 7:begin y:=8; x:=9; f:=1; c:=1 end;
  286. 8:begin y:=8; x:=29; f:=1; c:=2 end;
  287. 9:begin y:=8; x:=49; f:=1; c:=3 end;
  288. 4:begin y:=18; x:=9; f:=2; c:=1 end;
  289. 5:begin y:=18; x:=29; f:=2; c:=2 end;
  290. 6:begin y:=18; x:=49; f:=2; c:=3 end;
  291. 1:begin y:=28; x:=9; f:=3; c:=1 end;
  292. 2:begin y:=28; x:=29; f:=3; c:=2 end;
  293. 3:begin y:=28; x:=49; f:=3; c:=3 end
  294. end;
  295. until tat[f,c]=0;
  296. textcolor(2);
  297. gotoxy(x,y); writeln(' *** '); y:=y+1;
  298. gotoxy(x,y); writeln(' ** ** '); y:=y+1;
  299. gotoxy(x,y); writeln('** **'); y:=y+1;
  300. gotoxy(x,y); writeln('** **'); y:=y+1;
  301. gotoxy(x,y); writeln(' ** ** '); y:=y+1;
  302. gotoxy(x,y); writeln(' *** ');
  303. tat[f,c]:=2;
  304. textcolor(15);
  305. j:=j+1;jug:=1 ; t:=t+1
  306. end;
  307. {VERIFICAR FINAL DE JPARTIDA-------------------------------------------------------}
  308. for g:=1to 2 do
  309. begin
  310. for i:= 1 to 3 do
  311. begin
  312. if ((tat[i,1]=tat[i,2])and(tat[i,1]=tat[i,3])and (tat[i,1]=g))
  313. then b:= g;
  314. if ((tat[1,i]=tat[2,i])and(tat[1,i]=tat[3,i])and (tat[1,i]=g))
  315. then b:= g
  316. end;
  317. if ((tat[1,1]=tat[2,2])and(tat[1,1]=tat[3,3])and (tat[1,1]=g))
  318. then b:= g;
  319. if ((tat[3,1]=tat[2,2])and(tat[3,1]=tat[1,3])and (tat[3,1]=g))
  320. then b:= g
  321. end;
  322. until (b<>0)or(j=9);
  323. clrscr;
  324. gotoxy (30,15);
  325. case b of
  326. 0: begin
  327. writeln ('EMPATE');
  328. aux1.pjug:=aux1.pjug+1;
  329. aux1.pgcon:=0;
  330. aux2.pjug:=aux2.pjug+1;
  331. aux2.pgcon:=0
  332. end;
  333. 1: begin
  334. write ('el ganador es ');
  335. textcolor(5); writeln (aux1.nom);
  336. aux1.pjug:=aux1.pjug+1;
  337. aux1.pgcon:=aux1.pgcon+1;
  338. aux2.pjug:=aux2.pjug+1;
  339. aux2.pgcon:=0
  340. end;
  341. 2: begin
  342. write ('el ganador es ');
  343. textcolor(2); writeln (n2);
  344. aux1.pjug:=aux1.pjug+1;
  345. aux1.pgcon:=0;
  346. aux2.pjug:=aux2.pjug+1;
  347. aux2.pgcon:=aux2.pgcon+1
  348. end
  349. end;
  350. seek(a,k1); write(a,aux1);
  351. seek(a,k2); write(a,aux2);
  352. textcolor(15); writeln; writeln; writeln;
  353. repeat write ('Desea jugar otra vez? S/N: '); readln; readln(rta);
  354. until (rta='n') or (rta='N')or (rta='s') or (rta='S');
  355. close(a);
  356. until (rta='n') or (rta='N');
  357. reset(a);
  358. writeln('NOMBRE':10,'PJUG':7,'PGAN':7,'PROM':7,'V SEG':7);
  359. z:=1;
  360. while (not eof (a)) do
  361. begin
  362. read (a,aux1);
  363. write (z:2, aux1.nom, aux1.pjug, aux1.pgan, (aux1.pgan/aux1.pjug)*100:5:2,'p',aux1.pgcon);
  364. z:=z+1
  365. end;
  366. readln;
  367. close(a);
  368. end.
  369.  
  370.  
Advertisement
Add Comment
Please, Sign In to add comment