{ +Narisovat Uxod za granicu +Narisovat Mishek +Zastavit Kushat Misku +Zastavit Poyavliatsia Novix Mishek +Ogranichet i razukrasit polia +Vvesti SCHET +Vvesti Skorost +Oformit Konec +Narisovat Chtob ne kushal sebia +Narisovat Zastavku; -Zdelat` chtob ne po`avlialis` miski vnutri cherviaka -Vvesti Tablicu Recordov } Program Cherv; uses Crt,graph; Const Shirina= 68 ; Visota = 49 ; Znak = '*'; Type Masiv= array[1..Shirina,1..Visota] of Shortint; Kord1= array[1..2,1..2000] of integer; Var I,j,x,y,Zi,Zj :Byte ; GameOver :Char ; Mas :Masiv ; Kord :Kord1 ; Nap :Char ; Flag :Char ; PredNapr,H :Char ; Kx,Ky :Shortint; Leng :Integer ; Dlin :Integer ; Speed :Integer ; Skushal :Byte ; Nachalo :Byte ; Procedure Start; Begin GotoXY(10,15);Writeln(' ## ### ## ### #### # # '); GotoXY(10,16);Writeln(' ## ## ## ## ## ## ## ## ### ### '); GotoXY(10,17);Writeln(' ## ## ## ## ## ## #### ## ## ## ## '); GotoXY(10,18);Writeln(' ## ## ## ## ## ## ### ## ## ## ## '); GotoXY(10,19);Writeln(' ### ### ## ## ## # ## ### ## '); GotoXY(10,20);Writeln(' # # ### ## # ## # ##'); Delay(10000);Delay(10000);Delay(10000); Window(1,1,80,50); TextBackGround(5); Clrscr; Window(2,2,68,49); TextBackGround(1); ClrScr; Window(1,1,80,50); Dlin :=5 ; Nap :='w' ; Speed :=2000 ; Skushal:=1 ; Nachalo:=0 ; X:=0;Y:=0; for i:=1 to dlin do Begin Kord[2,i]:=21+i; Kord[1,i]:=41 ; End; For i:=2 to Shirina do For j:=2 to Visota do Mas[i,j]:=0; End; Procedure Konec; Begin GotoXY(30,25); Write('Game over'); Nap:='q'; End; Procedure VibirNapravlenie; Var Napravlenie :Char; Begin IF KeyPressed Then Begin PredNapr:=nap; Napravlenie := ReadKey; IF ( (Napravlenie= 'w' ) or (Napravlenie= 'a' ) or (Napravlenie= 'd' ) or (Napravlenie= 's' ) or (Napravlenie= 'q' ) or (Napravlenie= 'p' ) or (Napravlenie= ',' ) or (Napravlenie= '.' )) THEN Nap := Napravlenie; Flag:= Nap ; END; End; Procedure VnutriNapravlenie; Begin If Nap= 'w' Then Begin Ky:=-1; Kx:= 0; End; If Nap= 's' Then Begin Ky:= 1; Kx:= 0; End; If Nap= 'a' Then Begin Kx:=-1; Ky:= 0; End; If Nap= 'd' Then Begin Kx:= 1; Ky:= 0; End; if (Nap= ',') and (Speed>1000) and (flag= ',') Then Begin Speed:=Speed-1000; Flag:='1'; End; if (Nap= '.') and (Speed<5000) and (flag= '.') Then Begin Speed:=Speed+1000; Flag:='1'; End; End; Procedure Dvigenie; Begin gotoXY(Kord[1,Dlin],Kord[2,Dlin]); Write(' '); mas[Kord[1,Dlin],Kord[2,Dlin]]:=0; for i:=2 to Dlin-1 do Begin gotoXY(kord[1,i],kord[2,i]); Write(Znak); mas[kord[1,i],kord[2,i]]:=2; End; gotoXY(kord[1,1],kord[2,1]); Write(Chr(1)); GotoXY(X,Y); Write('0'); End; Procedure Zamena; Begin for i:=Dlin downto 2 do Begin Kord[1,i]:=Kord[1,i-1]; Kord[2,i]:=Kord[2,i-1]; End; if ((Kord[1,1]= 2) and (kx=-1)) then Kord[1,1]:=Shirina else If ((Kord[1,1]=Shirina) and (kx= 1)) then Kord[1,1]:=2 else If ((Kord[2,1]= 2) and (ky=-1)) then Kord[2,1]:=Visota else If ((Kord[2,1]=Visota) and (ky= 1)) then Kord[2,1]:=2 else Begin Kord[1,1]:=Kord[1,1]+kx; Kord[2,1]:=Kord[2,1]+ky; End; End; Procedure Miski; Begin { if nachalo=1 then Begin Kord[1,1]:=X; Kord[2,1]:=Y; nachalo:=1; End; } mas[x,y]:=0; Randomize; Repeat X:= random(Shirina); Until x>1 ; Repeat Y:= random(Visota) ; Until Y>1 ; mas[x,y]:=1; Skushal:=0; End; Procedure Proverka_na_prepiatstvie; { 1-Skushal Misku 2-Skushal Xvost 3-Stenka } Begin If Mas[kord[1,1],kord[2,1]]=1 then Begin Skushal:=1; Dlin:=Dlin+1; End; If Mas[kord[1,1]+Kx,kord[2,1]+Ky]>1 then Konec; End; Procedure Vivod; Begin GotoXY(70,5); Write('Dlina '); Write(dlin-2); GotoXY(70,6); Write('Speed '); Write(speed/1000:0:0); GotoXY(70,8); Write('P-Pause'); GotoXY(70,9); Write('Q-Exit'); If Nap='p' then Begin H:='l'; While H<>'p' do Begin GotoXY(30,25); Write('Pause'); Delay(10000); GotoXY(30,25); Write(' '); Delay(10000); IF KeyPressed Then H := ReadKey; if H = 'q' then Begin Konec; exit; End; End; Nap:=PredNapr; End; End; Begin Repeat Clrscr; Start; While Nap<>'q' do Begin If Skushal=1 then Miski; Proverka_na_prepiatstvie; VibirNapravlenie; VnutriNapravlenie; Vivod; Dvigenie; Zamena; Delay(Speed); End; Konec; Repeat GotoXY(30,26); Write('New Game?(Y/N)'); GameOver:=ReadKey; Until (GameOver='y') or (GameOver='n'); Until GameOver='n'; End.