Game tạo bằng ...Pascal!

K

kien_coi_1997

Last edited by a moderator:
K

kien_coi_1997

!!! Không thể compile trên FREE PASCAL !!!
Chỉ compile trên TP hay BP.
So với phiên bản trước EggCrt nhanh,mạnh hơn nhiều so với EggGames.
Có thể coi đây là EggGames 3.0.
Các bạn hãy để ý function SpecialKey(c:byte):boolean;
Tác dụng: đọc phím đặc biệt.
VD: SpecialKey(Ctrl+Alt)=true nếu ctrl và Alt đang ấn.
Để dùng hàm đó, yêu cầu phải viết:
const
rShift=1; lShift=2; Ctrl=4; Alt=8;
ScrLock=16; NumLock=32; CapsLock=64; Insert=128;
Mã:
Code EggCrt.PAS:
program EggCrt;
{==============   Can doc   ================}
{!!! Khong Compile duoc bang Free Pascal !!!}
{===========================================}
uses crt,dos;
const x1=5;y1=4;x2=77;y2=18;
rShift=1; lShift=2; Ctrl=4; Alt=8;
ScrLock=16; NumLock=32; CapsLock=64; Insert=128;
var EggX,EggY:byte;
    BedX:1..x2-9;
    Mark:byte;
    Lost:Byte;
    c,d:byte;
