Tin học Game Rắn săn mồi bằng Pascal

HưngMC2007

Học sinh mới
Thành viên
5 Tháng ba 2021
4
1
6
17
Bình Định
THCS Bình Thuận
[TẶNG BẠN] TRỌN BỘ Bí kíp học tốt 08 môn
Chắc suất Đại học top - Giữ chỗ ngay!!

ĐĂNG BÀI NGAY để cùng trao đổi với các thành viên siêu nhiệt tình & dễ thương trên diễn đàn.

uses tcvn, crt, dos;
var c, i, x, y, d, a, b, j, v, wx, wy : integer;
ye, mo, da, tim, ou, ol, od, ori : word;
xx, yy : array[0..9999] of byte;
tsp : text;
st, ten, yea, mon, day, time, ctrl : string;
m, n, ch, up, lef, dow, rig, pa : char;
k, sou : boolean;
procedure thoat;
begin
if m=chr(27) then
k:=false;
end;
procedure sod2;
begin
if sou=true then
sound(300);
delay(1000);
nosound;
end;
procedure dc3;
var i : integer;
begin
xx[0]:=x;yy[0]:=y;
gotoxy(xx[d],yy[d]);
textbackground(6);
write(#32,#32);
textbackground(10);
for i:=d downto 1 do begin
xx:=xx[i-1];yy:=yy[i-1];
gotoxy(xx,yy);
write(#32,#32);
end;
for i:=2 to d do
if (xx=x) and (yy=y) then begin k:=false;sod2 end;
for i:=2 to d do begin
if (xx=a) and (yy=b) then begin
textbackground(0);
a:=(random(37)+2)*2-1;
b:=random(22)+2;
gotoxy(a,b);
textbackground(8);
textcolor(14+blink);
write(#40,#41);
textcolor(0);
textbackground(0);
end;
end;
end;
procedure dc1;
begin
gotoxy(x,y);
textbackground(10);
write(#32,#32);
textbackground(0);
end;
procedure sod1;
begin
if sou=true then
sound(700);
delay(200);
nosound;
end;
procedure dc2;
begin
if (x=a) and (y=b) then begin
inc(d); sod1;
gotoxy(5,25);
textbackground(11);
write('Score: ',d-1);
textbackground(0);
a:=(random(37)+2)*2-1;
b:=random(22)+2;
gotoxy(a,b);
textbackground(8);
textcolor(14+blink);
write(#40,#41);
textcolor(0);
textbackground(0);
if (d-1>0) and ((d-1) mod 10=0) and (v>50) then begin
v:=v-trunc(v/5);
if v<50 then v:=50;
end;
if ((d-1) mod 10=0) and (v>=50) then begin
gotoxy(29,25);
textbackground(7);
write('Speed = ',1000/v/2.5:5:2,' cm/s');
textbackground(0);
end;
end;
dc3;
gotoxy(x,y);
textbackground(2);
write(#39,#39);
textbackground(0);
inc(j);
if j=2 then begin
gotoxy(wx,wy);
textbackground(6);
write(#32,#32);
textbackground(0);
end;
delay(v);
end;
begin
loadfont;
highvideo;
assign(tsp,'RSM.inp');
append(tsp);
write(tsp,'');
close(tsp);
sou:=true;
up:='w';lef:='a';dow:='s';rig:='d';
ou:=ord(up);ol:=ord(lef);od:=ord(dow);ori:=ord(rig);
repeat begin
textbackground(10);
textcolor(0);
clrscr;
gotoxy(37,11);
write(telex('Chowi (C)'));
gotoxy(34,12);
write(telex('Thafnh tisch (A)'));
gotoxy(34,13);
write(telex('Casch chowi (H)'));
gotoxy(35,14);
write(telex('Tufy chojn (S)'));
gotoxy(37,15);
write(telex('Thoast (E)'));
keypressed;
ch:=readkey;
while (ch<>'c') and (ch<>'a') and (ch<>'h') and (ch<>'s') and
(ch<>chr(27)) and (ch<>chr(13)) and (ch<>'e') do
begin keypressed;ch:=readkey end;
if ch='h' then repeat begin
textbackground(10);
textcolor(0);
clrscr;
gotoxy(34,9);
writeln(telex('Casch chowi'));
gotoxy(13,wherey);
writeln(telex('Nhaasn casc phism W, A, S, D hoawjc casc phism muxi teen ddeer chowi.'));
gotoxy(20,wherey);
writeln(telex('Cos theer chirnh ddieefu khieern owr phaafn cafi ddawjt.'));
gotoxy(21,wherey);
writeln(telex('Di chuyeern con rawsn ddi awn casc ddieerm dden.'));
gotoxy(14,wherey);
writeln(telex('Khoong theer ddi theo huwowsng nguwowjc laji cura huwowsng ddang ddi.'));
gotoxy(26,wherey);
writeln(telex('Nhaasn phism P ddeer duwfng trof chowi.'));
gotoxy(23,wherey);
writeln(telex('Nhaasn phism '),'ESC',telex(' ddeer keest thusc trof chowi.'));
gotoxy(31,wherey);
writeln(telex('Chusc may mawsn :3'));
gotoxy(35,wherey);
write('Home (N)');
repeat until keypressed;
ch:=readkey;
while (ch<>'n') and (ch<>chr(13)) and (ch<>chr(27)) do begin
keypressed;
ch:=readkey;
end;
delay(50);
end until (ch='n') or (ch=chr(13)) or (ch=chr(27)) else
if (ch='c') or (ch=chr(13)) then
repeat begin
k:=true;
repeat begin
clrscr;
textbackground(10);
textcolor(0);
gotoxy(24,13);
write(telex('Nhaajp teen( 1 --> 12 kis tuwj ): '));readln(ten);
end until (length(ten)>0) and (length(ten)<=12);
randomize;
x:=(random(37)+2)*2-1;
y:=random(22)+2;
wx:=x;wy:=y;
d:=1;
v:=200;
textbackground(0);
textbackground(14);
clrscr;
gotoxy(x,y);
textbackground(2);
write(#39,#39);
textbackground(4);
gotoxy(1,1);
for i:=1 to 80 do write(#32);
for i:=1 to 24 do begin
gotoxy(79,i);
write(#32,#32);
end;
for i:=80 downto 1 do begin
gotoxy(i,24);
write(#32);
end;
gotoxy(1,1);
for i:=1 to 24 do writeln(#32,#32);
textcolor(0);
gotoxy(5,25);
textbackground(11);
write('Score: ',d-1);
textbackground(0);
gotoxy(15,25);
textbackground(13);
write(ten);
textbackground(0);
gotoxy(29,25);
textbackground(7);
write('Speed = ',1000/v/2.5:5:2,' cm/s');
textbackground(0);
a:=(random(37)+2)*2-1;
b:=random(22)+2;
gotoxy(a,b);
textbackground(8);
textcolor(14+blink);
write(#40,#41);
textcolor(0);
textbackground(0);
m:=' ';
repeat begin
keypressed;
n:=readkey;
if (n=up) or (n=lef) or (n=rig)
or (n=dow) or (n=chr(72)) or (n=chr(75))
or (n=chr(80)) or (n=chr(77)) or (n=chr(27)) then m:=n;
j:=0;
end until m<>' ';
thoat;
pa:='p';
repeat begin
if j=0 then j:=1
else begin
gotoxy(x,y);
keypressed;
n:=readkey;
if n=chr(27) then k:=false;
while (n='p') or (pa<>'p') do begin
gotoxy(75,25);
textbackground(1);
write('Pause');
textbackground(0);
repeat until keypressed;
pa:=readkey;
n:=' ';
gotoxy(75,25);
textbackground(14);
write(' ');
textbackground(0);
end;
end;
if (m=up) or (m=chr(72)) then
if (n=up) or (n=chr(72)) or (n=lef) or
(n=chr(75)) or (n=rig) or (n=chr(77)) then m:=n;
if (m=lef) or (m=chr(75)) then
if (n=up) or (n=chr(72)) or (n=lef) or
(n=chr(75)) or (n=dow) or (n=chr(80)) then m:=n;
if (m=dow) or (m=chr(80)) then
if (n=dow) or (n=chr(80)) or (n=lef) or
(n=chr(75)) or (n=rig) or (n=chr(77)) then m:=n;
if (m=rig) or (m=chr(77)) then
if (n=up) or (n=chr(72)) or (n=chr(80)) or
(n=dow) or (n=rig) or (n=chr(77)) then m:=n;
if m=chr(ou) then repeat begin
dc1;
dec(y);
dc2;
if k=false then break;
if (x=79) or (x=1) or (y=24) or (y=1)
then begin sod2;k:=false;break end;
end until keypressed else
if m=chr(ol) then repeat begin
dc1;
dec(x,2);
dc2;
if k=false then break;
if (x=79) or (x=1) or (y=24) or (y=1)
then begin sod2;k:=false;break end;
end until keypressed else
if m=chr(od) then repeat begin
dc1;
inc(y);
dc2;
if k=false then break;
if (x=79) or (x=1) or (y=24) or (y=1)
then begin sod2;k:=false;break end;
end until keypressed else
if m=chr(ori) then repeat begin
dc1;
inc(x,2);
dc2;
if k=false then break;
if (x=79) or (x=1) or (y=24) or (y=1)
then begin sod2;k:=false;break end;
end until keypressed else
case m of
chr(72): repeat begin
dc1;
dec(y);
dc2;
if k=false then break;
if (x=79) or (x=1) or (y=24) or (y=1)
then begin sod2;k:=false;break end;
end until keypressed;
chr(75): repeat begin
dc1;
dec(x,2);
dc2;
if k=false then break;
if (x=79) or (x=1) or (y=24) or (y=1)
then begin sod2;k:=false;break end;
end until keypressed;
chr(80): repeat begin
dc1;
inc(y);
dc2;
if k=false then break;
if (x=79) or (x=1) or (y=24) or (y=1)
then begin sod2;k:=false;break end;
end until keypressed;
chr(77): repeat begin
dc1;
inc(x,2);
dc2;
if k=false then break;
if (x=79) or (x=1) or (y=24) or (y=1)
then begin sod2;k:=false;break end;
end until keypressed;
end;
end until k=false;
getdate(ye,mo,da,tim);
append(tsp);
str(d-1:4,st);
str(ye:4,yea);
str(mo:2,mon);
str(da:2,day);
str(tim:2,time);
st:=st+' '+day+'/'+mon+'/'+yea+' '+ten;
writeln(tsp,'/',st);
close(tsp);
textbackground(10);
clrscr;
textbackground(0);
textbackground(15);
textcolor(0);
gotoxy(34,10);
write(telex('Suaast sawsc!'));
gotoxy(32,11);
write(telex('Bajn cos '),d-1,telex(' ddieerm!'));
delay(1000);
repeat until keypressed;
textbackground(0);
textbackground(10);
repeat begin
clrscr;
gotoxy(33,12);
writeln(telex('Thuwr laji? (Y/N)'));
keypressed;
n:=readkey;
end until (n='y') or (n='n');
end until n='n' else
if ch='a' then repeat begin
clrscr;
gotoxy(36,2);
writeln(telex('Thafnh tisch'));
gotoxy(26,wherey);
writeln(telex('Ddieerm Thowfi gian Teen'));
assign(tsp,'RSM.inp');
reset(tsp);
textcolor(0);
j:=0;
while not eof(tsp) do begin
inc(j);
readln(tsp,st);
gotoxy(23,wherey);
writeln(j,'/',st);
end;
gotoxy(25,24);
writeln('Home (N)');
gotoxy(43,24);
writeln(telex('Xosa taast car (D)'));
repeat until keypressed;
ch:=readkey;
while (ch<>'n') and (ch<>'d') and (ch<>chr(13)) and (ch<>chr(27)) do begin
keypressed;
ch:=readkey;
end;
if ch='d' then begin
rewrite(tsp);
write('');
close(tsp);
end;
delay(50);
end until (ch='n') or (ch='d') or (ch=chr(13)) or (ch=chr(27)) else
if ch='s' then repeat begin
clrscr;
textbackground(10);
clrscr;
gotoxy(32,10);
write(telex('Ddieefu khieern:'));
gotoxy(37,11);
write('(U)');
gotoxy(37,12);
textbackground(7);
write('[',up,']');
gotoxy(34,13);
write('[',lef,']','[',dow,']','[',rig,']');
textbackground(10);
write(telex(' Ddawjt laji (A)'));
gotoxy(34,14);
write('(L)(D)(R)');
gotoxy(30,15);
if sou=true then write(telex('Aam thanh( S ) - Baajt -'))
else if sou=false then write(telex('Aam thanh( S ) - Tawst -'));
gotoxy(37,24);
write('Home (N)');
repeat until keypressed;
ch:=readkey;
while (ch<>'n') and (ch<>'s') and (ch<>chr(13)) and (ch<>chr(27)) and
(ch<>'u') and (ch<>'l') and (ch<>'d') and (ch<>'r') and (ch<>'a')
do begin
keypressed;
ch:=readkey;
end;
if ch='s' then
if sou=true then sou:=false else sou:=true
else if ch='a' then begin
up:='w';lef:='a';dow:='s';rig:='d';
end
else if ch='r' then begin
repeat begin
clrscr;
gotoxy(20,13);
write(telex('Chirnh suwra ddieefu khieern cura phism phari laf: '));
readln(ctrl);
end until (length(ctrl)=1) and (ctrl[1] in ['a'..'z','0'..'9']);
rig:=ctrl[1];
ori:=ord(rig);
end else
if ch='u' then begin
repeat begin
clrscr;
gotoxy(20,13);
write(telex('Chirnh suwra ddieefu khieern cura phism leen laf: '));
readln(ctrl);
end until (length(ctrl)=1) and (ctrl[1] in ['a'..'z','0'..'9']);
up:=ctrl[1];
ou:=ord(up);
end else
if ch='l' then begin
repeat begin
clrscr;
gotoxy(20,13);
write(telex('Chirnh suwra ddieefu khieern cura phism trasi laf: '));
readln(ctrl);
end until (length(ctrl)=1) and (ctrl[1] in ['a'..'z','0'..'9']);
lef:=ctrl[1];
ol:=ord(lef);
end else
if ch='d' then begin
repeat begin
clrscr;
gotoxy(20,13);
write(telex('Chirnh suwra ddieefu khieern cura phism duwowsi laf: '));
readln(ctrl);
end until (length(ctrl)=1) and (ctrl[1] in ['a'..'z','0'..'9']);
dow:=ctrl[1];
od:=ord(dow);
end;
delay(50);
end until (ch='n') or (ch=chr(13)) or (ch=chr(27));
end until (ch='e') or (ch=chr(27));
textbackground(0);
end.
 
Top Bottom