Pascal

Modified: Wednesday, 22-12-2021 07:00 AM

Game Flappy Bird chạy Console trong Pascal
Code của Tống Hoàng Vũ 
Còn một số Bug nhưng không đáng kể. Chủ yếu là hiểu hơn một số lệnh trong Pascal và cho thấy sự mạnh mẽ của ngôn ngữ Pascal.



uses crt,windows,sysutils;
var
i,x,y,n,vt,xx,yy:byte;
c:char;
score:longint;
procedure tuong(c:char;vt,n1,n,n2:byte);
var
i:byte;
s:string;
begin
    gotoxy(vt,1);
    for i:=1 to n1 do
        write(c+#10+#8);
    gotoxy(vt,1+n1+n);
    for i:=1 to n2 do
        write(c+#10+#8);
end;
procedure bird(c:char;xx,yy:byte);
begin
    textcolor(10);
    gotoxy(xx,yy);
    write(c);
    textcolor(15);
end;
procedure lose(score:longint);
begin
    clrscr;
    textcolor(10);
    writeln(' You lose !');
    textcolor(15);
    writeln(' Your score: ',score);
    repeat
        c:=readkey;
        if c=#13 then halt;
    until false;
end;
procedure freshscore(score:longint);
begin
    gotoxy(3,28);
    textcolor(10);
    write('Score: ');
    textcolor(15);
    write(score);
end;
procedure win;
begin
    clrscr;
    textcolor(10);
    writeln(' You win');
    textcolor(15);
    writeln(' Your have a best score, ',score);
    repeat
        c:=readkey;
        if c=#13 then halt;
    until false;
end;
begin
    clrscr;
    ExecuteProcess('cmd','/c mode con: cols=60 lines=35');
    textcolor(15);
    cursoroff;
    randomize;
    messagebox(0,'Nhan phim cach de nhay, nhan Esc de thoat','Huong dan',mb_ok);
    score:=0;
    xx:=1;
    yy:=10;
    bird('',xx,yy);
    repeat
        freshscore(score);
        x:=random(14);
        n:=6+score div 4;
        y:=26-x-n;
        vt:=50;
        repeat
            dec(vt);
            tuong('#',vt,x,n,y);
            tuong(' ',vt+1,x,n,y);
            inc(yy);
            if yy=27 then
                lose(score);
            bird('',xx,yy);
            bird(' ',xx,yy-1);
            delay(80-4*score);
            if keypressed then
            begin
                c:=readkey;
                if (c=' ') and (yy-(n-4)>=0) then
                begin
                    yy:=yy-(n-4);
                    bird('',xx,yy);
                    bird(' ',xx,yy+(n-4));
                end;
            end;
        until (vt=1) or (c=#27);
        if yy in [x+1..x+n] then
            else
            lose(score);
        if score=15 then
            win;
        tuong(' ',1,x,n,y);
        inc(score);
    until c=#27;
end.