procedure writexy(x,y:byte;c:string);
begin gotoxy(x,y); write(c); end;
function SpecialKey(c:byte):boolean;
var regs:registers;
begin
Regs.AH:=2; Intr($16,Regs);
if Regs.AL and c = c then
SpecialKey:=True
else SpecialKey:=False;
end;
procedure vekhung(x1,y1,x2,y2:word);
var z,a,b:word;
begin
if (x1<>x2) and (y1<>y2) then
begin
a:=wherex; b:=wherey;
if x1>x2 then
begin z:=x1; x1:=x2; x2:=z; end;
if y1>y2 then
begin z:=y1; y1:=y2; y2:=z; end;
gotoxy(x1,y1); write(#201);
if x2-x1>1 then for z:=1 to x2-x1-1 do write(#205);
gotoxy(x2,y1); write(#187);
gotoxy(x1,y2); write(#200);
if x2-x1>1 then for z:=1 to x2-x1-1 do write(#205);
gotoxy(x2,y2); write(#188);
if y2-y1>1 then for z:=1 to y2-y1-1 do begin
gotoxy(x1,z+y1); write(#186); end;
if y2-y1>1 then for z:=1 to y2-y1-1 do begin
gotoxy(x2,z+y1); write(#186); end;
end;
gotoxy(a,b);
end;
procedure Drawmark;
begin
gotoxy(x1-1,y2+4); write('Mark: ',mark,'/10');
gotoxy(x1-1,y2+5); write('Lost: ',Lost,'/',mark+Lost);
end;
Procedure Delay(ms:word);
var t: longint; n:real;
begin n:=ms/1000;
t := meml[0:$46C];
repeat until meml[0:$46C] - t > n*18.2;
end;
procedure DrawEgg;
begin textcolor(yellow);
writexy(Eggx+x1,Eggy div 3 + y1-1,#32);
writexy(Eggx+x1,Eggy div 3 + y1,#9);
textcolor(white); end;
procedure DrawBed;
begin textcolor(brown);
writexy(Bedx+x1-2,y2,#32#32#177#177#177#177#177#177#177#177#177#32#32);
textcolor(white); end;
procedure init;
begin randomize;
vekhung(x1-3,y1-2,x2+2,y2+2);
vekhung(x1-3,y2+3,x1+15,24);
vekhung(x1+18,y2+3,x2+2,24);
writexy(x1+20,y2+4,'Dieu khien de trung roi vao o  Alt: Tam dung');
writexy(x1+20,y2+5,'Left/Right Shift: di chuyen    Ctrl: Di nhanh');
writexy(20,10,'An Alt de tiep tuc...');
repeat eggX:=random(60)+3; until specialkey(alt);
repeat until not specialkey(alt);
writexy(20,10,'                             ');
end;
BEGIN
textmode(co80); textcolor(white); clrscr; c:=30;
writexy(c,11,#75#32#32#75#32#73#32#69#69#69#69#32#78#32#32#78);
writexy(c,12,#75#32#75#32#32#73#32#69#32#32#32#32#78#78#32#78);
writexy(c,13,#75#75#32#32#32#73#32#69#69#69#32#32#78#32#78#78);
writexy(c,14,#75#32#75#32#32#73#32#69#32#32#32#32#78#32#32#78);
writexy(c,15,#75#32#75#32#32#73#32#69#69#69#69#32#78#32#32#78);
writexy(c,16,#45#45#45#45#45#45#45#45#45#45#45#45#45#45#45#45);
writexy(c,17,#67#32#79#32#73#32#95#32#49#32#57#32#57#32#55#32);
writexy(c,5,#71#97#109#101#32#72#117#110#103#32#84#114#117#110#103);
writexy(25,9,#66#97#110#32#113#117#121#101#110#58);
writexy(37,9,#107#105#101#110#95#99#111#105#95#49#57#57#55);
writexy(12,19,'Phong to cua so < Alt+Enter > de chat luong anh tot nhat');
textcolor(lightgray);
writexy(c,22,#76#32#79#32#65#32#68#32#73#32#78#32#71);
textcolor(yellow); gotoxy(c,22);
write(#76#32);delay(1000);
write(#79#32);delay(1000);
write(#65#32);delay(1000);
write(#68#32);delay(1000);
write(#73#32);delay(1000);
write(#78#32);delay(1000);
write(#71);delay(1000);
textcolor(white);
repeat
clrscr; mark:=0; Lost:=0;
init;bedx:=20;
for c:=1 to 10 do begin
Eggx:=random(60)+3; gotoxy(5,14+3);
write('                                                                 ');
for Eggy:=1 to 14*3 do begin
drawbed;
drawegg;
drawmark;
if specialkey(lshift) and (bedx>=1) then dec(bedx);
if specialkey(rshift) and (bedx+14<x2) then inc(bedx);
if specialkey(ctrl or lshift) and (bedx>=1) then dec(bedx);
if specialkey(ctrl or rshift) and (bedx+14<x2) then inc(bedx);
if specialkey(Alt) then
begin
repeat until not specialkey(alt);
writexy(20,10,'An Alt de tiep tuc...');
repeat until specialkey(alt);
repeat until not specialkey(alt);
writexy(20,10,'                             ');
drawegg; end;
if (Eggy=14*3) then
begin
 if abs(-BedX-4+Eggx)<4 then inc(Mark)
 else inc(Lost);
 writexy(Eggx+4,18,#32);
end;
delay(0);
end;
end;
gotoxy(20,7); write('So diem dat duoc: ',mark);
gotoxy(20,10); write('So trung bi rot: ',lost);
gotoxy(20,13); write('An Shift+Alt de tiep tuc, Ctrl+Alt de thoat');
repeat until specialKey(lshift+alt)
          or specialkey(ctrl+alt)
          or specialkey(rshift+alt);
until specialkey(Alt+Ctrl);
end.
 
Last edited by a moderator:
K

kien_coi_1997

Game luồn lách: Dùng các phím D A W để đi lên tầng cao hơn.

Code:

Mã:
program uptowin;
 uses crt;
 const dong=5; tocdo=1000;
 var
 memory:array[1..dong]of word;
 vt:shortint;thua,Qexit:boolean;x,y,z:word;{x,y,z la bien nhap}
 dem,key:byte;c:char;
 {_}
function wall(a:word;b:byte):boolean;
begin
b:=16-b;
if odd(a shr (b)) then wall:=true
else wall:=false;
end;
{_}
procedure vekhung(x1,y1,x2,y2:word);
var z,a,b:word;
begin
if (x1<>x2) and (y1<>y2) then
begin
a:=wherex; b:=wherey;
 if x1>x2 then
  begin z:=x1; x1:=x2; x2:=z; end;
 if y1>y2 then
  begin z:=y1; y1:=y2; y2:=z; end;
 gotoxy(x1,y1); write(#201);
 if x2-x1>1 then for z:=1 to x2-x1-1 do write(#205);
 gotoxy(x2,y1); write(#187);
 gotoxy(x1,y2); write(#200);
 if x2-x1>1 then for z:=1 to x2-x1-1 do write(#205);
 gotoxy(x2,y2); write(#188);
 if y2-y1>1 then for z:=1 to y2-y1-1 do begin
 gotoxy(x1,z+y1); write(#186); end;
 if y2-y1>1 then for z:=1 to y2-y1-1 do begin
 gotoxy(x2,z+y1); write(#186); end;
end;
gotoxy(a,b);
end;
function rand:word;
var a:word;b,c:byte;
begin
 b:=random(14)+1;
 for c:=1 to b do
 a:=a+ 1 shl (c-1);
 a:=a shl random(14);
 rand:=not a;
 if (a=0) or (not a=0) then a:=rand;
end;
 {_}
procedure run(x:boolean);
var e:byte;
{\}
 procedure traiphai(var a:word);
 var d:boolean;
 begin
  if odd(dem+e) then
  begin
   if a>maxint then
   begin d:=true;
   a:=a-maxint-1; end
   else d:=false;
   a:=a shl 1;
   if d then a:=a+1;
   if (wall(memory[1],vt)) then
   vt:=vt-1;
  end
  else
  begin
   if odd(a) then
   begin a:=a-1;
   d:=true; end
   else d:=false;
   a:=a shr 1;
   if d then a:=a+maxint+1;
   if (wall(memory[1],vt)) then
   vt:=vt+1;
  end;
 end;
{/}
begin
 for e:=1 to dong do
  if x and odd(e) then
    traiphai(memory[e])
  else if not x and not odd(e)then
    traiphai(memory[e]);
end;
 {_}
procedure draw;
var x,y:byte;
{\}
 procedure help;
 begin
 textcolor(white);
 vekhung(51,5,70,22);
 vekhung(8,5,25,22);
 textcolor(yellow);
 gotoxy(54,8);write('  W  : Up');
 gotoxy(54,11);write('  A  : Left');
 gotoxy(54,14);write('  D  : Right');
 gotoxy(54,17);write('  Space  : Pause');
 gotoxy(54,20);write('  Esc  : Exit');
 vekhung(54,7,58,9);
 vekhung(54,10,58,12);
 vekhung(54,13,58,15);
 vekhung(54,16,62,18);
 vekhung(54,19,60,21);
 gotoxy(9,6); write('Go up each floor');
 gotoxy(9,7); write(', you will add 1');
 gotoxy(9,8); write('bonus. But must');
 gotoxy(9,9); write('not passing wall');
 gotoxy(11,10); write('Example:');
 gotoxy(11,12); write('Can''t go up:');
 gotoxy(12,13);write(#219#32#219#219#32#219);
gotoxy(12,14);write(#205#205#205#205#205#205);
gotoxy(12,15);write('  ',#15,'   ');
gotoxy(12,17);write('Can go up:');
gotoxy(12,18);write(#219#32#219#219#32#219);
gotoxy(12,19);write(#205#205#205#205#205#205);
gotoxy(12,20);write(' ',#15,'   ');
 end;
{/}
begin
clrscr;
textcolor(white);
vekhung(20,1,60,3);
gotoxy(30,2); write('*** GO UP TO WIN! ***');
vekhung(28,5,47,22);
textcolor(yellow);
gotoxy(30,7);
writeln(#205#205#205#205#205#205#205#205,
        #205#205#205#205#205#205#205#205);
 for x:=dong downto 1 do
 begin
  gotoxy(30,8+(dong-x)*2);
  for y:=1 to 16 do
   if memory[x] shl (y-1)>maxint-1 then write(#219)
   else write(' ');
  writeln;
  gotoxy(30,8+(dong-x)*2+1);
  writeln(#205#205#205,
  #205#205#205#205#205#205#205,
  #205#205#205#205#205#205);
 end;
 help;
 gotoxy(30,20); write('Lines:',dem,' Key:',key,'/50');
 gotoxy(vt+29,16); write(#15);
end;
procedure pause;
begin
clrscr;
vekhung(15,10,65,15);
gotoxy(18,13);
write(' Paused! Press any key to continue...');
readkey;
end;
procedure thuchon;
begin{+3}
  c:=readkey;
    case upcase(c) of{+4}
    'D':if not wall(memory[1],vt+1) then vt:=vt+1;
    'A':if not wall(memory[1],vt-1) then vt:=vt-1;
    'W':if not wall(memory[2],vt) then begin{+5}
      dem:=dem+1;
      for z:= 1 to dong-1 do
      memory[z]:=memory[z+1];
      memory[dong]:=rand;
     end;{-5}
    ' ': pause;
    #27:begin
    qexit:=true;
    thua:=true;
    end;
    end;{-4}
    if upcase(c) in['D','A','W'] then
    begin key:=key+1; draw; end;
  if key=50 then thua:=true;
end;{-3}

{____Main Program____}
begin
textbackground(blue); textcolor(yellow); clrscr;
randomize;
vekhung(15,10,65,15);
gotoxy(18,13);
write('Press any key to continue...');
repeat x:=random(1); until keypressed;
window(1,1,80,25);
repeat
key:=0;thua:=false;Qexit:=false;
vt:=8;x:=0;clrscr;
for x:=2 to dong do
memory[x]:=rand;
repeat{+0}
draw;
for x:=0 to 1000 do
begin{+1}
if x=0 then
run(true);
if x=500 then
run(false);
 for y:=0 to tocdo do
 begin{+2}
  if keypressed then
  thuchon;
  if not (vt in[1..16]) then
  begin thua:=true; break; end;
 end;{-2}
 end;{-1}
until thua;
gotoxy(1,4);
for x:= 1 to 80*21 do
begin write(' ');
for y:=1 to 1000 do
for z:=1 to 600 do; end;
textcolor(white);
vekhung(15,11,65,15);
gotoxy(30,11); write(' Infomation ');
textcolor(yellow);
gotoxy(19,12); write('Score: ',dem);
if not qexit then
write('         You are lost!');
gotoxy(19,13); write('Press Enter or Esc to quit!');
gotoxy(19,14); write('Press Space to replay!');
repeat c:=readkey; until c in [#27,#13,#32];
until c in [#27,#13];
end.
 
Last edited by a moderator:
K

kien_coi_1997

Dùng phím mũi tên nghen

Mã:
 program GameXepHinh;
uses graph,crt;
var
 c,c1:char;
 x,y:shortint;dem,rd,z:word;
 lp,lp2:byte;  {lp2:dong,lp:cot}
 mau,maux:array[1..4,1..4]of shortint;
 Gd,Gm: Integer;
{____}
function mu(c,e:integer):integer;
var l1:integer;n:integer;
begin
n:=1;
if e>0 then
for l1:=1 to e do
n:=n*c;
mu:=n;
end;
{____}
procedure writedem(x,y:word);
var a,b:word;d:integer;
begin
 b:=dem;
 for d:=4 downto 0 do
 begin
  a:=b div (mu(10,d));
  case a of
   0: outtextxy(x+(4-d)*10,y,'0');
   1: outtextxy(x+(4-d)*10,y,'1');
   2: outtextxy(x+(4-d)*10,y,'2');
   3: outtextxy(x+(4-d)*10,y,'3');
   4: outtextxy(x+(4-d)*10,y,'4');
   5: outtextxy(x+(4-d)*10,y,'5');
   6: outtextxy(x+(4-d)*10,y,'6');
   7: outtextxy(x+(4-d)*10,y,'7');
   8: outtextxy(x+(4-d)*10,y,'8');
   9: outtextxy(x+(4-d)*10,y,'9');
   10: outtextxy(x+(4-d)*10,y,'10');
  end;
 b:=b mod mu(10,d);
 end;
end;
procedure hcn(x1,y1,x2,y2,mausac:word);
var loop:word;
begin
 setcolor(mausac);
 rectangle(x1,y1,x2,y2);
 for loop:=1 to y2-y1 do
 line(x1,y1+loop,x2,y1+loop);
end;
{_____}
procedure draw;
begin
 for lp:=1to 4do
  for lp2:=1 to 4 do
   hcn(50*(lp+7),50*(lp2),50*(lp+8),50*(lp2+1),maux[lp,lp2]);
   setcolor(15);
  rectangle(400,50,600,250);
  hcn(40+240,270,120+240,330,lightgray);
  setcolor(white);
  writedem(55+240,295);
  rectangle(45+240,275,115+240,325);
end;
{____}
procedure duoi;
var tmp:shortint;
begin
 if y>1 then
 begin
  tmp:=maux[x,y];
  maux[x,y]:=maux[x,y-1];
  maux[x,y-1]:=tmp;
  dem:=dem+1;
  y:=y-1;
 end;
end;
{____}
procedure tren;
var tmp:shortint;
begin
 if y<4 then
 begin
  tmp:=maux[x,y];
  maux[x,y]:=maux[x,y+1];
  maux[x,y+1]:=tmp;
  dem:=dem+1;
  y:=y+1;
 end;
end;
procedure phai;
var tmp:shortint;
begin
 if x>1 then
 begin
  tmp:=maux[x,y];
  maux[x,y]:=maux[x-1,y];
  maux[x-1,y]:=tmp;
  dem:=dem+1;
  x:=x-1;
 end;
end;
{____}
procedure trai;
var tmp:shortint;
begin
 if x<4 then
 begin
  tmp:=maux[x,y];
  maux[x,y]:=maux[x+1,y];
  maux[x+1,y]:=tmp;
  dem:=dem+1;
  x:=x+1;
 end;
end;
{ct chinh}
begin
 Gd := Detect; InitGraph(Gd, Gm,' ');
 if GraphResult <> grOk then Halt(1);
repeat
 cleardevice;
 dem:=0;
 {random}
 randomize;
 hcn(95,75,500,125,lightgray);
 setcolor(white);
 rectangle(100,80,495,120);
 Outtextxy(100,100,'           Nhan phim Enter de tiep tuc');
 repeat
 rd:=random(1000)+1;
 until keypressed;
 readln;
 cleardevice;
 {ve ket qua}
 for lp:=1to 4do
  for lp2:=1 to 4 do
  begin
  mau[lp,lp2]:=(lp-1)*4+(lp2); mau[4,4]:=0;
  hcn(50*(lp),50*(lp2),50*(lp+1),50*(lp2+1),mau[lp,lp2]);
  end; x:=4;y:=4; {x:cot,y:dong}
  setcolor(15);
  rectangle(50,50,250,250); {to vien}
 {gan maux = mau}
  for lp:=1 to 4 do
   for lp2:= 1 to 4 do
   maux[lp,lp2]:=mau[lp,lp2];
 {luat choi}
 OutTextXY(100,400,'Luat choi:');
 OutTextXY(100,420,'Ban hay an cac phim mui ten de xep hinh.');
 OutTextXY(105,430,'-   : Len tren');
 OutTextXY(105,440,'-   : Xuong duoi');
 OutTextXY(105,450,'-   : Sang trai');
 OutTextXY(105,460,'-   : Sang phai');
 OutTextXY(105,470,'- Esc : Thoat');
 outtextxy(120,430,#24);
 outtextxy(120,440,#25);
 outtextxy(120,450,#26);
 outtextxy(120,460,#27);
 {trao doi}
 repeat
 rd:=random(1000);
 if(rd mod 4 = 0) then tren;
 if(rd mod 4 = 1) then duoi;
 if(rd mod 4 = 2) then trai;
 if(rd mod 4 = 3) then phai;
 z:=z+1;
 until (z>200)and(x=4)and(y=4);
 dem:=0;draw;
 {bd choi}
 repeat
 c:=readkey;
 if c=#0 then
 begin
 c1:=readkey;
 if c1=#80 then duoi;
 if c1=#72 then tren;
 if c1=#75 then trai;
 if c1=#77 then phai;
 end;
 draw;
 z:=0;
 for lp:= 1 to 4 do
  for lp2:= 1 to 4 do
   if maux[lp,lp2]=mau[lp,lp2] then
    z:=z+1;
   if z=16 then c:=chr(27);
 until c=chr(27);
 {thang thua}
 if z=16 then
 begin
  cleardevice;
  hcn(30,40,600,110,lightgray);
  setcolor(white);
  rectangle(35,45,595,105);
  outtextxy(100,60,'Ban da thang voi ');
  writedem(235,60);
  outtextxy(245,60,'      lan di chuyen');
  outtextxy(100,80,'Nhan Esc de thoat hoac nhan Enter de tiep tuc');
  c:=readkey;
 end;
until c=chr(27);
CloseGraph;
end.
 
Last edited by a moderator:
  • Like
Reactions: Lăng Sóc
K

kien_coi_1997

Một lần nữa xin nhắc các bạn, háy nhớ ghi nguồn là http://vn.myblog.yahoo.com/kien_coi_1997
Muốn copy CODE nhanh, bạn hãy vào thủ thuật copy ở trang chính.

Cờ vua hai người
CODE Chess2p.PAS:

Mã:
uses crt,dos; {http://vn.myblog.yahoo.com/kien_coi_1997}
type
quan=(k,xeD,maD,tuongD,hauD,vuaD,totD,
           xeT,maT,tuongT,hauT,vuaT,totT);
nguoi=(Trang,Den);
mType=array[1..8,1..8]of quan;
his=record
xh1,yh1,xh2,yh2:0..8;
Old:quan;dirh:0..3;
end;
const xStart=2; yStart=1; Player:nguoi=trang;
{den:darkgray;trang:white}
New:mType=            ((xeT,MaT,TuongT,HauT,VuaT,TuongT,MaT,XeT)
                          ,(totT,totT,totT,totT,totT,totT,totT,totT)
                          ,(k,k,k,k,k,k,k,k),(k,k,k,k,k,k,k,k)
                          ,(k,k,k,k,k,k,k,k),(k,k,k,k,k,k,k,k)
                          ,(totD,totD,totD,totD,totD,totD,totD,totD)
                          ,(xeD,MaD,TuongD,HauD,VuaD,TuongD,MaD,XeD));
function mouseinstalled:boolean; assembler; asm
xor ax,ax; int 33h; cmp ax,-1; je @skip; xor al,al; @skip: end;

function getmousex:word; assembler; asm
mov ax,3; int 33h; mov ax,cx end;

function getmousey:word; assembler; asm
mov ax,3; int 33h; mov ax,dx end;

function leftpressed:boolean; assembler; asm
mov ax,3; int 33h; and bx,1; mov ax,bx end;

function rightpressed:boolean; assembler; asm
mov ax,3; int 33h; and bx,2; mov ax,bx end;

procedure mousesensetivity(x,y:word); assembler; asm
mov ax,1ah; mov bx,x; mov cx,y; xor dx,dx; int 33h end;

function mouserange(x1,y1,x2,y2:word):boolean;
begin
if        (getmousex div 8>=x1)
      and (getmousex div 8<=x2)
      and (getmousey div 8>=y1)
      and (getmousey div 8<=y2)
then mouserange:=true
else mouserange:=false;
end;

function getmousexcrt:word;
begin
getmousexcrt:=trunc(getmousex/8+1);
end;

function getmouseycrt:word;
begin
getmouseycrt:=trunc(getmousey/8+1);
end;

procedure vekhung(x1,y1,x2,y2:word);
var z,a,b:word;
begin
if (x1<>x2) and (y1<>y2) then
begin
a:=wherex; b:=wherey;
 if x1>x2 then
  begin z:=x1; x1:=x2; x2:=z; end;
 if y1>y2 then
  begin z:=y1; y1:=y2; y2:=z; end;
 gotoxy(x1,y1); write(#201);
 if x2-x1>1 then for z:=1 to x2-x1-1 do write(#205);
 gotoxy(x2,y1); write(#187);
 gotoxy(x1,y2); write(#200);
 if x2-x1>1 then for z:=1 to x2-x1-1 do write(#205);
 gotoxy(x2,y2); write(#188);
 if y2-y1>1 then for z:=1 to y2-y1-1 do begin
 gotoxy(x1,z+y1); write(#186); end;
 if y2-y1>1 then for z:=1 to y2-y1-1 do begin
 gotoxy(x2,z+y1); write(#186); end;
end;
gotoxy(a,b);
end;
procedure RangeMouse(x1,y1,x2,y2:word);
var regs:registers;
begin
Regs.AX:=7; Regs.CX:=x1; Regs.DX:=x2;
Intr($33,Regs);
Regs.AX:=8; Regs.CX:=y1; Regs.DX:=y2;
Intr($33,Regs);
end;
var x1,y1,x2,y2:byte;
    xMove1,yMove1,xMove2,yMove2:byte;
    Moving:boolean;c:char;
    History:array[1..4]of his;
    dir:0..3;m:mtype;
function Lawful(x1,y1,x2,y2:byte):boolean;
var z:quan;
function NotBlock(x1,y1,x2,y2:byte):boolean;
var c,d:byte;
begin
NotBlock:=true;c:=0;d:=0;
if m[x2,y2]=k then
d:=1;
if (x1>x2)and(y1=y2) then
begin c:=x1; x1:=x2; x2:=c; end;
if (y1>y2)and(x1=x2) then
begin c:=y1; y1:=y2; y2:=c; end;
if x1=x2 then
begin
 for c:= y1 to y2 do
 if m[x1,c]<>k then
 d:=d+1;
end;
if y1=y2 then
begin
 for c:= x1 to x2 do
 if m[c,y1]<>k then d:=d+1;
end;
if abs(x2-x1)=abs(y2-y1) then
begin
if x1<x2 then
 for c:= x1 to x2 do
 begin
  if y1<y2 then
  if m[c,c+y1-x1]<>k then
  d:=d+1;
  if y1>y2 then
  if m[c,x2+y2-c]<>k then
  d:=d+1;
 end;
if x1>x2 then
 for c:= x2 to x1 do
 begin
 if y1<y2
  if m[c,x2+y2-c]<>k then
  d:=d+1;
 if y1>y2 then
  if m[c,c+y2-x2]<>k then
  d:=d+1;
 end;
end;
if d>2then
notblock:=false;
end;
begin
z:=m[x1,y1]; textbackground(black);
gotoxy(68,7); write('             ');
gotoxy(75,5); write('      ');
if ((m[x1,y1]in[xeD..totD])and(m[x2,y2]in[xeT..totT])
 or (m[x1,y1]in[xeT..totT])and(m[x2,y2]in[xeD..totD])
 or (m[x2,y2]=k)) and ((x1<>x2)or(y1<>y2)) then
case z of
xeT,xeD:        Lawful:=((x1=x2)xor(y1=y2))and NotBlock(x1,y1,x2,y2);
maT,maD:        lawful:=(abs(x1-x2)+abs(y1-y2)=3)and(x1<>x2)and(y1<>y2);
tuongT,tuongD:  Lawful:=(abs(x2-x1)=abs(y2-y1))and NotBlock(x1,y1,x2,y2);
hauT,hauD:      Lawful:=(((x1=x2)or(y1=y2))or(abs(x2-x1)=abs(y2-y1)))
                         and NotBlock(x1,y1,x2,y2);
vuaT,vuaD:      Lawful:=(abs(x2-x1)<2)and(abs(y2-y1)<2)
                         and((x1<>x2)or(y1<>y2));
totT:           Lawful:=(((dir=0)and(x2-x1=1)and(y1=y2)
                     or (x2-x1=1)and(abs(y1-y2)=1)and(m[x2,y2]<>k)
                     or (x2-x1=2)and(x1=2)and(y1=y2))
                     or ((dir=1)and(y2-y1=1)and(x1=x2)
                     or (y2-y1=1)and(abs(x1-x2)=1)and(m[x2,y2]<>k)
                     or (y2-y1=2)and(y1=2)and(x1=x2))
                     or ((dir=2)and(x1-x2=1)and(y1=y2)
                     or (x1-x2=1)and(abs(x1-x2)=1)and(m[x2,y2]<>k)
                     or (x1-x2=2)and(x1=7)and( y1=y2))
                     or ((dir=3)and(y1-y2=1)and(x1=x2)
                     or (y1-y2=1)and(abs(x1-x2)=1)and(m[x2,y2]<>k)
                     or (y1-y2=2)and(y1=7)and(x1=x2)))
                     and notblock(x1,y1,x2,y2);
totD:           Lawful:=(((dir=2)and(x2-x1=1)and(y1=y2)
                     or (x2-x1=1)and(abs(y1-y2)=1)and(m[x2,y2]<>k)
                     or (x2-x1=2)and(x1=2)and(y1=y2))
                     or ((dir=3)and(y2-y1=1)and(x1=x2)
                     or (y2-y1=1)and(abs(x1-x2)=1)and(m[x2,y2]<>k)
                     or (y2-y1=2)and(y1=2)and(x1=x2))
                     or ((dir=0)and(x1-x2=1)and(y1=y2)
                     or (x1-x2=1)and(abs(x1-x2)=1)and(m[x2,y2]<>k)
                     or (x1-x2=2)and(x1=7)and(y1=y2))
                     or ((dir=1)and(y1-y2=1)and(x1=x2)
                     or (y1-y2=1)and(abs(x1-x2)=1)and(m[x2,y2]<>k)
                     or (y1-y2=2)and(y1=7)and(x1=x2)))
                     and notblock(x1,y1,x2,y2);

end else begin Lawful:=false;
gotoxy(68,7);textcolor(lightred);textbackground(Red);
write('!QuanCungMau'); end;
if not notblock(x1,y1,x2,y2) then
begin gotoxy(75,5);textcolor(lightred);
textbackground(Red);write('! Can'); end;

end;

procedure clearCell(x,y,z:byte);
begin
if z =0 then
if odd(x+y) then textcolor(black)
else textcolor(lightgray)
else textcolor(z);
gotoxy(x*8-8+xStart,y*3-3+yStart);
write(#219,#219,#219,#219,#219,#219,#219,#219);
gotoxy(x*8-8+xStart,y*3-3+yStart+1);
write(#219,#219,#219,#219,#219,#219,#219,#219);
gotoxy(x*8-8+xStart,y*3-3+yStart+2);
write(#219,#219,#219,#219,#219,#219,#219,#219);
textcolor(white);
end;
procedure qXe(x,y,z,b:byte);
begin

textcolor(z);
if b>0 then textbackground(b)
else if odd(x+y+1) then textbackground(white)
else textbackground(black);



gotoxy(x*8-8+xStart,y*3-3+yStart);
write(#32,#219,#32,#219,#32,#219,#32,#32);
gotoxy(x*8-8+xStart,y*3-3+yStart+1);
write(#32,#32,#178,#178,#178,#32,#32,#32);
gotoxy(x*8-8+xStart,y*3-3+yStart+2);
write(#32,#219,#219,#219,#219,#219,#32,#32);
end;
procedure qMa(x,y,z,b:byte);
begin

textcolor(z);
if b>0 then textbackground(b)
else if odd(x+y+1) then textbackground(white)
else textbackground(black);
gotoxy(x*8-8+xStart,y*3-3+yStart);
write(#32,#222,#223,#219,#220,#32,#32,#32);
gotoxy(x*8-8+xStart,y*3-3+yStart+1);
write(#32,#32,#222,#219,#219,#221,#32,#32);
gotoxy(x*8-8+xStart,y*3-3+yStart+2);
write(#32,#32,#219,#219,#219,#219,#32,#32);
end;
procedure qTot(x,y,z,b:byte);
begin

textcolor(z);
if b>0 then textbackground(b)
else if odd(x+y+1) then textbackground(white)
else textbackground(black);
gotoxy(x*8-8+xStart,y*3-3+yStart);
write(#32,#32,#32,#32,#254,#32,#32,#32);
gotoxy(x*8-8+xStart,y*3-3+yStart+1);
write(#32,#32,#32,#40,#42,#41,#32,#32);
gotoxy(x*8-8+xStart,y*3-3+yStart+2);
write(#32,#32,#220,#219,#219,#219,#220,#32);
end;
procedure qTuong(x,y,z,b:byte);
begin

textcolor(z);
if b>0 then textbackground(b)
else if odd(x+y+1) then textbackground(white)
else textbackground(black);


gotoxy(x*8-8+xStart,y*3-3+yStart);
write(#32,#32,#32,#234,#32,#32,#32,#32);
gotoxy(x*8-8+xStart,y*3-3+yStart+1);
write(#32,#32,#222,#254,#221,#32,#32,#32);
gotoxy(x*8-8+xStart,y*3-3+yStart+2);
write(#32,#220,#219,#219,#219,#220,#32,#32);
end;
procedure qVua(x,y,z,b:byte);
begin

textcolor(z);
if b>0 then textbackground(b)
else if odd(x+y+1) then textbackground(white)
else textbackground(black);
gotoxy(x*8-8+xStart,y*3-3+yStart);
write(#32,#47,#92,#32,#42,#32,#47,#92);
gotoxy(x*8-8+xStart,y*3-3+yStart+1);
write(#32,#92,#32,#221,#254,#222,#32,#47);
gotoxy(x*8-8+xStart,y*3-3+yStart+2);
write(#32,#32,#219,#219,#42,#219,#219,#32);
end;
procedure qHau(x,y,z,b:byte);
begin

textcolor(z);
if b>0 then textbackground(b)
else if odd(x+y+1) then textbackground(white)
else textbackground(black);
gotoxy(x*8-8+xStart,y*3-3+yStart);
write(#95,#46,#61,#42,#42,#61,#46,#95);
gotoxy(x*8-8+xStart,y*3-3+yStart+1);
write(#92,#92,#30,#30,#30,#30,#47,#47);
gotoxy(x*8-8+xStart,y*3-3+yStart+2);
write(#32,#176,#177,#178,#178,#177,#176,#32);
end;
{còn nữa, vì bị giới hạn số lượng nên chia làm 2 part }
 
K

kien_coi_1997

{Đây là part 2 của cái trên, ghếp lại bạn nhe}

Mã:
procedure Draw(x,y,z:byte);
procedure ex(k0:byte);
begin
case m[x,y] of
 xeT:qxe(x,y,white,k0);
 maT:qMa(x,y,white,k0);
 tuongT:qTuong(x,y,white,k0);
 HauT:qHau(x,y,white,k0);
 VuaT:qVua(x,y,white,k0);
 TotT:qTot(x,y,white,k0);
 (*_*)
 xeD:qxe(x,y,darkgray,k0);
 maD:qMa(x,y,darkgray,k0);
 TuongD:qTuong(x,y,darkgray,k0);
 HauD:qHau(x,y,darkgray,k0);
 VuaD:qVua(x,y,darkgray,k0);
 TotD:qTot(x,y,darkgray,k0);
 k:clearcell(x,y,z);
 end;
end;
begin
if x+y=0 then
for x:=1 to 8 do
 for y:=1 to 8 do
 ex(0);
if x+y>1 then ex(z);
end;
procedure Rotate;
var c,d:byte;
t:mtype;
begin
 for c:=1 to 8 do
  for d:=1 to 8 do
  t[c,d]:=m[d,9-c];
m:=t;draw(0,0,0);
end;
procedure Shift(xuong:boolean);
var c:byte;
begin
if xuong then
for c:=2 to 4 do
history[c]:=history[c-1]
else for c:=1 to 3 do
history[c]:=history[c+1];
end;
procedure Update;
var c,d:byte;
begin
shift(true);
with history[1] do
begin
 xh1:=xMove1; yh1:=yMove1;
 xh2:=xMove2; yh2:=yMove2;
 Old:=m[xMove2,yMove2];
 dirh:=dir;
end;
inc(player);
end;
procedure Undo;
begin
if history[1].xh1+history[1].yh1=0 then exit;
if (4-history[1].dirh+dir)mod 4=1 then begin rotate; rotate; rotate; end;
if (4-history[1].dirh+dir)mod 4=2 then begin rotate; rotate;         end;
if (4-history[1].dirh+dir)mod 4=3 then begin rotate;                 end;
dir:=history[1].dirh;
m[history[1].xh1,history[1].yh1]
   :=m[history[1].xh2,history[1].yh2];
m[history[1].xh2,history[1].yh2]:=history[1].Old;
draw(0,0,0); shift(false); inc(player);
end;

procedure NewGame;
var x,y:byte;
begin
m:=new;player:=trang;
textcolor(lightgreen); textbackground(black); clrscr;
gotoxy(70,3);write('CHESS 2p');
gotoxy(70,10);write(#67#111#112#121#32#102#114#111#109#58);
Gotoxy(68,11);write(#75#105#101#110#95#99#111#105#95#49#57#57#55);
gotoxy(68,15);write(#27#58#82#111#116#97#116#101#32,'-90');
gotoxy(68,16);write(#25#58#82#111#116#97#116#101#32,'180');
gotoxy(68,17);write(#26#58#82#111#116#97#116#101#32,'+90');
gotoxy(68,19);write(#67#116#114#108#43#90#58#32#85#110#100#111);
gotoxy(68,20);write(#67#116#114#108#43#78#58#32#78#101#119);
gotoxy(68,21);write(#82#67#108#105#99#107#58#32#69#120#105#116);
{Cells}
for x:=1 to 8 do
 for y:=1 to 8 do
 clearcell(x,y,0);
{H}
gotoxy(2,25);
for x:=1 to 64 do
if x mod 8 = 4 then
begin
textcolor(darkgray);
textbackground(white);
write(chr(x div 8 + 65));
textcolor(white);
textbackground(black);
end else
write(#219);
{V}
for y:=1 to 25 do
begin
gotoxy(1,y);
if y mod 3 = 2 then
begin
textcolor(darkgray);
textbackground(white);
write(y div 3 + 1);
textcolor(white);
textbackground(black);
end else write(#219);
gotoxy(66,y);
write(#219);
end;
draw(0,0,0);
end;
(*_*)(*_*)
begin
clrscr;
NewGame;
RangeMouse(8,8,511,191);
repeat
x2:=x1; y2:=y1;
x1:=(getmousexcrt-1) div 8 +1;
y1:=(getmouseycrt-1) div 3 +1;
if leftpressed then
 if (x1>0) and (y1>0) and (x1<=8) and (y1<=8) then
 begin
 if not moving then
 begin
  xMove1:=x1; yMove1:=y1;
  draw(xMove2,yMove2,0);
  draw(xMove1,yMove1,1);
  moving:=true;
 end
 else
 begin
  xMove2:=x1; yMove2:=y1; update;
  if lawful(xMove1,yMove1,xMove2,yMove2) then
  begin
  m[xMove2,yMove2]:=m[xMove1,yMove1];
  m[xMove1,yMove1]:=k;
  draw(xMove1,yMove1,0);
  draw(xMove2,yMove2,6);
  end else draw(xMove1,yMove1,0);
  inc(player);
  moving:=false;
 end;
 repeat until not leftpressed;
 end;
if (x2>0) and (y2>0) and (x2<=8) and (y2<=8) then
if not (moving and (x1=xMove1) and (y1=ymove1)) then draw(x2,y2,0);
if (x1>0) and (y1>0) and (x1<=8) and (y1<=8) then
if not (moving and (x1=xMove1) and (y1=ymove1))then draw(x1,y1,10);
if not moving and (xMove2>0) and
   (x1<>xMove2) and (y1<>yMove2) then draw(xMove2,yMove2,6);
if keypressed then
begin c:=readkey;
 if c=#0 then
  begin
  c:=readkey;
  case c of
  'P':begin rotate;rotate;              dir:=(dir+2)mod 4; end;
  'K':begin rotate;rotate;rotate;       dir:=(dir+3)mod 4; end;
  'M':begin rotate;                     dir:=(dir+1)mod 4; end;
  end;
  end else if c=#26 then undo
      else if c=#14 then newgame;
end;
repeat until ((getmousexcrt-1) div 8 +1<>x1)
         or ((getmouseycrt-1) div 3 +1<>y1)
         or rightpressed or leftpressed or keypressed;
until rightpressed;
rangemouse(1,1,639,199);
end.
[ Nguồn http://vn.myblog.yahoo.com/kien_coi_1997 ]
 
K

kien_coi_1997

Mới có Cải Tiến... Game Rút cờ.
Dùng bàn phím số nghe bạn. Game này hình như trên ti vi có rồi, tên ban đầu hình như là Búc tường lửa.
Nhập vào số quân cần xoá ( nhỏ hơn Max và lớn hơn 0 ). Ai xoa cuối cùng thì người đó thắng.
CODE Clear.pas :

Mã:
uses crt; const sx=5; sy=5;
var count,max,n:byte; x,y:byte; c:char;
{ NEU DUNG TP THI COPY TU DAY DEN EEEEEEEEEEEE}
Procedure Delay(ms:word);
var t: longint; n:real;
begin n:=ms/1000;
t := meml[0:$46C];
repeat until meml[0:$46C] - t > n*18.2;
end;
{EEEEEEEEEEEEEE NEU DUNG FP THI XOA DI}
procedure vekhung(x1,y1,x2,y2:word);
var z,a,b:word;
begin
if (x1<>x2) and (y1<>y2) then
begin
a:=wherex; b:=wherey;
 if x1>x2 then
  begin z:=x1; x1:=x2; x2:=z; end;
 if y1>y2 then
  begin z:=y1; y1:=y2; y2:=z; end;
 gotoxy(x1,y1); write(#201);
 if x2-x1>1 then for z:=1 to x2-x1-1 do write(#205);
 gotoxy(x2,y1); write(#187);
 gotoxy(x1,y2); write(#200);
 if x2-x1>1 then for z:=1 to x2-x1-1 do write(#205);
 gotoxy(x2,y2); write(#188);
 if y2-y1>1 then for z:=1 to y2-y1-1 do begin
 gotoxy(x1,z+y1); write(#186); end;
 if y2-y1>1 then for z:=1 to y2-y1-1 do begin
 gotoxy(x2,z+y1); write(#186); end;
end;
gotoxy(a,b);
end;
procedure draw;
var i:byte;
begin
window(sx,sy,sx+15,sy+16);
if count>0 then
for i:=1 to count do
write('þ');
for i:=count+1 to 255 do write('.'); write('.');
window(1,1,80,25);
gotoxy(sx+25,sy); write('Max: ',max:7);
gotoxy(sx+25,sy+1); write('Count: ',count:5);
gotoxy(sx+25+20,sy); write('Nuoc truoc cua ban: ',x:5);
gotoxy(sx+25+20,sy+1); write('Nuoc truoc cua may: ',y:5);
end;
procedure clear(m:byte);
begin
if m=0 then m:=random(max-1)+1;
begin y:=m; count:=count-m; end;
end;

Procedure New;
begin
repeat
count:=random(250)+5; draw; delay(100);
max:=random(count div 3)+count div 6;
until keypressed; while keypressed do readkey;
end;

begin
repeat
textcolor(Yellow); textbackground(Brown); clrscr;
vekhung(Sx-2,sy-2,sx+18,sy+18);
vekhung(sx+22,sy-2,sx+39,sy+3);
vekhung(sx+42,sy-2,80-2,sy+3);
vekhung(sx+22,sy+5,80-2,sy+9);
vekhung(sx+22,sy+11,80-2,sy+18);
gotoxy(30,1); write(#71#97#109#101#32#88#111#97#32#67#111);
gotoxy(15,25); write(#66#97#110#32#81#117#121#101#110#58#32,
#107#105#101#110#95#99#111#105#95#49#57#57#55,
#64#121#97#104#111#111#46#99#111#109#46#118#110);
gotoxy(sx+25,sy+13); write('Xoa mot so quan ( 0 < n < MAX ).');
gotoxy(sx+25,sy+15); write('Ai xoa cuoi cung nguoi do thang.');
gotoxy(sx+25,sy+7);
write('Press any key to start'); New; draw;
repeat
 repeat
  gotoxy(sx+25,sy+7); write('Nhap so quan can xoa: ');
  readln(n); gotoxy(sx+25,sy+7); write('':30);
  if (n>max) or (n=0) then
  begin gotoxy(sx+25,sy+7); write('':30); end;
  if (n>max) or (n=0) then
  begin gotoxy(sx+25,sy+7); write('Loi! 0<n<MAX.Hit a key'); readkey; end;
 until (n<=max) and (n>0); x:=n; clear(n); draw;
if count=0 then begin gotoxy(sx+25,sy+7);
write('Ban da thang! Hit a key '); draw;
readkey; gotoxy(sx+25,sy+7);
write('[ ESC ] : Quit  [ Any key ] : Replay');
c:=readkey; end
else begin if count<=max then begin
gotoxy(sx+25,sy+7); write('A n a l y z i n g...'); delay(500);
y:=count; clear(y); end
else begin gotoxy(sx+25,sy+7); write('A n a l y z i n g...'); delay(500);
y:=count mod (max+1); clear(y); end;
draw; if count=0 then begin draw; gotoxy(sx+25,sy+7);
write('Ban da thua! Hit a key '); draw;
readkey; gotoxy(sx+25,sy+7);
write('[ ESC ] : Quit  [ Any key ] : Replay');
c:=readkey; end; end;
until count=0;
until c=#27;
end.
 
  • Like
Reactions: Lăng Sóc
T

tear_viem_tear

cho hỏi, Free Pascal ko ctrl+F9 đc a`k ??? dzỵ thj` khô~ wá -.=''

p/s: ghê ta, kùng sjnh năm 97 màk seo tui gà hơn ôg nhju` wá taz :D tuj chưa dzjết games, tạj ko nghj~ ra j` hjk :D
 
Top Bottom