Vykreslí prasa ktorým sa dá pohybovat za pomoci šípok

Delphi & Pascal (česká wiki)
Přejít na: navigace, hledání
Kategorija: KMP (Programy mladňakoch

Zrobil: Juraj Pupák
Program: Pig.pas
Subor exe: Pig.exe

Vykreslí prasa ktorým sa dá pohybovat za pomoci šípok.
{ PIG.PAS                                                           }
{ Vykresli prasa ktorym sa da pohybovat za pomoci sipok.            }
{                                                                   }
{ Author: Juraj Pupak                                               }
{ Date  : 27.10.2006                           http://www.trsek.com }
 
program Pig;
uses crt;
var
  i : integer;
  KeyChar : char;
  Quit : Boolean;
  x,y : integer;
  f : boolean;
 
Procedure KresliPrasa(x,y,farba : integer);
 var
  i : integer;
 begin
  If farba <> 0 THEN f := not f;
  textcolor(farba);
  gotoxy(x,y);
  write(chr(218));
  IF f = False THEN
     begin
       gotoxy(x + 5,y + 5);
       write(chr(47));
       gotoxy(x + 6,y + 5);
       write(chr(92));
       gotoxy(x + 10,y + 5);
       write(chr(47));
       gotoxy(x + 11,y + 5);
       write(chr(92));
       gotoxy(x + 14,y + 3);
       write(chr(196));
     end;
 
  IF f = true THEN
     begin
       gotoxy(x + 5,y + 5);
       write(chr(179));
       gotoxy(x + 10,y + 5);
       write(chr(179));
       gotoxy(x + 14,y + 3);
       write(chr(96));
     end;
 
  For i := 1 To 12 Do
    begin
      gotoxy(x + i,y);
      write(chr(196));
    end;
 
  For i := 1 To 4 Do
    begin
      gotoxy(x,y + i);
      write(chr(179));
    end;
 
  gotoxy(x,y + i);
  write(chr(192));
  For i := 1 To 13 Do
    begin
      gotoxy(x + i,y + 4);
      write(chr(196));
    end;
 
  gotoxy(x + i,y + 4);
  write(chr(217));
  gotoxy(x + i,y);
  write(chr(191));
  For i := y + 3 downto y + 1 Do
    begin
      gotoxy(x + 13,i);
      write(chr(179));
    end;
 
  gotoxy(x + 14,y + 1);
  write(chr(92));
  gotoxy(x + 15,y + 2);
  write(chr(92));
  gotoxy(x + 15,y + 3);
  write(chr(47));
  gotoxy(x + 14,y + 4);
  write(chr(47));
  gotoxy(x + 14,y + 2);
  write(chr(9));
end;
 
begin
 clrscr;
 writeln('Pohyb prasata sipkami, enter-koniec');
 
 x := 1;
 y := 5;
 f := true;
 KresliPrasa(x,y,12);
 
 Repeat
  KeyChar := Readkey;
  Quit := False;
  Case Ord(KeyChar) Of
    0 : begin
          KeyChar := ReadKey;
          Case Ord(KeyChar) Of
            72 : if  y > 1 Then
              begin
                KresliPrasa(x,y,0);
                y := y - 1;
                KresliPrasa(x,y,12);
              end;
            80 : if y < 44 THEN
              begin
                KresliPrasa(x,y,0);
                y := y + 1;
                KresliPrasa(x,y,12);
              end;
            75 : if x > 1 THEN
              begin
                KresliPrasa(x,y,0);
                x := x - 1;
                KresliPrasa(x,y,12);
              end;
            77 : if x < 65 THEN
              begin
                KresliPrasa(x,y,0);
                x := x + 1;
                KresliPrasa(x,y,12);
              end;
          end;
      end;
  13 : Quit := True;
  end;
 Until Quit;
end.