Game in ships

Delphi & Pascal (česká wiki)
Přejít na: navigace, hledání
Category:
starki.pngAuthor: Mac from Poland
Program: Statki.pas
File exe: Statki.exe

Game in ships.
{ STATKI.PAS                                      Copyright (c) Mac }
{ Game in ships.                                                    }
{                                                                   }
{ Datum:23.03.2006                             http://www.trsek.com }
 
program Statki_game;
 
uses CRT;
 
var
  i, j, x, y, z, q, a, b :integer;
  punktycpu, punktyplayera:word;
  c:char;
  plansza1: array [1..10,1..10] of integer;
  plansza2: array [1..10,1..10] of integer;
  maszty4: array[1..4,1..4] of integer;
  maszty3: array[1..3,1..3] of integer;
  maszty2: array[1..2,1..2] of integer;
 
procedure statki;
begin
  gotoxy(13,1);  write('   /   _____/_/  |_ _____  _/  |_ |  | __|__|');
  gotoxy(13,2);  write('   \_____  \ \   __\\__  \ \   __\|  |/ /|  |');
  gotoxy(13,3);  write('   /        \ |  |   / __ \_|  |  |    < |  |');
  gotoxy(13,4);  write('  /_______  / |__|  (____  /|__|  |__|_ \|__|');
  gotoxy(13,5);  write('          \/             \/            \/    ');
end;
 
 
procedure planszacpu;
begin
 
  gotoxy(20,7);
  write('CPU');
 
  for i:= 1 to 10 do
  begin
    gotoxy(10+i*2,9);    {cyferki 1 g}
    write(i);
    gotoxy(10+i*2,22);   {cyferki 1 d}
    write(i);
    gotoxy(8,10+i);      {cyferki 1 l}
    write(i);
    gotoxy(33,10+i);     {cyferki 1 p}
    write(i);
  end;
 
 
  gotoxy(10,10);    {1 lewy gorny rog}
  write(#201);
 
  gotoxy(32,10);    {1 prawy gorny rog}
  write(#187);
 
  gotoxy(10,21);    {1 lewy dolny rog}
  write(#200);
 
  gotoxy(32,21);    {1 prawy dolny rog}
  write(#188);
 
 
 
  for i:= 1 to 10 do {1l}
   begin
    gotoxy(10 ,10+i);
    write(#186);
   end;
 
 
  for i:= 1 to 10 do {1p}
   begin
    gotoxy(32 ,10+i);
    write(#186);
   end;
 
 
  for i:= 1 to 21 do {1g}
   begin
    gotoxy(10+i,10);
    write(#205);
   end;
 
  for i:= 1 to 21 do {1d}
   begin
    gotoxy(10+i,21);
    write(#205);
   end;
 
  gotoxy(61,5);
  write('Punkty CPU: ');
 
end;
 
 
procedure planszaplayer;
begin
 
  gotoxy(51,7);
  write('Player');
 
  for i:= 1 to 10 do  {cyferki 2 g}
   begin
    gotoxy(42+i*2,9);
    write(i);
   end;
 
  for i:= 1 to 10 do
    begin
     gotoxy(42+i*2,22); {cyferki 2 d}
     write(i);
     gotoxy(40,10+i);   {cyferki 2 l}
     write(i);
     gotoxy(65,10+i);   {cyferki 2 p}
     write(i);
    end;
 
 
  gotoxy(42,10);    {2 lewy gorny rog}
   write(#201);
 
  gotoxy(64,10);    {2 prawy gorny rog}
   write(#187);
 
  gotoxy(42,21);    {2 lewy dolny rog}
   write(#200);
 
  gotoxy(64,21);    {2 prawy dolny rog}
   write(#188);
 
  for i:= 1 to 10 do {2l}
   begin
    gotoxy(42 ,10+i);
    write(#186);
   end;
 
  for i:= 1 to 10 do {2p}
   begin
    gotoxy(64 ,10+i);
    write(#186);
   end;
 
  for i:= 1 to 21 do {2g}
   begin
    gotoxy(42+i,10);
    write(#205);
   end;
 
  for i:= 1 to 21 do {2d}
   begin
    gotoxy(42+i,21);
    write(#205);
   end;
 
  gotoxy(61,3);
  write('Punkty Playera: ');
end;
 
 
BEGIN
 
  statki;
  planszacpu;
  planszaplayer;
  punktycpu:=0;
  punktyplayera:=0;
  gotoxy(72,5);
  write('0');
  gotoxy(76,3);
  write('0');
 
  { rysowanie statków playera }
  { czteromasztowiec; }
 
  gotoxy(68,8);
  readln(a);
  gotoxy(68,9);
  readln(b);
  plansza2[a,b]:=1;
  gotoxy(42+a*2,10+b);
  write(#219);
  c:=readkey;
 
  if c='w' then
   begin
    plansza2[a,b-1]:=1;                        { góra }
    gotoxy(42+a*2,9+b);
    write(#219);
    plansza2[a,b-2]:=1;
    gotoxy(42+a*2,8+b);
    write(#219);
    plansza2[a,b-3]:=1;
    gotoxy(42+a*2,7+b);
    write(#219);
  end;
 
  if c='s' then                                { dół }
   begin
    plansza2[a,b+1]:=1;
    gotoxy(42+a*2,11+b);
    write(#219);
    plansza2[a,b+2]:=1;
    gotoxy(42+a*2,12+b);
    write(#219);
    plansza2[a,b+3]:=1;
    gotoxy(42+a*2,13+b);
    write(#219);
   end;
 
  if c='d' then                                { prawo }
   begin
    plansza2[a+1,b]:=1;
    gotoxy(44+a*2,10+b);
    write(#219);
    plansza2[a+2,b]:=1;
    gotoxy(46+a*2,10+b);
    write(#219);
    plansza2[a+3,b]:=1;
    gotoxy(48+a*2,10+b);
    write(#219);
   end;
 
  if c='a' then                                { lewo }
   begin
    plansza2[a-1,b]:=1;
    gotoxy(40+a*2,10+b);
    write(#219);
    plansza2[a-2,b]:=1;
    gotoxy(38+a*2,10+b);
    write(#219);
    plansza2[a-3,b]:=1;
    gotoxy(36+a*2,10+b);
    write(#219);
   end;
 
 
   { pierwszy trzymasztowiec; }
 
   gotoxy(68,8);
   readln(a);
   gotoxy(68,9);
   readln(b);
   plansza2[a,b]:=1;
   gotoxy(42+a*2,10+b);
   write(#219);
   c:=readkey;
 
   if c='w' then
    begin
     plansza2[a,b-1]:=1;             { góra }
     gotoxy(42+a*2,9+b);
     write(#219);
     plansza2[a,b-2]:=1;
     gotoxy(42+a*2,8+b);
     write(#219);
    end;
 
   if c='s' then                     { dół }
    begin
     plansza2[a,b+1]:=1;
     gotoxy(42+a*2,11+b);
     write(#219);
     plansza2[a,b+2]:=1;
     gotoxy(42+a*2,12+b);
     write(#219);
    end;
 
   if c='d' then                     { prawo }
    begin
     plansza2[a+1,b]:=1;
     gotoxy(44+a*2,10+b);
     write(#219);
     plansza2[a+2,b]:=1;
     gotoxy(46+a*2,10+b);
     write(#219);
    end;
 
   if c='a' then                     { lewo }
    begin
     plansza2[a-1,b]:=1;
     gotoxy(40+a*2,10+b);
     write(#219);
     plansza2[a-2,b]:=1;
     gotoxy(38+a*2,10+b);
     write(#219);
    end;
 
  { drugi trzymasztowiec }
 
  gotoxy(68,8);
  readln(a);
  gotoxy(68,9);
  readln(b);
  plansza2[a,b]:=1;
  gotoxy(42+a*2,10+b);
  write(#219);
  c:=readkey;
 
  if c='w' then
   begin
    plansza2[a,b-1]:=1;              { góra }
    gotoxy(42+a*2,9+b);
    write(#219);
    plansza2[a,b-2]:=1;
    gotoxy(42+a*2,8+b);
    write(#219);
   end;
 
  if c='s' then                      { dół }
   begin
    plansza2[a,b+1]:=1;
    gotoxy(42+a*2,11+b);
    write(#219);
    plansza2[a,b+2]:=1;
    gotoxy(42+a*2,12+b);
    write(#219);
   end;
 
  if c='d' then                      { prawo }
   begin
    plansza2[a+1,b]:=1;
    gotoxy(44+a*2,10+b);
    write(#219);
    plansza2[a+2,b]:=1;
    gotoxy(46+a*2,10+b);
    write(#219);
   end;
 
  if c='a' then                      { lewo }
   begin
    plansza2[a-1,b]:=1;
    gotoxy(40+a*2,10+b);
    write(#219);
    plansza2[a-2,b]:=1;
    gotoxy(38+a*2,10+b);
    write(#219);
   end;
 
 
  { pierwszy dwumasztowiec }
 
  gotoxy(68,8);
  readln(a);
  gotoxy(68,9);
  readln(b);
  plansza2[a,b]:=1;
  gotoxy(42+a*2,10+b);
  write(#219);
  c:=readkey;
 
  if c='w' then
     begin
           plansza2[a,b-1]:=1;        { góra }
           gotoxy(42+a*2,9+b);
           write(#219);
     end;
 
  if c=#25 then                       { dół }
     begin
           plansza2[a,b+1]:=1;
           gotoxy(42+a*2,11+b);
           write(#219);
     end;
 
  if c=#26 then                       { prawo }
     begin
           plansza2[a+1,b]:=1;
           gotoxy(44+a*2,9+b);
           write(#219);
     end;
 
  if c=#27 then                       { lewo }
     begin
           plansza2[a-1,b]:=1;
           gotoxy(40+a*2,9+b);
           write(#219);
     end;
 
  { drugi dwumasztowiec }
 
  gotoxy(68,8);
  readln(a);
  gotoxy(68,9);
  readln(b);
  plansza2[a,b]:=1;
  gotoxy(42+a*2,10+b);
  write(#219);
  c:=readkey;
 
  if c='w' then
     begin
           plansza2[a,b-1]:=1;        { góra }
           gotoxy(42+a*2,9+b);
           write(#219);
     end;
 
  if c='s' then                       { dół }
     begin
           plansza2[a,b+1]:=1;
           gotoxy(42+a*2,11+b);
           write(#219);
     end;
 
  if c='d' then                       { prawo }
     begin
           plansza2[a+1,b]:=1;
           gotoxy(44+a*2,9+b);
           write(#219);
     end;
 
  if c='a' then                       { lewo }
     begin
           plansza2[a-1,b]:=1;
           gotoxy(40+a*2,9+b);
           write(#219);
     end;
 
  { trzeci dwumasztowiec; }
 
  gotoxy(68,8);
  readln(a);
  gotoxy(68,9);
  readln(b);
  plansza2[a,b]:=1;
  gotoxy(42+a*2,10+b);
  write(#219);
  c:=readkey;
 
  if c='w' then
     begin
           plansza2[a,b-1]:=1;         { góra }
           gotoxy(42+a*2,9+b);
           write(#219);
     end;
 
  if c='s' then                        { dół }
     begin
           plansza2[a,b+1]:=1;
           gotoxy(42+a*2,11+b);
           write(#219);
     end;
 
  if c='d' then                        { prawo }
     begin
           plansza2[a+1,b]:=1;
           gotoxy(44+a*2,9+b);
           write(#219);
     end;
 
  if c=#27 then                        { lewo }
     begin
           plansza2[a-1,b]:=1;
           gotoxy(40+a*2,9+b);
           write(#219);
     end;
 
 
 
  { pierwszy jednomasztowiec; }
 
  gotoxy(68,8);
  readln(a);
  gotoxy(68,9);
  readln(b);
 
 
  plansza2[a,b]:=1;
  gotoxy(42+a*2,10+b);
  write(#219);
 
 
 
  { drugi jednomasztowiec; }
 
  gotoxy(68,8);
  readln(a);
  gotoxy(68,9);
  readln(b);
 
  plansza2[a,b]:=1;
  gotoxy(42+a*2,10+b);
  write(#219);
 
 
  { trzeci jednomasztowiec; }
 
  gotoxy(68,8);
  readln(a);
  gotoxy(68,9);
  readln(b);
 
  plansza2[a,b]:=1;
  gotoxy(42+a*2,10+b);
  write(#219);
 
 
 
  { czwarty jednomasztowiec; }
 
  gotoxy(68,8);
  readln(a);
  gotoxy(68,9);
  readln(b);
 
 
  plansza2[a,b]:=1;
  gotoxy(42+a*2,10+b);
  write(#219);
 
 
begin
                               {plansza CPU}
  randomize;
  for i:=1 to 10 do
    for j:=1 to 10 do
       plansza1[i,j]:=random(2);
end;
 
 
  { begin                          plansza playera
  randomize;
  for i:=1 to 10 do
    for j:=1 to 10 do
       plansza2[i,j]:=random(2);
end;
 
 for i:= 1 to 10 do
   for j:=1 to 10 do
     begin
        gotoxy(42+i*2,10+j);
        if plansza2[i,j]=0  then
           write(' ');
        if plansza2[i,j]=1 then
           write(#219);
     end;                                    }
 
 
 repeat
 
   repeat
     gotoxy(1,1);
     readln(x);
     readln(y);
     gotoxy(1,1);
     write('   ');
     gotoxy(1,2);
     write('   ');
 
   until (x>=1) and (x<=10) and (y>=1) and (y<=10);
 
   gotoxy(x*2+10,y+10);
 
 
   if plansza1[x,y]=0 then
      begin
         plansza1[x,y]:=2;
         write('O');
      end;
 
   if plansza1[x,y]=1 then
      begin
         plansza1[x,y]:=3;
         write(#177);
         punktyplayera:=punktyplayera+1;
         gotoxy(76,3);
         write(punktyplayera);
      end;
 
 
   begin
      randomize;
 
      z:=random(10);
      q:=random(10);
      gotoxy(z*2+44,q+11);
 
      if plansza2[z+1,q+1]=0 then
         begin
           plansza2[z+1,q+1]:=2;
           write('O');
         end;
 
      if plansza2[z+1,q+1]=1 then
         begin
           plansza2[z+1,q+1]:=3;
           write(#177);
           punktycpu:=punktycpu+1;
           gotoxy(72,5);
           write(punktycpu);
         end;
 
   end;
 
   for i:= 1 to 5 do
     begin
       gotoxy(1,i);
       write('    ');
     end;
 
 until false;
 
END.