thieumao

Game Sao Băng

Apr 30th, 2013
2,454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.58 KB | None | 0 0
  1. {
  2. **
  3. * @(#) saobang.pas
  4. *
  5. * @author: Thieu Mao - KSEC (Coding Team - VHB)
  6. * @version: 1.00 01/05/2013
  7. **
  8. }
  9. program saobang;
  10. uses crt;
  11. var
  12.   ch: char;
  13.   x,y,m,xd,yd,diem: byte;
  14.   xuat:string;
  15.   move,kt:real;
  16. procedure dich;
  17. begin
  18.   repeat
  19.     xd:=random(79); yd:=random(24);
  20.   until (xd>0) and (yd>0);
  21.   gotoxy(xd,yd); write('@');
  22. end;
  23. begin
  24.   repeat
  25.     clrscr;
  26.     gotoxy(23,10);
  27.     write('Nhap so buoc ban muon di chuyen: '); readln(kt);
  28.   until (kt>0) and (kt<1000);
  29.   clrscr;
  30.   randomize;
  31.   x:=10;
  32.   y:=10;
  33.   move:=0;
  34.   diem:=0;
  35.   {x=80;y=25}
  36.   xuat:='*';
  37.   dich;
  38.   repeat
  39.     begin
  40.       {clrscr;}
  41.       if (x=xd) and (y=yd) then
  42.         begin
  43.           gotoxy(xd,yd); write(' ');
  44.           diem:=diem+1;
  45.           dich;
  46.         end;
  47.       gotoxy(x,y);
  48.       write(xuat);
  49.       gotoxy(1,1); write(move:3:0,' - ',diem); gotoxy(3,1);
  50.       {gotoxy(75,25);write(x:2,',',y:2);}
  51.       ch:=readkey;
  52.       move:=move+0.5;
  53.       gotoxy(x,y); write(' ');
  54.       if ord(ch)=72 then begin y:=y-1; if y<1  then y:=25; end;
  55.       if ord(ch)=80 then begin y:=y+1; if y>25 then y:=1;  end;
  56.       if ord(ch)=75 then begin x:=x-1; if x<1  then x:=80; end;
  57.       if ord(ch)=77 then begin x:=x+1; if x>80 then x:=1;  end;
  58.       {writeln(ch,' = ',ord(ch));}
  59.       if move=kt then
  60.         begin
  61.           clrscr;
  62.           gotoxy(23,10);
  63.           write('Sau ',move:3:0, ' buoc, so diem ban dat duoc: ',diem);
  64.           gotoxy(26,12);
  65.           write('Game over - Go Enter de thoat');
  66.           readln;
  67.           exit;
  68.         end;
  69.     end;
  70.   until ord(ch)=27;
  71. end.
Advertisement
Add Comment
Please, Sign In to add comment