Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program statki;
- uses allegro, crt, dos;
- type
- tablica=ARRAY[-1..11,-1..11] of integer;
- const
- ScreenWidth= 1200;
- ScreenHeight= 720;
- var
- tab1, tab2, tab1_c, tab2_c : tablica;
- litery : ARRAY [1..20] of string;
- mx, my, mb, tryb, komp, _1, _2, typ : integer;
- procedure inicjalizuj();
- var
- i, j: integer;
- begin
- al_init;
- al_install_keyboard;
- al_install_mouse;
- al_set_color_depth(32);
- al_set_gfx_mode(Al_GFX_AUTODETECT_WINDOWED,ScreenWidth,ScreenHeight,0,0);
- al_show_mouse( al_screen );
- al_unscare_mouse();
- for i:=0 to 11 do
- begin
- for j:=0 to 11 do
- begin
- tab1[i][j]:=0;
- tab2[i][j]:=0;
- tab1_c[i][j]:=0;
- tab2_c[i][j]:=0;
- end;
- end;
- litery[1]:='A';
- litery[2]:='B';
- litery[3]:='C';
- litery[4]:='D';
- litery[5]:='E';
- litery[6]:='F';
- litery[7]:='G';
- litery[8]:='H';
- litery[9]:='I';
- litery[10]:='J';
- litery[11]:='1';
- litery[12]:='2';
- litery[13]:='3';
- litery[14]:='4';
- litery[15]:='5';
- litery[16]:='6';
- litery[17]:='7';
- litery[18]:='8';
- litery[19]:='9';
- litery[20]:='10';
- komp:=0;
- end;
- procedure pozycja_myszki();
- begin
- if ((mx <> al_mouse_x) AND (my <> al_mouse_y) AND (mb <> al_mouse_b)) then
- begin
- mx:=al_mouse_x;
- my:=al_mouse_y;
- mb:=al_mouse_b;
- end;
- end;
- procedure clear ();
- begin
- al_clear_to_color( al_screen, al_makecol( 0, 0, 0 ) );
- end;
- procedure wyswietl_c (var tab : tablica; var tab_c :tablica);
- var
- i, j : integer;
- begin
- for i:=1 to 10 do
- begin
- for j:=1 to 10 do
- begin
- if (tab[i][j]>0) then
- begin
- al_rectfill( al_screen, (j-1)*30+435, (i-1)*30+65, j*30+430, i*30+60, al_makecol( 200, 30, 30 ) );
- al_rect( al_screen, (j-1)*30+435, (i-1)*30+65, j*30+430, i*30+60, al_makecol( 200, 30, 30 ) );
- end;
- if (tab[i][j]=-1) then
- begin
- al_rectfill( al_screen, (j-1)*30+435, (i-1)*30+65, j*30+430, i*30+60, al_makecol( 0, 0, 0 ) );
- al_rect( al_screen, (j-1)*30+435, (i-1)*30+65, j*30+430, i*30+60, al_makecol( 200, 200, 200 ) );
- end;
- if ((tab[i][j]=-10) OR (tab[i][j]=-11) OR (tab[i][j]=-9)) then
- begin
- al_rectfill( al_screen, (j-1)*30+435, (i-1)*30+65, j*30+430, i*30+60, al_makecol( 0, 0, 0 ) );
- al_rect( al_screen, (j-1)*30+435, (i-1)*30+65, j*30+430, i*30+60, al_makecol( 200, 200, 200 ) );
- al_line( al_screen, (j-1)*30+435, (i-1)*30+65, j*30+430, i*30+60, al_makecol( 200, 200, 200 ) );
- al_line( al_screen, (j-1)*30+435, (i-1)*30+90, j*30+430, i*30+35, al_makecol( 200, 200, 200 ) );
- end;
- end;
- end;
- for i:=1 to 10 do
- begin
- for j:=1 to 10 do
- begin
- if (tab_c[i][j]=-1) then
- begin
- al_rectfill( al_screen, (j-1)*30+35, (i-1)*30+65, j*30+30, i*30+60, al_makecol( 0, 0, 0 ) );
- al_rect( al_screen, (j-1)*30+35, (i-1)*30+65, j*30+30, i*30+60, al_makecol( 200, 200, 200 ) );
- end;
- if (tab_c[i][j]=-2) then
- begin
- al_rectfill( al_screen, (j-1)*30+35, (i-1)*30+65, j*30+30, i*30+60, al_makecol( 200, 200, 200 ) );
- al_rect( al_screen, (j-1)*30+35, (i-1)*30+65, j*30+30, i*30+60, al_makecol( 200, 200, 200 ) );
- end;
- if (tab_c[i][j]=-3) then
- begin
- al_rectfill( al_screen, (j-1)*30+35, (i-1)*30+65, j*30+30, i*30+60, al_makecol( 255, 255, 0 ) );
- al_rect( al_screen, (j-1)*30+35, (i-1)*30+65, j*30+30, i*30+60, al_makecol( 200, 200, 200 ) );
- end;
- end;
- end;
- end;
- procedure wyswietl (var tab : tablica; var tab_c:tablica; gracz : string; parametr : integer);
- var
- i, j : integer;
- begin
- al_textout_ex(al_screen, al_font,gracz, 350, 10, al_makecol(200,200,200), -1);
- for i:=1 to 10 do
- begin
- for j:=1 to 10 do
- begin
- if (tab_c[i][j]=0) then
- begin
- al_rectfill( al_screen, (j-1)*30+35, (i-1)*30+65, j*30+30, i*30+60, al_makecol( 128, 30, 30 ) );
- al_rect( al_screen, (j-1)*30+35, (i-1)*30+65, j*30+30, i*30+60, al_makecol( 128, 30, 30 ) );
- end;
- if (tab_c[i][j]=-1) then
- begin
- al_rectfill( al_screen, (j-1)*30+35, (i-1)*30+65, j*30+30, i*30+60, al_makecol( 0, 0, 0 ) );
- al_rect( al_screen, (j-1)*30+35, (i-1)*30+65, j*30+30, i*30+60, al_makecol( 200, 200, 200 ) );
- end;
- if (tab_c[i][j]=-2) then
- begin
- al_rectfill( al_screen, (j-1)*30+35, (i-1)*30+65, j*30+30, i*30+60, al_makecol( 200, 200, 200 ) );
- al_rect( al_screen, (j-1)*30+35, (i-1)*30+65, j*30+30, i*30+60, al_makecol( 200, 200, 200 ) );
- end;
- if (tab_c[i][j]=-3) then
- begin
- al_rectfill( al_screen, (j-1)*30+35, (i-1)*30+65, j*30+30, i*30+60, al_makecol( 255, 255, 0 ) );
- al_rect( al_screen, (j-1)*30+35, (i-1)*30+65, j*30+30, i*30+60, al_makecol( 200, 200, 200 ) );
- end;
- end;
- end;
- for i:=1 to 10 do
- begin
- for j:=1 to 10 do
- begin
- if (tab[i][j]=0) then
- begin
- al_rectfill( al_screen, (j-1)*30+435, (i-1)*30+65, j*30+430, i*30+60, al_makecol( 128, 30, 30 ) );
- al_rect( al_screen, (j-1)*30+435, (i-1)*30+65, j*30+430, i*30+60, al_makecol( 128, 30, 30 ) );
- end;
- if (tab[i][j]>0) then
- begin
- al_rectfill( al_screen, (j-1)*30+435, (i-1)*30+65, j*30+430, i*30+60, al_makecol( 200, 30, 30 ) );
- al_rect( al_screen, (j-1)*30+435, (i-1)*30+65, j*30+430, i*30+60, al_makecol( 200, 30, 30 ) );
- end;
- if (tab[i][j]=-1) then
- begin
- al_rectfill( al_screen, (j-1)*30+435, (i-1)*30+65, j*30+430, i*30+60, al_makecol( 0, 0, 0 ) );
- al_rect( al_screen, (j-1)*30+435, (i-1)*30+65, j*30+430, i*30+60, al_makecol( 200, 200, 200 ) );
- end;
- if ((tab[i][j]=-10) OR (tab[i][j]=-11) OR (tab[i][j]=-9)) then
- begin
- al_rectfill( al_screen, (j-1)*30+435, (i-1)*30+65, j*30+430, i*30+60, al_makecol( 0, 0, 0 ) );
- al_rect( al_screen, (j-1)*30+435, (i-1)*30+65, j*30+430, i*30+60, al_makecol( 200, 200, 200 ) );
- al_line( al_screen, (j-1)*30+435, (i-1)*30+65, j*30+430, i*30+60, al_makecol( 200, 200, 200 ) );
- al_line( al_screen, (j-1)*30+435, (i-1)*30+90, j*30+430, i*30+35, al_makecol( 200, 200, 200 ) );
- end;
- end;
- end;
- al_textout_ex(al_screen, al_font,'Twoje statki', 540, 30, al_makecol(200,200,200), -1);
- al_textout_ex(al_screen, al_font,'Twoje strzaly', 130, 30, al_makecol(200,200,200), -1);
- for i:=1 to 10 do
- begin
- al_textout_ex(al_screen, al_font,litery[i], (i-1)*30+44, 50, al_makecol(200,200,200), -1);
- al_textout_ex(al_screen, al_font,litery[i], (i-1)*30+444, 50, al_makecol(200,200,200), -1);
- end;
- for i:=11 to 20 do
- begin
- al_textout_ex(al_screen, al_font, litery[i], 15, (i-11)*30+73, al_makecol(200,200,200), -1);
- al_textout_ex(al_screen, al_font, litery[i], 415, (i-11)*30+73, al_makecol(200,200,200), -1);
- end;
- if (parametr>=-1) then
- begin
- al_textout_ex(al_screen, al_font,'Stworz:', 750, 50, al_makecol(200,200,200), -1);
- al_textout_ex(al_screen, al_font,'1x czteromasztowiec', 750, 70, al_makecol(200,200,200), -1);
- al_textout_ex(al_screen, al_font,'2x trojmasztowiec', 750, 90, al_makecol(200,200,200), -1);
- al_textout_ex(al_screen, al_font,'3x dwumasztowiec', 750, 110, al_makecol(200,200,200), -1);
- al_textout_ex(al_screen, al_font,'4x jednomasztowiec', 750, 130, al_makecol(200,200,200), -1);
- end;
- if (parametr>=0) then
- begin
- al_line( al_screen, 750, (parametr*20)+75, 900, (parametr*20)+75, al_makecol( 200, 200, 200 ) );
- end;
- if (parametr=-2) then
- begin
- al_textout_ex(al_screen, al_font,'Legenda:', 750, 70, al_makecol(200,200,200), -1);
- al_rectfill( al_screen, 750, 90 , 780, 120, al_makecol( 0, 0, 0 ) );
- al_rect( al_screen, 750, 90, 780, 120, al_makecol( 200, 200, 200 ) );
- al_textout_ex(al_screen, al_font,'-pudlo', 790, 105, al_makecol(200,200,200), -1);
- al_rectfill( al_screen, 750, 130 , 780, 160, al_makecol( 200, 200, 200 ) );
- al_rect( al_screen, 750, 130, 780, 160, al_makecol( 200, 200, 200 ) );
- al_textout_ex(al_screen, al_font,'-trafiony, niezatopiony', 790, 145, al_makecol(200,200,200), -1);
- al_rectfill( al_screen, 750, 170 , 780, 200, al_makecol( 255, 255 , 0 ) );
- al_rect( al_screen, 750, 170, 780, 200, al_makecol( 200, 200, 200 ) );
- al_textout_ex(al_screen, al_font,'-trafiony, zatopiony', 790, 185, al_makecol(200,200,200), -1);
- al_rectfill( al_screen, 750, 210 , 780, 240, al_makecol( 200, 30 , 30 ) );
- al_rect( al_screen, 750, 210, 780, 240, al_makecol( 200, 200, 200 ) );
- al_textout_ex(al_screen, al_font,'-twoj statek', 790, 225, al_makecol(200,200,200), -1);
- al_rectfill( al_screen, 750, 250, 780, 280, al_makecol( 0, 0, 0 ) );
- al_rect( al_screen, 750, 250, 780, 280, al_makecol( 200, 200, 200 ) );
- al_line( al_screen, 750, 250, 780, 280, al_makecol( 200, 200, 200 ) );
- al_line( al_screen, 750, 280, 780, 250, al_makecol( 200, 200, 200 ) );
- al_textout_ex(al_screen, al_font,'-strzaly przeciwnika', 790, 265, al_makecol(200,200,200), -1);
- end;
- al_rectfill( al_screen, 10, 660 , 100, 710, al_makecol( 0, 0, 0 ) );
- al_rect( al_screen, 10, 660, 100, 710, al_makecol( 200, 200, 200 ) );
- al_textout_ex(al_screen, al_font,'Wyjdz', 35, 685, al_makecol(200,200,200), -1);
- end;
- function warunek_tworzenia_1(var tab : tablica; d : integer) : boolean;
- begin
- if (((tab[((my-65)DIV 30)+2][((mx-435)DIV 30)]=d) OR (tab[((my-65)DIV 30)+2][((mx-435)DIV 30)]=0)) AND ((tab[((my-65)DIV 30)+2][((mx-435)DIV 30)+1]=d) OR (tab[((my-65)DIV 30)+2][((mx-435)DIV 30)+1]=0)) AND ((tab[((my-65)DIV 30)+2][((mx-435)DIV 30)+2]=d) OR (tab[((my-65)DIV 30)+2][((mx-435)DIV 30)+2]=0)) AND ((tab[((my-65)DIV 30)+1][((mx-435)DIV 30)+2]=d) OR (tab[((my-65)DIV 30)+1][((mx-435)DIV 30)+2]=0)) AND ((tab[((my-65)DIV 30)+1][((mx-435)DIV 30)]=d) OR (tab[((my-65)DIV 30)+1][((mx-435)DIV 30)]=0)) AND ((tab[((my-65)DIV 30)][((mx-435)DIV 30)]=d) OR (tab[((my-65)DIV 30)][((mx-435)DIV 30)]=0)) AND ((tab[((my-65)DIV 30)][((mx-435)DIV 30)+1]=d) OR (tab[((my-65)DIV 30)][((mx-435)DIV 30)+1]=0)) AND ((tab[((my-65)DIV 30)][((mx-435)DIV 30)+2]=d)OR (tab[((my-65)DIV 30)][((mx-435)DIV 30)+2]=0))AND (tab[((my-65)DIV 30)+1][((mx-435)DIV 30)+1]=0))then
- warunek_tworzenia_1:=true
- else
- warunek_tworzenia_1:=false;
- end;
- function warunek_tworzenia_2 (var tab:tablica; i : integer) : boolean;
- begin
- if (((tab[((my-65)DIV 30)+2][((mx-435)DIV 30)+1]=i) OR (tab[((my-65)DIV 30)+1][((mx-435)DIV 30)+2]=i) OR (tab[((my-65)DIV 30)+1][((mx-435)DIV 30)]=i) OR (tab[((my-65)DIV 30)][((mx-435)DIV 30)+1]=i))AND (tab[((my-65)DIV 30)+1][((mx-435)DIV 30)+1]=0)) then
- warunek_tworzenia_2:=true
- else
- warunek_tworzenia_2:=false;
- end;
- procedure koniec(wygrany : string);
- begin
- al_textout_centre_ex(al_screen,al_font,'KONIEC GRY', ScreenWidth div 2, ScreenHeight div 3, al_makecol(200,200,200), -1);
- al_textout_centre_ex(al_screen,al_font,'Wygral:', ScreenWidth div 2-30, ScreenHeight div 3+15, al_makecol(200,200,200), -1);
- al_textout_centre_ex(al_screen,al_font,wygrany, (ScreenWidth div 2)+42, ScreenHeight div 3+15, al_makecol(200,200,200), -1);
- al_readkey;
- halt;
- end;
- function przekroczenie_1( a: integer; b: integer; c: integer; d: integer):boolean;
- begin
- if ((mb=1) AND (((mx<a) OR (mx>b)) OR ((my<c) OR (my>d)))) then
- begin
- al_textout_ex(al_screen, al_font, 'Jestes poza plansza', 310, 450, al_makecol(200,200,200), -1);
- przekroczenie_1 :=true;
- if ((mx>10) AND (mx<100) AND(my>660) AND (my<710)) then
- begin
- al_rectfill( al_screen, 10, 660 , 100, 710, al_makecol( 200, 200, 200 ) );
- al_rect( al_screen, 10, 660, 100, 710, al_makecol( 200, 200, 200 ) );
- al_textout_ex(al_screen, al_font,'Wyjdz', 35, 685, al_makecol(0,0,0), -1);
- delay(500);
- clear();
- koniec('pies');
- end;
- end
- else
- begin
- al_textout_ex(al_screen, al_font, 'Jestes poza plansza', 310, 450, al_makecol(0,0,0), -1);
- przekroczenie_1:=false;
- end;
- end;
- procedure tworzenie_4(var tab : tablica;var tab_c :tablica; gracz : string);
- var
- m : integer;
- begin
- m:=0;
- al_textout_ex(al_screen, al_font, 'Stworz 4 masztowiec', 310, 400, al_makecol(200,200,200), -1);
- wyswietl(tab,tab_c, gracz, -1);
- repeat
- begin
- mb:=0;
- repeat
- pozycja_myszki();
- przekroczenie_1(435,750,65,360);
- until ((mb=1)AND (przekroczenie_1(435,750,65,360)=false));
- if (m=0) then
- begin
- tab[((my-65)DIV 30)+1][((mx-435)DIV 30)+1]:=10;
- m:=m+1;
- al_rectfill( al_screen, 240, 415 , 1000, 440, al_makecol( 0, 0, 0 ) );
- end
- else
- begin
- if (warunek_tworzenia_2(tab, 10)=true) then
- begin
- tab[((my-65)DIV 30)+1][((mx-435)DIV 30)+1]:=10;
- m:=m+1;
- al_rectfill( al_screen, 240, 415 , 1000, 440, al_makecol( 0, 0, 0 ) );
- end
- else if (warunek_tworzenia_2(tab, 10)=false) then
- begin
- al_textout_ex(al_screen, al_font, 'Statek musi byc polaczony', 250, 420, al_makecol(200,200,200), -1);
- end;
- end;
- end;
- wyswietl_c(tab, tab_c);
- until (m=4);
- wyswietl_c(tab, tab_c);
- end;
- procedure tworzenie_3(var tab: tablica; var tab_c :tablica; gracz : string);
- var
- m, d, p : integer;
- begin
- al_textout_ex(al_screen, al_font, 'Stworz 4 masztowiec', 310, 400, al_makecol(0,0,0), -1);
- for d:=8 to 9 do
- begin
- wyswietl(tab,tab_c, gracz,0);
- m:=0;
- al_textout_ex(al_screen, al_font, 'Stworz 3 masztowiec', 310, 400, al_makecol(200,200,200), -1);
- wyswietl_c(tab, tab_c);
- repeat
- begin
- mb:=0;
- repeat
- pozycja_myszki();
- przekroczenie_1(435,750,65,360);
- until ((mb=1) AND (przekroczenie_1(435,750,65,360)=false));
- if (warunek_tworzenia_1(tab, d)=true) then
- begin
- if (m>=1) then
- begin
- if (warunek_tworzenia_2(tab,d)=true) then
- begin
- tab[((my-65)DIV 30)+1][((mx-435)DIV 30)+1]:=d;
- m:=m+1;
- p:=1;
- end
- else
- begin
- al_textout_ex(al_screen, al_font, 'Statek musi byc polaczony', 250, 420, al_makecol(200,200,200), -1);
- end;
- end
- else
- begin
- tab[((my-65)DIV 30)+1][((mx-435)DIV 30)+1]:=d;
- m:=m+1;
- p:=1;
- end;
- al_rectfill( al_screen, 240, 415 , 1000, 440, al_makecol( 0, 0, 0 ) );
- end
- else if(warunek_tworzenia_1(tab, d)=false) then
- begin
- al_textout_ex(al_screen, al_font, 'Nowo utworzony statek nie moze dotykac statku wczesniej utworzonego', 310, 420, al_makecol(200,200,200), -1);
- p:=1;
- end;
- if(p=0) then
- begin
- if (warunek_tworzenia_2(tab, d)=true) then
- begin
- tab[((my-65)DIV 30)+1][((mx-435)DIV 30)+1]:=d;
- al_rectfill( al_screen, 240, 415 , 1000, 440, al_makecol( 0, 0, 0 ) );
- m:=m+1;
- end
- else if(warunek_tworzenia_2(tab, d)=false) then
- begin
- al_textout_ex(al_screen, al_font, 'Statek musi byc polaczony', 250, 420, al_makecol(200,200,200), -1);
- end;
- end;
- wyswietl_c(tab,tab_c);
- end;
- p:=0;
- until (m=3);
- wyswietl_c(tab,tab_c);
- end;
- end;
- procedure tworzenie_2(var tab:tablica; var tab_c : tablica; gracz:string);
- var
- m, p, b : integer;
- begin
- al_textout_ex(al_screen, al_font, 'Stworz 3 masztowiec', 310, 400, al_makecol(0,0,0), -1);
- for b:=5 to 7 do
- begin
- wyswietl(tab,tab_c, gracz,1);
- m:=0;
- al_textout_ex(al_screen, al_font, 'Stworz 2 masztowiec', 310, 400, al_makecol(200,200,200), -1);
- wyswietl_c(tab, tab_c);
- repeat
- begin
- mb:=0;
- repeat
- pozycja_myszki();
- przekroczenie_1(435,750,65,360);
- until ((mb=1)AND(przekroczenie_1(435,750,65,360)=false));
- if(warunek_tworzenia_1(tab, b)=true) then
- begin
- if (m>0) then
- begin
- if (warunek_tworzenia_2(tab,b)=true) then
- begin
- tab[((my-65)DIV 30)+1][((mx-435)DIV 30)+1]:=b;
- end
- else if (warunek_tworzenia_2(tab,b)=false) then
- begin
- al_textout_ex(al_screen, al_font, 'Statek musi byc polaczony', 250, 420, al_makecol(200,200,200), -1);
- end;
- end
- else
- begin
- tab[((my-65)DIV 30)+1][((mx-435)DIV 30)+1]:=b;
- end;
- al_rectfill( al_screen, 240, 415 , 1000, 440, al_makecol( 0, 0, 0 ) );
- m:=m+1;
- p:=1;
- end
- else if(warunek_tworzenia_1(tab, b)=false) then
- begin
- al_textout_ex(al_screen, al_font, 'Nowo utworzony statek nie moze dotykac statku wczesniej utworzonego', 310, 420, al_makecol(200,200,200), -1);
- p:=1;
- end;
- if (p=0) then
- begin
- if(warunek_tworzenia_2(tab, b)=true)then
- begin
- tab[((my-65)DIV 30)+1][((mx-435)DIV 30)+1]:=b;
- al_rectfill( al_screen, 240, 415 , 1000, 440, al_makecol( 0, 0, 0 ) );
- m:=m+1;
- p:=1;
- end
- else if (warunek_tworzenia_2(tab, b)=false) then
- begin
- al_textout_ex(al_screen, al_font, 'Statek musi byc polaczony', 250, 420, al_makecol(200,200,200), -1);
- end;
- end;
- wyswietl_c(tab, tab_c);
- end;
- p:=1;
- until (m=2);
- wyswietl_c(tab, tab_c);
- end;
- end;
- procedure tworzenie_1(var tab:tablica; var tab_c : tablica; gracz:string);
- var
- m, a : integer;
- begin
- al_textout_ex(al_screen, al_font, 'Stworz 2 masztowiec', 310, 400, al_makecol(0,0,0), -1);
- for a:=1 to 4 do
- begin
- wyswietl(tab,tab_c, gracz,2);
- m:=0;
- al_textout_ex(al_screen, al_font, 'Stworz 1 masztowiec', 310, 400, al_makecol(200,200,200), -1);
- wyswietl_c(tab, tab_c);
- repeat
- begin
- mb:=0;
- repeat
- pozycja_myszki();
- przekroczenie_1(435,750,65,360);
- until ((mb=1) AND (przekroczenie_1(435,750,65,360)=false));
- if((warunek_tworzenia_1(tab,a)=true) AND (tab[((my-65)DIV 30)+1][((mx-435)DIV 30)+1]=0))then
- begin
- tab[((my-65)DIV 30)+1][((mx-435)DIV 30)+1]:=a;
- al_rectfill( al_screen, 240, 415 , 1000, 440, al_makecol( 0, 0, 0 ) );
- m:=m+1;
- end
- else if(warunek_tworzenia_1(tab,a)=false) then
- begin
- al_textout_ex(al_screen, al_font, 'Nowo utworzony statek nie moze dotykac statku wczesniej utworzonego', 310, 420, al_makecol(200,200,200), -1);
- end
- else if (tab[((my-65)DIV 30)+1][((mx-435)DIV 30)+1]<>0) then
- begin
- al_textout_ex(al_screen, al_font, 'Tu jest statek', 310, 420, al_makecol(200,200,200), -1);
- end
- end;
- wyswietl_c(tab, tab_c);
- until (m=1);
- wyswietl_c(tab, tab_c);
- end;
- wyswietl_c(tab, tab_c);
- delay(1000);
- end;
- procedure tworzenie_4_k;
- var
- typ_statku, x, y, stw : integer;
- begin
- stw:=0;
- repeat
- randomize();
- typ_statku:=random(13)+1;
- if(typ_statku=1) then
- begin
- y:=random(8)+1;
- x:=random(9)+2;
- tab2[y][x]:=10;
- tab2[y+1][x]:=10;
- tab2[y+2][x]:=10;
- tab2[y+2][x-1]:=10;
- break;
- end;
- if(typ_statku=2) then
- begin
- y:=random(8)+1;
- x:=random(9)+1;
- tab2[y][x]:=10;
- tab2[y+1][x]:=10;
- tab2[y+2][x]:=10;
- tab2[y+2][x+1]:=10;
- break;
- end;
- if(typ_statku=3) then
- begin
- y:=random(7)+1;
- x:=random(10)+1;
- tab2[y][x]:=10;
- tab2[y+1][x]:=10;
- tab2[y+2][x]:=10;
- tab2[y+3][x]:=10;
- break;
- end;
- if(typ_statku=4) then
- begin
- y:=random(10)+1;
- x:=random(7)+1;
- tab2[y][x]:=10;
- tab2[y][x+1]:=10;
- tab2[y][x+2]:=10;
- tab2[y][x+3]:=10;
- break;
- end;
- if(typ_statku=5) then
- begin
- y:=random(9)+1;
- x:=random(8)+1;
- tab2[y][x]:=10;
- tab2[y][x+1]:=10;
- tab2[y][x+2]:=10;
- tab2[y+1][x+1]:=10;
- break;
- end;
- if(typ_statku=6) then
- begin
- y:=random(9)+2;
- x:=random(8)+1;
- tab2[y][x]:=10;
- tab2[y][x+1]:=10;
- tab2[y][x+2]:=10;
- tab2[y-1][x+2]:=10;
- break;
- end;
- if(typ_statku=7) then
- begin
- y:=random(9)+2;
- x:=random(8)+1;
- tab2[y][x]:=10;
- tab2[y][x+1]:=10;
- tab2[y][x+2]:=10;
- tab2[y-1][x]:=10;
- break;
- end;
- if(typ_statku=8) then
- begin
- y:=random(9)+2;
- x:=random(8)+1;
- tab2[y][x]:=10;
- tab2[y][x+1]:=10;
- tab2[y][x+2]:=10;
- tab2[y-1][x+1]:=10;
- break;
- end;
- if(typ_statku=9) then
- begin
- y:=random(9)+1;
- x:=random(8)+1;
- tab2[y][x]:=10;
- tab2[y+1][x]:=10;
- tab2[y][x+1]:=10;
- tab2[y][x+2]:=10;
- break;
- end;
- if(typ_statku=10) then
- begin
- y:=random(9)+1;
- x:=random(8)+1;
- tab2[y][x]:=10;
- tab2[y][x+1]:=10;
- tab2[y][x+2]:=10;
- tab2[y+1][x+2]:=10;
- break;
- end;
- if(typ_statku=11) then
- begin
- y:=random(9)+1;
- x:=random(9)+1;
- tab2[y][x]:=10;
- tab2[y+1][x+1]:=10;
- tab2[y][x+1]:=10;
- tab2[y+1][x]:=10;
- break;
- end;
- if(typ_statku=12) then
- begin
- y:=random(8)+1;
- x:=random(9)+2;
- tab2[y][x]:=10;
- tab2[y+1][x]:=10;
- tab2[y+2][x]:=10;
- tab2[y][x-1]:=10;
- break;
- end;
- if(typ_statku=13) then
- begin
- y:=random(8)+1;
- x:=random(9)+1;
- tab2[y][x]:=10;
- tab2[y+1][x]:=10;
- tab2[y+2][x]:=10;
- tab2[y][x+1]:=10;
- break;
- end;
- until (stw=1);
- end;
- procedure tworzenie_3_k();
- var
- typ_statku, it1, it2, x, y, stw, a, war : integer;
- begin
- stw:=0;
- for a:=8 to 9 do
- begin
- war:=0;
- repeat
- randomize();
- typ_statku:=random(6)+1;
- if (typ_statku=1)then
- begin
- y:=random(10)+1;
- x:=random(8)+1;
- for it1:=-1 to 1 do
- begin
- for it2:=-1 to 1 do
- begin
- if ((tab2[y+it1][x+it2]=0) AND (tab2[y+it1][x+1+it2]=0) AND (tab2[y+it1][x+2+it2]=0))then
- begin
- war:=war+1;
- end;
- end;
- end;
- if (war=9) then
- begin
- tab2[y][x]:=a;
- tab2[y][x+1]:=a;
- tab2[y][x+2]:=a;
- break;
- end;
- war:=0;
- end;
- if (typ_statku=2)then
- begin
- y:=random(9)+1;
- x:=random(9)+1;
- for it1:=-1 to 1 do
- begin
- for it2:=-1 to 1 do
- begin
- if ((tab2[y+it1][x+it2]=0) AND (tab2[y+it1][x+1+it2]=0) AND (tab2[y+1+it1][x+1+it2]=0))then
- begin
- war:=war+1;
- end;
- end;
- end;
- if (war=9) then
- begin
- tab2[y][x]:=a;
- tab2[y][x+1]:=a;
- tab2[y+1][x+1]:=a;
- break;
- end;
- war:=0;
- end;
- if (typ_statku=3)then
- begin
- y:=random(9)+1;
- x:=random(9)+1;
- for it1:=-1 to 1 do
- begin
- for it2:=-1 to 1 do
- begin
- if ((tab2[y+it1][x+it2]=0) AND (tab2[y+it1][x+1+it2]=0) AND (tab2[y+1+it1][x+it2]=0))then
- begin
- war:=war+1;
- end;
- end;
- end;
- if (war=9) then
- begin
- tab2[y][x]:=a;
- tab2[y][x+1]:=a;
- tab2[y+1][x]:=a;
- break;
- end;
- war:=0;
- end;
- if (typ_statku=4)then
- begin
- y:=random(9)+1;
- x:=random(9)+1;
- for it1:=-1 to 1 do
- begin
- for it2:=-1 to 1 do
- begin
- if ((tab2[y+it1][x+it2]=0) AND (tab2[y+1+it1][x+1+it2]=0) AND (tab2[y+1+it1][x+it2]=0))then
- begin
- war:=war+1;
- end;
- end;
- end;
- if (war=9) then
- begin
- tab2[y][x]:=a;
- tab2[y+1][x]:=a;
- tab2[y+1][x+1]:=a;
- break;
- end;
- war:=0;
- end;
- if (typ_statku=5)then
- begin
- y:=random(9)+2;
- x:=random(9)+1;
- for it1:=-1 to 1 do
- begin
- for it2:=-1 to 1 do
- begin
- if ((tab2[y+it1][x+it2]=0) AND (tab2[y+it1][x+1+it2]=0) AND (tab2[y-1+it1][x+1+it2]=0))then
- begin
- war:=war+1;
- end;
- end;
- end;
- if (war=9) then
- begin
- tab2[y][x]:=a;
- tab2[y][x+1]:=a;
- tab2[y-1][x+1]:=a;
- break;
- end;
- war:=0;
- end;
- if (typ_statku=6)then
- begin
- y:=random(8)+1;
- x:=random(10)+1;
- for it1:=-1 to 1 do
- begin
- for it2:=-1 to 1 do
- begin
- if ((tab2[y+it1][x+it2]=0) AND (tab2[y+1+it1][x+it2]=0) AND (tab2[y+2+it1][x+it2]=0))then
- begin
- war:=war+1;
- end;
- end;
- end;
- if (war=9) then
- begin
- tab2[y][x]:=a;
- tab2[y+1][x]:=a;
- tab2[y+2][x]:=a;
- break;
- end;
- war:=0;
- end;
- until (stw=1) ;
- end;
- end;
- procedure tworzenie_2_k();
- var
- stw, typ_statku, it1, it2, war, a, x, y : integer;
- begin
- stw:=0;
- for a:=5 to 7 do
- begin
- war:=0;
- repeat
- randomize();
- typ_statku:=random(2)+1;
- if (typ_statku=1)then
- begin
- y:=random(10)+1;
- x:=random(9)+1;
- for it1:=-1 to 1 do
- begin
- for it2:=-1 to 1 do
- begin
- if ((tab2[y+it1][x+it2]=0) AND (tab2[y+it1][x+1+it2]=0))then
- begin
- war:=war+1;
- end;
- end;
- end;
- if (war=9) then
- begin
- tab2[y][x]:=a;
- tab2[y][x+1]:=a;
- break;
- end;
- war:=0;
- end;
- if (typ_statku=2)then
- begin
- y:=random(9)+1;
- x:=random(10)+1;
- for it1:=-1 to 1 do
- begin
- for it2:=-1 to 1 do
- begin
- if ((tab2[y+it1][x+it2]=0) AND (tab2[y+1+it1][x+it2]=0))then
- begin
- war:=war+1;
- end;
- end;
- end;
- if (war=9) then
- begin
- tab2[y][x]:=a;
- tab2[y+1][x]:=a;
- break;
- end;
- war:=0;
- end;
- until (stw=1);
- end;
- end;
- procedure tworzenie_1_k();
- var
- it1, it2, b, war, stw,x, y :integer;
- begin
- stw:=0;
- for b:=1 to 4 do
- begin
- war:=0;
- repeat
- y:=random(10)+1;
- x:=random(10)+1;
- for it1:=-1 to 1 do
- begin
- for it2:=-1 to 1 do
- begin
- if (tab2[y+it1][x+it2]=0) then
- begin
- war:=war+1;
- end;
- end;
- end;
- if (war=9) then
- begin
- tab2[y][x]:=b;
- break;
- end;
- war:=0;
- until (stw=1);
- end;
- end;
- procedure ruch_komputera(var komp : integer; var _1 : integer; var _2 : integer; var typ : integer);
- var
- x, y, it1, it2,m, zm,a,b, myk, odmyk : integer;
- begin
- zm:=0;
- if (komp=0) then
- begin
- m:=0;
- repeat
- randomize();
- y:=random(10)+1;
- x:=random(10)+1;
- until (tab2_c[y][x]=0);
- if ((tab1[y][x]=0) AND (tab2_c[y][x]=0)) then
- begin
- tab1[y][x]:=-9;
- tab2_c[y][x]:=-1;
- komp:=0;
- zm:=1;
- end;
- if (zm=0) then
- begin
- for it1:=-1 to 1 do
- begin
- for it2:=-1 to 1 do
- begin
- if ((it1=0) AND (it2=0)) then break;
- if ((tab1[y+it1][x+it2]=0) AND (tab1[y][x]>0) AND (tab2_c[y][x]=0)) then
- begin
- m:=m+1;
- end;
- end;
- end;
- if(m=8) then
- begin
- tab1[y][x]:=-11;
- tab2_c[y][x]:=-3;
- komp:=0;
- zm:=1;
- end;
- if (m<8) then
- begin
- typ:=tab1[y][x];
- tab1[y][x]:=-10;
- tab2_c[y][x]:=-2;
- _1:=y;
- _2:=x;
- komp:=1;
- zm:=1;
- end;
- end;
- end;
- if ((komp=1) AND (zm=0)) then
- begin
- odmyk:=1;
- writeln('1');
- for it1:=-1 to 1 do
- begin
- for it2:=-1 to 1 do
- begin
- if (((it1=0)OR(it2=0))AND (tab2_c[_1+it1][_2+it2]=0) AND (_1+it1<=10) AND (_1+it1>=1) AND (_2+it2<=10) AND (_2+it2>=1)) then
- begin
- odmyk:=2;
- break;
- end
- else continue;
- end;
- if (odmyk=2) then break;
- end;
- if(tab1[_1+it1][_2+it2]=typ) then
- begin
- tab1[_1+it1][_2+it2]:=-10;
- tab2_c[_1+it1][_2+it2]:=-2;
- myk:=1;
- for a:=-3 to 3 do
- begin
- for b:=-3 to 3 do
- begin
- if (tab1[_1+a][_2+b]=typ) then
- begin
- komp:=1;
- myk:=2;
- break;
- end;
- end;
- if (myk=2) then break;
- end;
- if (myk=1) then
- begin
- for a:=-3 to 3 do
- begin
- for b:=-3 to 3 do
- begin
- if (tab1[_1+a][_2+b]=-10) then
- begin
- if ((_1+a>11) OR (_1+a<0) OR (_2+b>11) OR (_2+b<0)) then
- break;
- komp:=0;
- tab1[_1+a][_2+b]:=-11;
- tab2_c[_1+a][_2+b]:=-3;
- komp:=0;
- end;
- end;
- end;
- end;
- _1:=_1+it1;
- _2:=_2+it2;
- end
- else if (tab1[_1+it1][_2+it2]=0) then
- begin
- tab1[_1+it1][_2+it2]:=-9;
- tab2_c[_1+it1][_2+it2]:=-1;
- komp:=1;
- end;
- end;
- end;
- procedure tworzenie(var tab:tablica; var tab_c : tablica; gracz : string);
- begin
- tworzenie_4(tab,tab_c, gracz);
- tworzenie_3(tab,tab_c, gracz);
- tworzenie_2(tab,tab_c, gracz);
- tworzenie_1(tab,tab_c, gracz);
- end;
- procedure tworzenie_k ();
- begin
- tworzenie_4_k();
- tworzenie_3_k();
- tworzenie_2_k();
- tworzenie_1_k();
- end;
- procedure przerwa();
- var
- m: integer;
- begin
- al_clear_to_color( al_screen, al_makecol( 0, 0, 0 ) );
- for m:=15 downto 11 do
- begin
- al_textout_ex(al_screen, al_font, 'Zmiana zawodnika, masz sekund', 310, 300, al_makecol(200,200,200), -1);
- al_textout_ex(al_screen, al_font, litery[m], 500, 300, al_makecol(200,200,200), -1);
- delay(1000);
- al_clear_to_color( al_screen, al_makecol( 0, 0, 0 ) );
- end;
- al_clear_to_color( al_screen, al_makecol( 0, 0, 0 ) );
- end;
- function powitalny() : byte;
- begin
- al_textout_centre_ex(al_screen,al_font,'WITAJ W GRZE W STATKI', ScreenWidth div 2, ScreenHeight div 3, al_makecol(200,200,200), -1);
- al_textout_ex(al_screen, al_font, 'Wykonal: Kamil Sobolewski Informatyka EAIIB 2015', 800, 700, al_makecol(200,200,200), -1);
- al_rectfill( al_screen, 470, 270 , 730, 320, al_makecol( 0, 0, 0 ) );
- al_rect( al_screen, 470, 270, 730, 320, al_makecol( 200, 200, 200 ) );
- al_textout_ex(al_screen, al_font, 'Gra z innym uzytkownikiem', 500, 295, al_makecol(200,200,200), -1);
- al_rectfill( al_screen, 470, 330 , 730, 380, al_makecol( 0, 0, 0 ) );
- al_rect( al_screen, 470, 330, 730, 390, al_makecol( 200, 200, 200 ) );
- al_textout_ex(al_screen, al_font, 'Gra z komputerem', 540, 360, al_makecol(200,200,200), -1);
- repeat
- pozycja_myszki();
- if((mx>470) AND (mx<730) AND (my<320) AND (my>270))then
- begin
- al_rectfill( al_screen, 470, 270 , 730, 320, al_makecol( 200, 200, 200 ) );
- al_rect( al_screen, 470, 270, 730, 320, al_makecol( 200, 200, 200 ) );
- al_textout_ex(al_screen, al_font, 'Gra z innym uzytkownikiem', 500, 295, al_makecol(0,0,0), -1);
- end;
- if((mx>470) AND (mx<730) AND (my<390) AND (my>330))then
- begin
- al_rectfill( al_screen, 470, 330 , 730, 390, al_makecol( 200, 200, 200 ) );
- al_rect( al_screen, 470, 330, 730, 390, al_makecol( 200, 200, 200 ) );
- al_textout_ex(al_screen, al_font, 'Gra z komputerem', 540, 360, al_makecol(0,0,0), -1);
- end;
- until (mb=1);
- if((mx>470) AND (mx<730) AND (my<390) AND (my>330))then
- begin
- powitalny:=2;
- end;
- if((mx>470) AND (mx<730) AND (my<320) AND (my>270))then
- begin
- powitalny:=1;
- end;
- end;
- function sprawdzenie ( var tab : tablica; a: integer; b: integer) : integer;
- begin
- if (tab[a][b]>0) then
- begin
- if (((tab[a+1][b]=0) OR (tab[a+1][b]=-10)OR (tab[a+1][b]=-9)) AND ((tab[a-1][b]=0) OR (tab[a-1][b]=-10)OR (tab[a-1][b]=-9)) AND ((tab[a][b+1]=0) OR (tab[a][b+1]=-10)OR (tab[a][b+1]=-9)) AND ((tab[a][b-1]=0)OR (tab[a][b-1]=-10)OR (tab[a][b-1]=-9)))then
- begin
- al_rectfill( al_screen, 240, 415 , 1000, 440, al_makecol( 0, 0, 0 ) );
- al_textout_ex(al_screen, al_font, 'Trafiony, zatopiony!', 310, 420, al_makecol(200,200,200), -1);
- tab[a][b]:=-11;
- sprawdzenie:=1;
- end
- else
- begin
- al_rectfill( al_screen, 240, 415 , 1000, 440, al_makecol( 0, 0, 0 ) );
- al_textout_ex(al_screen, al_font, 'Trafiony, niezatapiony!', 310, 420, al_makecol(200,200,200), -1);
- tab[a][b]:=-10;
- sprawdzenie:=2;
- end;
- end
- else
- begin
- tab[a][b]:=-9;
- sprawdzenie:=3;
- al_rectfill( al_screen, 240, 415 , 1000, 440, al_makecol( 0, 0, 0 ) );
- al_textout_ex(al_screen, al_font, 'Pudlo!', 310, 420, al_makecol(200,200,200), -1);
- end;
- end;
- procedure ruch ( var tab : tablica; var tab_c : tablica; var tab_wys : tablica;gracz: string);
- var
- m, a, b, i, iterator1,iterator2, check : integer;
- begin
- if (tryb=1) then
- begin
- clear();
- end;
- m:=0;
- i:=0;
- wyswietl(tab_wys, tab_c, gracz, -2);
- al_textout_ex(al_screen, al_font, 'Twoj ruch, wybierz pole i strzelaj', 310, 400, al_makecol(200,200,200), -1);
- repeat
- begin
- mb:=0;
- repeat
- pozycja_myszki();
- przekroczenie_1(35, 350, 65, 360);
- until ((mb=1) AND (przekroczenie_1(35,350,65,360)=false));
- if ((tab_c[((my-65)DIV 30)+1][((mx-35)DIV 30)+1]<>-1) AND (tab_c[((my-65)DIV 30)+1][((mx-35) DIV 30)+1]<>-2) AND (tab_c[((my-65)DIV 30)+1][((mx-35) DIV 30)+1]<>-3)) then
- begin
- a:=((my-65)DIV 30)+1;
- b:=((mx-35) DIV 30)+1;
- check:=sprawdzenie(tab,a,b);
- if (check=1) then
- begin
- tab_c[a][b]:=-3;
- for iterator1:=-3 to 3 do
- begin
- for iterator2:=-3 to 3 do
- begin
- if((iterator1=0) AND (iterator2=0)) then break;
- if(tab[a+iterator1][b+iterator2]=-10) then
- begin
- if ((a+iterator1>11) OR (a+iterator1<0) OR (b+iterator2>11) OR (b+iterator2<0)) then
- break;
- tab[a+iterator1][b+iterator2]:=-11;
- tab_c[a+iterator1][b+iterator2]:=-3;
- end;
- end;
- end;
- end;
- if (check=2) then tab_c[a][b]:=-2;;
- if (check=3) then tab_c[a][b]:=-1;
- m:=1;
- if (i<>0) then
- begin
- al_textout_ex(al_screen, al_font, 'To pole bylo wybrane wczesniej', 310, 420, al_makecol(0,0,0), -1);
- end;
- end
- else
- begin
- al_textout_ex(al_screen, al_font, 'To pole bylo wybrane wczesniej', 310, 420, al_makecol(200,200,200), -1);
- end;
- i:=i+1;
- end;
- until (m=1);
- wyswietl_c(tab_wys, tab_c);
- delay(1000);
- end;
- function warunek_gry (tab1 : tablica; tab2 : tablica) : integer;
- var
- i, j : integer;
- licznik1, licznik2 : integer;
- begin
- licznik1:=0;
- licznik2:=0;
- for i:=1 to 10 do
- begin
- for j:=1 to 10 do
- begin
- if (tab1[i][j]<=0) then licznik1:=licznik1+1;
- if (tab2[i][j]<=0) then licznik2:=licznik2+1;
- end;
- end;
- if (licznik1=100) then warunek_gry:=0;
- if (licznik2=100) then warunek_gry:=1;
- if((licznik1<>100) AND (licznik2<>100))then warunek_gry:=2;
- end;
- procedure dwoch_graczy ();
- var
- wygrany : string;
- warunek : integer;
- begin
- wyswietl(tab1,tab1_c, 'Gracz 1.',-1);
- tworzenie(tab1,tab1_c, 'Gracz 1.');
- przerwa();
- wyswietl(tab2,tab2_c, 'Gracz 2.', -1);
- tworzenie(tab2,tab2_c, 'Gracz 2.');
- przerwa();
- warunek:=5;
- repeat
- ruch(tab2, tab1_c, tab1, 'Gracz 1.');
- warunek:=warunek_gry(tab1,tab2);
- if((warunek=0) OR (warunek=1)) then break;
- delay(1500);
- przerwa();
- clear();
- ruch(tab1, tab2_c, tab2, 'Gracz 2.');
- delay(1500);
- warunek:=warunek_gry(tab1,tab2);
- if((warunek=0) OR (warunek=1)) then break;
- przerwa();
- clear();
- until ((warunek=0) OR (warunek=1));
- if (warunek_gry(tab1, tab2)=0) then wygrany:='Gracz 2.';
- if (warunek_gry(tab1, tab2)=1) then wygrany:='Gracz 1.';
- clear();
- koniec(wygrany);
- end;
- procedure komputer ();
- var
- wygrany : string;
- warunek, zm : integer;
- begin
- wyswietl(tab1,tab1_c, 'Gracz 1.',-1);
- tworzenie(tab1,tab1_c, 'Gracz 1.');
- tworzenie_k();
- warunek:=5;
- zm:=0;
- repeat
- if(zm=0) then clear;
- ruch(tab2, tab1_c, tab1, 'Gracz 1.');
- warunek:=warunek_gry(tab1,tab2);
- if((warunek=0) OR (warunek=1)) then break;
- ruch_komputera(komp, _1, _2, typ);
- warunek:=warunek_gry(tab1,tab2);
- if((warunek=0) OR (warunek=1)) then break;
- zm:=zm+1;
- until ((warunek=0) OR (warunek=1));
- if (warunek_gry(tab1, tab2)=0) then wygrany:='Gracz 2.';
- if (warunek_gry(tab1, tab2)=1) then wygrany:='Gracz 1.';
- clear();
- koniec(wygrany);
- end;
- begin
- inicjalizuj();
- tryb:=powitalny();
- delay(500);
- clear();
- case tryb of
- 1 : dwoch_graczy();
- 2 : komputer();
- end;
- al_readkey;
- al_exit();
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement