Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Tris  by Phi - Tris.pas

Tris.pas

Caricato da: Phi
Scarica il programma completo

  1. Program Tris;
  2. {  $Id: gplprog.pt,v 1.2 2002/09/07 15:40:47 peter Exp 2010/02/14 13:11:28 peter Exp $
  3.     This file is part of Tris Application
  4.     Copyright (c) 2010 by Phi
  5.  
  6.     Gioco del Tris
  7.  
  8.     This program is distributed in the hope that it will be useful,
  9.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11.  
  12.  **********************************************************************}
  13. {**** Programma compilato con Free Pascal ****}
  14. {$R risorsetris.res}
  15. {$apptype gui}
  16.  
  17. uses windows, graph, winmouse, dos;
  18.  
  19. type
  20. arrstr = array of char;
  21. zona = (vuota, croce, cerchio);
  22. campo = array[1..3,1..3] of zona;
  23. time = record
  24.  h, min, sec, s100 : word;
  25. end;
  26. partita = record
  27.  punti : array[croce..cerchio]of byte;
  28.  match : campo;
  29.  turno, t1 : byte;
  30.  turni : Qword;
  31. end;
  32. bit8 = string[8];
  33. lettera = array[1..12] of array[1..12] of byte;
  34.  
  35. const
  36. G1 : integer = VGA;
  37. G2 : integer = 2;
  38. Salv = 'tris\salv.tris';
  39. Titolo : pchar = 'Tris   v1.2';
  40.  
  41. function tempo : time;
  42. begin
  43. gettime(tempo.h,tempo.min,tempo.sec,tempo.s100);
  44. end;
  45.  
  46. var
  47. icona : hicon;
  48. ch : lettera;
  49. I, J : longword;
  50. K, V, W, l1, l2, lz1, lz2 : byte;
  51. cont : longword;
  52. col, dim : byte;
  53. s : string[150];
  54. S8 : bit8;
  55.  
  56. function str (R : real; A, B : byte):string;
  57. begin
  58. system.str(R:A:B,str);
  59. end;
  60.  
  61. function strpc (S:string):Pchar;
  62. begin
  63. strpc := nil;
  64. strpc := @S;
  65. end;
  66.  
  67. Function ExtractIcon(hInst: HINST; lpszExeFileName :LPCSTR ; nIconIndex : UINT):HICON; stdcall;external 'shell32.dll' name 'ExtractIconA';
  68. function let(C:char;B:byte):bit8;external 'phi immgrd' name'lettera';
  69. procedure carica(C : byte);external 'phi immgrd' name 'carica';
  70. function letf(C : char) : lettera;external 'phi immgrd' name 'letteratipo';
  71.  
  72. procedure writeln(X,Y : word;S:string);
  73. begin
  74. for I := 1 to length(S) do
  75.  for J := 0 to 7 do begin
  76.   S8 := let(S[i],J);
  77.   for K := 1 to 8 do for V := 1 to dim  do for W := 1 to dim do
  78.    if S8[K]='1' then putpixel(X+(I-1)*9+j*dim-1+v,y+(8-K)*dim+w,col);
  79. end;
  80. end;
  81.  
  82. procedure linea(x,y,x2,y2:word;dim:byte);
  83. begin
  84. cont := 0;
  85. for cont := 0 to dim do begin
  86. line(x+cont,y,x2+cont,y2);
  87. line(x-cont,y,x2-cont,y2);
  88. line(x,y+cont,x2,y2+cont);
  89. line(x,y-cont,x2,y2-cont);
  90. end;
  91. end;
  92.  
  93. procedure rettsmus(const x1,y1,x2,y2 : word);
  94. begin
  95. line(x1,(y1+6),x1,(y2-6));
  96. line((x1+6),y1,(x2-6),y1);
  97. line(x2,(y1+6),x2,(y2-6));
  98. line((x1+6),y2,(x2-6),y2);
  99. arc((x2-6),(y1+6),0,90,6);
  100. arc((x1+6),(y1+6),90,180,6);
  101. arc((x1+6),(y2-6),180,270,6);
  102. arc((x2-6),(y2-6),270,360,6);
  103. end;
  104.  
  105. var
  106. win, chiudi, pieno : boolean;
  107. wins : zona;
  108. F : file of partita;
  109. M : partita;
  110. t : time;
  111. pc : byte;
  112. b, x, y : longint;
  113. R : searchRec;
  114.  
  115. procedure camp;
  116. begin
  117. setcolor(0);
  118. for I := 1 to 150 do begin
  119.  setrgbpalette(0,150-I,150-I,150-I);
  120.  rectangle(200-I,235-I,199+I,235+I);
  121. end;
  122. for I := 1 to 50 do begin
  123.  setrgbpalette(0,100-I,100-I,100-I);
  124.  rectangle(470-I,151-I,530+I,150+I);
  125. end;
  126. for I := 1 to 26 do begin
  127.  setrgbpalette(0,100-I,100-I,100-I);
  128.  rectangle(445-I,376-I,555+I,375+I);
  129. end;
  130. setcolor(15);
  131. linea(150,85,150,384,1);
  132. linea(250,85,250,384,1);
  133. linea(50,185,350,185,1);
  134. linea(50,285,350,285,1);
  135. linea(420,140,580,140,1);
  136. linea(500,101,500,201,1);
  137. dim := 2;
  138. col := 15;
  139. writeln(451,110,'X');
  140. writeln(533,110,'0');
  141. dim := 1;
  142. writeln(425,355,'E'' il turno di:');
  143. settextstyle(0,0,2);
  144. outtextxy(451,160,str(M.punti[croce],1,0));
  145. outtextxy(533,160,str(M.punti[cerchio],1,0));
  146. if M.turno = 1 then outtextxy(490,380,'X') else outtextxy(490,380,'0');
  147. setcolor(0);
  148. for I := 1 to 11 do begin
  149.  if (I mod 3) = 0 then setrgbpalette(0,0,0,0) else
  150.   setrgbpalette(0,128+(I div 10)*I*3,64+(I div 10)*I*3,0);
  151.  rectangle(50-I,85-I,349+I,384+I);
  152. end;
  153. for I := 1 to 10 do begin
  154.  if (I mod 3) = 0 then setrgbpalette(0,0,0,0) else
  155.   setrgbpalette(0,128+(I div 10)*I*3,64+(I div 8)*I*3,0);
  156.  rectangle(420-I,101-I,580+I,200+I);
  157. end;
  158. for I := 1 to 10 do begin
  159.  if (I mod 3) = 0 then setrgbpalette(0,0,0,0) else
  160.   setrgbpalette(0,128+(I div 10)*I*3,64+(I div 8)*I*3,0);
  161.  rectangle(420-I,350-I,580+I,400+I);
  162. end;
  163. setrgbpalette(0,0,0,0);
  164. setcolor(15);
  165. for I := 1 to 3 do for J := 1 to 3 do begin
  166. if M.match[I,J]=croce then begin
  167. linea(I*100-40,j*100-5,40+I*100,75+j*100,2);
  168. linea(I*100-40,75+j*100,40+I*100,j*100-5,2);
  169. end;
  170. if M.match[I,J]=cerchio then for cont := 1 to 5 do circle(I*100,35+j*100,35+cont)
  171. end;
  172. end;
  173.  
  174. procedure ntime;
  175. begin
  176. t := tempo;
  177. bar3d(554,464,636,478,3,true);
  178. bar(556,466,634,476);
  179. col := 4;dim := 1;
  180. writeln(560,467,concat(str(t.h,2,0),':',str(t.min,2,0),':',str(t.sec,2,0)));
  181. end;
  182.  
  183. procedure mouse (var x,y : longint);
  184. begin
  185. repeat
  186. getmousestate(x,y,b);
  187. sleep(15); ntime;
  188. until b = 0;
  189. repeat
  190. getmousestate(x,y,b);
  191. sleep(15); ntime;
  192. until b = 1;
  193. end;
  194.  
  195. procedure tasto;
  196. var O : byte;
  197. begin
  198. setcolor(4);
  199. O := 0;
  200. repeat
  201. mouse(x,y);
  202. if (y>9) and (y<30) and (x>=500) and(x<630) then begin chiudi := true; O := 1; end;
  203. if (y>39) and (y<60) and (x>=500) and(x<630) then halt(0);
  204. if (x>50) and (x < 350) and (y>85) and (y < 384) then if M.match[(x+50)div 100,(y+15) div 100] = vuota then begin
  205.  O := 1;
  206.  if M.turno = 1 then M.match[(x+50)div 100,(y+15) div 100]:= croce else M.match[(x+50)div 100,(y+15) div 100] := cerchio;
  207. end;
  208. if (x>555) and (x < 636) and (y>462) and (y < 478) then exec('orologio.exe','');
  209. until O = 1;
  210. end;
  211.  
  212. BEGIN
  213. randomize;col := 0; dim := 1; pc := 0;
  214. icona := extracticon(hinstance,'Tris.exe',0);
  215. graph.icon := icona;
  216. windowtitle := Titolo;
  217. carica(1);
  218. Assign(F,Salv);
  219. findfirst(salv,anyfile,R);
  220. if DosError= 0 then if MessageBox(parentWindow,'Vuoi caricare la partita salvata','Tris',MB_IconQuestion Or MB_YesNo)=IdYes then begin
  221.  reset(F); read(F,M);
  222.  close(F); pc := 1;
  223. end;
  224. if pc <> 1 then MessageBox(parentWindow,'Estrazione 1'#176' giocatore','Tris',MB_IconQuestion);
  225. initgraph(G1,G2,'');
  226. setcolor(0);
  227. for I := 1 to 558 do begin
  228.  setrgbpalette(0,200-(I*160)div 500,200-(I*160)div 600,210);
  229.  setcolor(0); line(1,I,I,1); line(1,1116-I,1116-I,1);
  230. end;
  231. icona:=extracticon(hinstance,'phi immgrd.dll',0);
  232. drawicon(windc,5,445,icona);
  233. drawicon(bitmapdc,5,445,icona);
  234. for I:= 0 to 4 do begin
  235.  ch:=letf(titolo[i]);
  236.  for l1 := 1 to 12 do for l2 := 1 to 12 do
  237.   if (ch[l1,l2]<>0)then for lz1 := 1 to 2 do for lz2 := 1 to 2 do begin
  238.    setrgbpalette(0,100+(ch[l1,l2]*150 div 255),20,20);
  239.    putpixel(160+(i-1)*20+l1*2+lz1-1,10+l2*2+lz2-1,0);
  240.   end;
  241. end;
  242. for I := 0 to 9 do begin
  243.  setrgbpalette(0,250-(I div 5)*I*20,250-(I div 5)*I*20,250-(I div 5)*I*20);
  244.  rettsmus(500-I,19-I,620+I,20+I);
  245. end;
  246. writeln(500,16,'SALVA E CHIUDI');
  247. for I := 0 to 9 do begin
  248.  setrgbpalette(0,250-(I div 5)*I*20,250-(I div 5)*I*20,250-(I div 5)*I*20);
  249.  rettsmus(500-I,49-I,620+I,50+I);
  250. end;
  251. writeln(510,46,'CHIUDI');
  252. camp;
  253. if (pc=1) then begin
  254.  if M.turno = 1 then S := 'Tocca al Giocatore "croce"' else S:= 'Tocca al Giocatore "cherchio"';
  255.  S[0]:=#32;
  256.  MessageBox(parentWindow,@S,'Tris',MB_IconQuestion Or MB_oK);
  257. end else begin
  258.  if (random(2) = 1) then M.turno := 1 else M.turno := 0;
  259.  M.t1 := M.turno;
  260.  M.turni := 0;
  261.  if M.turno = 1 then MessageBox(GraphWindow,'Inizia il Giocatore "croce"','Tris',MB_IconQuestion Or MB_oK)
  262.  else MessageBox(GraphWindow,'Inizia il Giocatore "cherchio"','Tris',MB_IconQuestion Or MB_oK);
  263. end;
  264. repeat
  265.  wins := vuota;
  266.  repeat
  267.   camp;
  268.   tasto;
  269.   camp;
  270.   if M.turno = 0 then inc(M.turno) else M.turno := 0;
  271.   for I := 1 to 3 do if ((M.match[I,1] = M.match[I,2]) and (M.match[I,1] = M.match[I,3])) then if M.match[I,1] <> vuota then wins := M.match[I,1];
  272.   for I := 1 to 3 do if ((M.match[1,I] = M.match[2,I]) and (M.match[1,I] = M.match[3,I])) then if M.match[1,I] <> vuota then wins := M.match[1,I];
  273.   if ((M.match[1,1] = M.match[2,2])and(M.match[2,2] = M.match[3,3])) or ((M.match[1,3] = M.match[2,2])and(M.match[2,2] = M.match[3,1])) then if M.match[2,2] <> vuota then wins := M.match[2,2];
  274.   pieno := true;
  275.   for I := 1 to 3 do for J := 1 to 3 do if (M.match[I,J] = vuota) then pieno := false;
  276.  until (wins<>vuota) or chiudi or pieno;
  277.  if wins <> vuota then inc(M.punti[wins]);
  278.  if not(chiudi) then begin
  279.   for I := 1 to 3 do for J := 1 to 3 do M.match[I,J] := vuota;
  280.   inc(M.turni);
  281.   beep(200,200);
  282.   if (M.turni mod 2) = 0 then M.turno := M.t1 else if M.t1 = 0 then M.turno:=1 else M.turno := 0;
  283.   camp;
  284.   if (M.punti[croce] = 5)and(M.punti[cerchio] = 5) then if M.turno = 1 then MessageBox(parentWindow,'Tocca al Giocatore "croce"','Tris',MB_IconQuestion Or MB_oK)
  285.   else MessageBox(parentWindow,'Tocca al Giocatore "cherchio"','Tris',MB_IconQuestion Or MB_oK);
  286.  end;
  287.  sleep(50);
  288.  for wins := croce to cerchio do if M.punti[wins] = 3 then begin
  289.   sleep(50);
  290.   setcolor(0);
  291.   for I := 1 to 150 do begin
  292.    setrgbpalette(0,200-I,200-I,250-I);
  293.    rectangle(200-I,235-I,199+I,235+I);
  294.   end;
  295.   setcolor(2);
  296.   settextstyle(0,0,4);
  297.   if wins = cerchio then outtextxy(90,140,'CERCHIO')
  298.   else outtextxy(115,140,'CROCE');
  299.   outtextxy(115,200,'VINCE');
  300.   outtextxy(130,260,'!!!!');
  301.   win := true;
  302.   beep(310,150);
  303.   sleep(20);
  304.   beep(310,150);
  305.   sleep(20);
  306.   sleep(150);
  307.   beep(210,105);
  308.   sleep(20);
  309.   beep(208,100);
  310.   beep(206,1);
  311.   sleep(3000);
  312.  end;
  313. until win or chiudi;
  314. if chiudi then begin
  315.  rewrite(F);
  316.  write(F,M);
  317.  close(F);
  318. end else if pc = 1 then erase(F);
  319. END.