Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program warcaby2222;
- {$APPTYPE CONSOLE}
- uses
- windows,
- SysUtils;
- const
- n=8;
- var
- t: array[1..n,1..n] of integer;
- w: array[1..2]of integer;
- x1,x2,y1,y2,p,p1,p2,s:integer;
- x3:char;
- procedure gotoxy(x,y:integer);
- var
- hnd: Thandle;
- pos: COORD;
- count: Cardinal;
- begin
- hnd:=getStdHandle(STD_OUTPUT_HANDLE);
- pos.X:=y+1;
- pos.Y:=x+1;
- SetConsoleCursorPosition(hnd,pos);
- end;
- {procedura rysująca ramkę}
- procedure rysuje_ramke(x1,y1,x2,y2:integer);
- var i:integer;
- begin
- for i:=(x1) to (x2-1) do
- begin
- gotoxy(i,y1);
- write('ş');
- gotoxy(i,y2);
- write('ş');
- end;
- for i:=(y1) to (y2-1) do
- begin
- gotoxy(x1,i);
- write('Í');
- gotoxy(x2,i);
- write('Í');
- end;
- gotoxy(x1,y1);
- write('É');
- gotoxy(x2,y1);
- write('Č');
- gotoxy(x1,y2);
- write('»');
- gotoxy(x2,y2);
- write('Ľ');
- end;
- {procedura rysująca aktualny stan planszy}
- procedure plansza;
- var
- a:char;
- i,j:integer;
- begin
- a:='A';
- for i:=1 to 8 do
- begin
- gotoxy(-1,i);
- write(i);
- gotoxy(10,i);
- write(i);
- gotoxy(i,-1);
- write(a);
- gotoxy(i,10);
- write(a);
- inc(a);
- end;
- for i:=1 to 8 do
- for j:=1 to 8 do
- begin
- gotoxy(i,j);
- if ((i-j) mod 2 =0) then
- begin
- if (i<4) then
- begin
- write('o');
- t[i,j]:=2;
- end;
- if (i>5) then
- begin
- write('x');
- t[i,j]:=3;
- end;
- if(i>=4) and (i<=5) then
- begin
- write(' ');
- t[i,j]:=1;
- end;
- end
- else t[i,j]:=0; write('±');
- end;
- end;
- {funkcja sprawdzająca poprawnosc ruchu - analiza 0-ruch niemożliwy, 1-ruch, 2-bicie, 3-ruch damką, 4-bicie damką}
- function pop3(g,x1,x2,y1,y2:integer):integer;
- var
- x,y,a:integer;
- begin
- a:=0;
- x:=x2-x1;
- y:=y2-y1;
- if t[x1,y1]=2 then
- if x=1 then pop3:=1
- else
- iF ((x=2) or (x=-2)) and ((t[((x1+x2)div 2),((y1+y2) div 2)]=3) or (t[(x1+x2) div 2,(y1+y2) div 2]=5)) then pop3:=2
- else pop3:=0;
- if t[x1,y1]=3 then
- if x=-1 then pop3:=1
- else
- if ((x=2) or (x=-2)) and ((t[(x1+x2) div 2,(y1+y2)div 2]=2) or (t[(x1+x2)div 2,(y1+y2)div 2]=4)) then pop3:=2
- else pop3:=0;
- if t[x1,y1]=4 then
- if x>0 then
- if y>0 then
- begin
- x:=1;
- repeat
- if t[x1+x,y1+x]=1 then a:=3
- else
- if x=y-1 then
- if (t[x1+x,y1+x]=3) or (t[x1+x,y1+x]=5) then a:=4;
- x:=x+1;
- until (x=y-1) or (a=4);
- end
- else
- begin
- x:=1;
- repeat
- if t[x1+x,y1-x]=1 then a:=3
- else
- if x=-y-1 then
- if (t[x1+x,y1-x]=3) or (t[x1+x,y1-x]=5) then a:=4;
- x:=x+1;
- until (x=-y-1) or (a=4);
- end
- else
- if y>0 then
- begin
- x:=1;
- repeat
- if t[x1-x,y1+x]=1 then a:=3
- else
- if x=y-1 then
- if (t[x1-x,y1+x]=3) or (t[x1-x,y1+x]=5) then a:=4;
- x:=x+1;
- until (x=y-1) or (a=4);
- end
- else
- begin
- x:=1;
- repeat
- if t[x1-x,y1-x]=1 then a:=3
- else
- if x=-y-1 then
- if (t[x1-x,y1-x]=3) or (t[x1-x,y1-x]=5) then a:=4;
- x:=x+1;
- until (x=-y-1) or (a=4);
- end ;
- if t[x1,y1]=5 then
- if x>0 then
- if y>0 then
- begin
- x:=1;
- repeat
- if t[x1+x,y1+x]=1 then a:=3
- else
- if x=y-1 then
- if (t[x1+x,y1+x]=2) or (t[x1+x,y1+x]=4) then a:=4;
- x:=x+1;
- until (x=y-1) or (a=4);
- end
- else
- begin
- x:=1;
- repeat
- if t[x1+x,y1-x]=1 then a:=3
- else
- if x=-y-1 then
- if (t[x1+x,y1-x]=2) or (t[x1+x,y1-x]=4) then a:=4;
- x:=x+1;
- until (x=-y-1) or (a=4);
- end
- else
- if y>0 then
- begin
- x:=1;
- repeat
- if t[x1-x,y1+x]=1 then a:=3
- else
- if x=y-1 then
- if (t[x1-x,y1+x]=2) or (t[x1-x,y1+x]=4) then a:=4;
- x:=x+1;
- until (x=y-1) or (a=4);
- end
- else
- begin
- x:=1;
- repeat
- if t[x1-x,y1-x]=1 then a:=3
- else
- if x=-y-1 then
- if (t[x1-x,y1-x]=2) or (t[x1-x,y1-x]=4) then a:=4;
- x:=x+1;
- until (x=-y-1) or (a=4);
- end ;
- if a=4 then pop3:=4
- else
- if a=3 then pop3:=3;
- end;
- procedure rysuj(x1,x2,y1,y2,g,s:integer);
- var
- x,y,i,j:integer;
- begin
- t[x2,y2]:=t[x1,y1];
- gotoxy(x2,y2);
- if t[x2,y2]=2 then
- if (x2=8) and ((y2=2) or (y2=4) or (y2=6) or (y2=8)) then t[x2,y2]:=4
- else Write('o');
- if t[x2,y2]=3 then
- if (x2=1) and ((y2=1) or (y2=3) or (y2=5) or (y2=7)) then t[x2,y2]:=5
- else Write('x');
- if t[x2,y2]=4 then Write('O');
- if t[x2,y2]=5 then Write('X');
- if s=2 then
- begin
- gotoxy((x1+x2)div 2,(y1+y2)div 2);
- Write(' ');
- t[(x1+x2)div 2,(y1+y2)div 2]:=1;
- end;
- if s=4 then
- begin
- x:=x2-x1;
- y:=y2-y1;
- if x>0 then
- begin
- i:=1;
- if y>0 then j:=1
- else j:=-1;
- end
- else
- begin
- i:=-1;
- if y>0 then j:=1
- else j:=-1;
- end;
- gotoxy(x2-i,y2-j);
- writeln(' ');
- t[x2-i,y2-j]:=1;
- end;
- gotoxy(x1,y1);
- write(' ');
- t[x1,y1]:=1;
- end;
- {funkcja czytajaca pierwsza wspolrzedna pola: char->integer}
- function czyt(x3:char):integer;
- begin
- if (x3>='A') and (x3<='H') then
- czyt:=ord(x3)-64
- else
- czyt:=ord(x3)-96;
- end;
- {funkcja sprawdzajaca poprawnosc (punkt 1) - czy istnieje takie pole na planszy,
- czy znajduje sie na nim twoj pionek,czy ten pionek nie jest zablokowany}
- function pop1(var p,x1,y1:integer):boolean;
- begin
- pop1:=false;
- if (((t[x1,y1]=p+1) or (t[x1,y1]=p+3))) and (x1>=1) and (x1<=8) and (y1>=1) and (y1<=8) then
- begin
- if ((t[x1,y1]=2) and (((t[x1+1,y1+1]=1) or (t[x1+1,y1-1]=1)) or
- ((t[x1+2,y1+2]=1) and ((t[x1+1,y1+1]=3) or (t[x1+1,y1+1]=5))) or
- ((t[x1-2,y1+2]=1) and ((t[x1-1,y1+1]=3) or (t[x1-1,y1+1]=5))) or
- ((t[x1+2,y1-2]=1) and ((t[x1+1,y1-1]=3) or (t[x1+1,y1-1]=5))) or
- ((t[x1-2,y1-2]=1) and ((t[x1-1,y1-1]=3) or (t[x1-1,y1-1]=5))))) or
- ((t[x1,y1]=3) and (((t[x1-1,y1+1]=1) or (t[x1-1,y1-1]=1)) or
- ((t[x1+2,y1+2]=1) and ((t[x1+1,y1+1]=2) or (t[x1+1,y1+1]=4))) or
- ((t[x1-2,y1+2]=1) and ((t[x1-1,y1+1]=2) or (t[x1-1,y1+1]=4))) or
- ((t[x1+2,y1-2]=1) and ((t[x1+1,y1-1]=2) or (t[x1+1,y1-1]=4))) or
- ((t[x1-2,y1-2]=1) and ((t[x1-1,y1-1]=2) or (t[x1-1,y1-1]=4))))) or
- (t[x1,y1]=4) or (t[x1,y1]=5) then
- pop1:=true;
- end
- else pop1:=false;
- end;
- {funkcja sprawdzajaca poprawnosc (punkt 2) - sprawdza czy ruch odbywa sie po przekatnej,
- czy istnieje na planszy takie pole, czy wybrane pole jest puste } {!}
- function pop2(g,x1,x2,y1,y2:integer):boolean;
- var
- x,y:integer;
- begin
- x:=x2-x1;
- y:=y2-y1;
- if t[x2,y2]<>1 then pop2:=false
- else
- begin
- if not((x-y=0) or (x+y=0)) and (x2>=1) and (x2<=8) and (y2>=1) and (y2<=8) then pop2:=false
- else pop2:=true;
- end;
- end;
- {funkcja sprawdzajaca czy mozliwe jest 2 bicie}
- function spr2bicie(x1,x2,y1,y2:integer):boolean;
- var
- i,j:integer;
- begin
- x1:=x2;
- y1:=y2;
- if((t[x1,y1]=2) and(((t[x1+2,y1+2]=1) and ((t[x1+1,y1+1]=3) or (t[x1+1,y1+1]=5))) or
- ((t[x1-2,y1+2]=1) and ((t[x1-1,y1+1]=3) or (t[x1-1,y1+1]=5))) or
- ((t[x1+2,y1-2]=1) and ((t[x1+1,y1-1]=3) or (t[x1+1,y1-1]=5))) or
- ((t[x1-2,y1-2]=1) and ((t[x1-1,y1-1]=3) or (t[x1-1,y1-1]=5))))) or
- ((t[x1,y1]=3) and(((t[x1+2,y1+2]=1) and ((t[x1+1,y1+1]=2) or (t[x1+1,y1+1]=4))) or
- ((t[x1-2,y1+2]=1) and ((t[x1-1,y1+1]=2) or (t[x1-1,y1+1]=4))) or
- ((t[x1+2,y1-2]=1) and ((t[x1+1,y1-1]=2) or (t[x1+1,y1-1]=4))) or
- ((t[x1-2,y1-2]=1) and ((t[x1-1,y1-1]=2) or (t[x1-1,y1-1]=4))))) then
- spr2bicie:=true;
- end;
- begin
- plansza;
- rysuje_ramke(0,0,9,9);
- p1:=0;
- P2:=0;
- p:=1;
- repeat
- repeat
- gotoxy(14,0);
- writeln('Gracz nr ',p);
- writeln('Podaj wspolrzedne pionka ktorym chesz wykonac ruch');
- gotoxy(16,-1);
- writeln(' ');
- repeat
- {$I-}gotoxy(16,0);
- read(x3);{$I+}
- until (IOResult=0) and (x3 in ['a'..'h','A'..'H']);
- repeat
- {$I-}gotoxy(16,4);
- read(y1);{$I+}
- until IOResult=0;
- x1:=czyt(x3);
- until pop1(p,x1,y1);
- write('Podaj wspolrzedne pola na ktore chcesz sie przemiescic');
- {!!!!!!}
- repeat
- repeat
- gotoxy(18,-1);
- writeln(' ');
- repeat
- {$I-}gotoxy(18,0);
- read(x3);{$I+}
- until (IOResult=0) and (x3 in ['a'..'h','A'..'H']);
- repeat
- {$I-}gotoxy(18,4);
- read(y2);{$I+}
- until IOResult=0;
- x2:=czyt(x3);
- s:=pop3(p,x1,x2,y1,y2);
- until ((pop2(p,x1,x2,y1,y2)) and (S<>0));
- rysuj(x1,x2,y1,y2,p,S);
- if (s=2) or (s=4) then w[p]:=w[p]+1;
- if (s=2) and (spr2bicie(x1,x2,y1,y2)) then
- begin
- gotoxy(16,0);
- writeln(x2);
- gotoxy(16,4);
- writeln(y2);
- x1:=x2;
- y1:=y2;
- end;
- until spr2bicie(x1,x2,y1,y2)=false;
- {!!!!!}
- p:=P+1 ;
- if p>2 then p:=p mod 2;
- rysuje_ramke(2,35,6,53);
- rysuje_ramke(0,45,2,53);
- gotoxy(1,46);
- writeln('PUNKTY');
- gotoxy(3,37);
- writeln('Gracz nr 1: ',w[1]);
- gotoxy(5,37);
- writeln('Gracz nr 2: ',w[2]);
- until (w[1]=12) or (w[2]=12);
- gotoxy(18,25);
- if w[2]=12 then
- writeln('Gratulacje wygrał gracz 2!')
- else
- writeln('Gratulacje wygrał gracz 1!');
- readln;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement