Tin học Game Cờ Vua viết bằng Pascal

trà nguyễn hữu nghĩa

Cựu Mod Vật Lí |Cây bút Thơ|Thần tượng VH
Thành viên
14 Tháng năm 2017
3,974
7,623
744
22
Phú Yên
Trường THPT Lương Văn Chánh

lâm tùng apollo

Cựu Mod Địa | PCN CLB Địa Lí
Thành viên
26 Tháng ba 2018
1,170
3,210
371
19
Shurima
Thái Nguyên
THPT LƯƠNG NGỌC QUYẾN
Ăn được quân Vua là thắng nha :p không cần phải chiếu hết.
View attachment 56260

Code đây nhá (Phải có thư viện Graph và phải dùng TP mới được):

Mã:
 Program Co_Vua;
 uses crt,graph,dos;

 const _KT = 50;
       Q_Vua = 0;
       Q_Hau = 1;
       Q_Tuong = 2;
       Q_Ma = 3;
       Q_Xe = 4;
       Q_Tot = 5;
       Q_Khong =  6;

       T_Trong = 0;
       T_Vao = 1;
       T_ChuanBi = 2;
       T_QuanCo = 3;
       T_Chon = 4;

 type TOCo = record
                   QuanCo: integer;
                   TuThe: integer;
                   MauO,MauCo: Word;
                   X,Y: integer;
             end;

 var gd,gm: integer;
     MX,MY: integer;
     OCo: array[-2..7,-2..7] of TOCo;
     LaOCo,OChon : TOCo;
     DangChon,EndGame: Boolean;
     Luot: integer;

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

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

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

 function MouseArea(x1,y1,x2,y2:word):boolean;
 begin
 if     (LeftClick)
        and (mousex >=x1)
        and (mousex <=x2)
        and (mousey >=y1)
        and (mousey <=y2)
 then mousearea:=true
 else mousearea:=false;
 end;

 Function InitMouse : boolean;
 var r: registers;
 Begin
 r.ax:=$00;intr($33,r);
 if r.ax<>0 then InitMouse:=true
 else InitMouse:=false;
 End;

 Procedure ShowMouse;
 Var r: registers;
 begin
 r.ax:=$01;intr($33,r);
 End;

 Procedure HideMouse;
 Var r:registers;
 Begin
 r.ax:=$002;
 intr($33,r);
 End;

 Procedure VeQuanVua(X,Y,Mau: integer);
 Begin
           Line(X,Y+48,X+30,Y+48);
           Line(X,Y+48,X+7,Y+24);
           Line(X+30,Y+48,X+23,Y+24);
           Line(X+7,Y+24,X,Y+24);
           Line(X+23,Y+24,X+30,Y+24);
           Line(X,Y+24,X,Y+21);
           Line(X+30,Y+24,X+30,Y+21);
           Line(X,Y+21,X+7,Y+21);
           Line(X+30,Y+21,X+23,Y+21);
           Line(X+7,Y+21,X,Y+16);
           Line(X+23,Y+21,X+30,Y+16);
           Line(X,Y+16,X+12,Y+16);
           Line(X+30,Y+16,X+18,Y+16);
           Line(X+12,Y+16,X+12,Y+10);
           Line(X+18,Y+16,X+18,Y+10);
           Line(X+12,Y+10,X+8,Y+10);
           Line(X+18,Y+10,X+22,Y+10);
           Line(X+8,Y+10,X+8,Y+6);
           Line(X+22,Y+10,X+22,Y+6);
           Line(X+8,Y+6,X+12,Y+6);
           Line(X+22,Y+6,X+18,Y+6);
           Line(X+12,Y+6,X+12,Y+3);
           Line(X+18,Y+6,X+18,Y+3);
           Line(X+12,Y+3,X+18,Y+3);
           CirCle(X+15,Y+22,3);
           FloodFill(X+15,Y+28,Mau);
 End;

 Procedure VeQuanHau(X,Y,Mau: integer);
 Begin
           Line(X,Y+48,X+30,Y+48);
           Line(X,Y+48,X+7,Y+24);
           Line(X+30,Y+48,X+23,Y+24);
           Line(X+7,Y+24,X,Y+24);
           Line(X+23,Y+24,X+30,Y+24);
           Line(X,Y+24,X,Y+21);
           Line(X+30,Y+24,X+30,Y+21);
           Line(X,Y+21,X+7,Y+21);
           Line(X+30,Y+21,X+23,Y+21);
           Line(X+7,Y+21,X,Y+16);
           Line(X+23,Y+21,X+30,Y+16);
           Line(X,Y+16,X+15,Y+10);
           Line(X+30,Y+16,X+15,Y+10);
           Line(X+15,Y+10,X+15,Y+3);
           FloodFill(X+15,Y+28,Mau);
 End;

 Procedure VeQuanTuong(X,Y,Mau: integer);
 Begin
           Line(X,Y+48,X+30,Y+48);
           Line(X,Y+48,X+7,Y+35);
           Line(X+30,Y+48,X+23,Y+35);
           Line(X+7,Y+35,X+7,Y+16);
           Line(X+23,Y+35,X+23,Y+16);
           Line(X+7,Y+16,X+15,Y+6);
           Line(X+23,Y+16,X+15,Y+6);
           FillEllipse(X+15,Y+4,2,2);
           Line(X+7,Y+21,X+17,Y+9);
           FloodFill(X+15,Y+28,Mau);
 End;

 Procedure VeQuanXe(X,Y,Mau: integer);
 Begin
           Line(X,Y+48,X+30,Y+48);
           Line(X,Y+48,X+7,Y+35);
           Line(X+30,Y+48,X+23,Y+35);
           Line(X+7,Y+35,X+7,Y+16);
           Line(X+23,Y+35,X+23,Y+16);
           Line(X+7,Y+16,X,Y+16);
           Line(X+23,Y+16,X+30,Y+16);
           Line(X,Y+16,X,Y+6);
           Line(X+30,Y+16,X+30,Y+6);
           Line(X,Y+6,X+6,Y+6);
           Line(X+30,Y+6,X+24,Y+6);
           Line(X+6,Y+6,X+6,Y+10);
           Line(X+24,Y+6,X+24,Y+10);
           Line(X+6,Y+10,X+12,Y+10);
           Line(X+24,Y+10,X+18,Y+10);
           Line(X+12,Y+10,X+12,Y+6);
           Line(X+18,Y+10,X+18,Y+6);
           Line(X+12,Y+6,X+18,Y+6);
           FloodFill(X+15,Y+28,Mau);
 End;

 Procedure VeQuanMa(X,Y,Mau: integer);
 Begin
           Line(X,Y+48,X+30,Y+48);
           Line(X,Y+48,X+7,Y+35);
           Line(X+30,Y+48,X+23,Y+35);
           Line(X+7,Y+35,X+13,Y+25);
           Line(X+13,Y+25,X+7,Y+17);
           Line(X+7,Y+17,X,Y+23);
           Line(X,Y+23,X-3,Y+20);
           Line(X-3,Y+20,X+2,Y+8);
           Line(X+2,Y+8,X+13,Y+5);
           Line(X+13,Y+5,X+23,Y+10);
           Line(X+23,Y+10,X+25,Y+30);
           Line(X+25,Y+30,X+23,Y+35);
           Circle(X+11,Y+12,2);
           FloodFill(X+15,Y+28,Mau);
 End;

 Procedure VeQuanTot(X,Y,Mau: integer);
 Begin
           Line(X,Y+48,X+30,Y+48);
           Line(X,Y+48,X+7,Y+35);
           Line(X+30,Y+48,X+23,Y+35);
           Line(X+7,Y+35,X+10,Y+20);
           Line(X+10,Y+20,X+7,Y+13);
           Line(X+23,Y+35,X+20,Y+20);
           Line(X+20,Y+20,X+23,Y+13);
           Line(X+7,Y+13,X+23,Y+13);
           FillEllipse(X+15,Y+7,6,6);
           FloodFill(X+15,Y+25,Mau);
 End;

 Procedure InQuanCo(X,Y,Quanco,Mau: integer);
 Begin
      SetColor(Mau);
      SetFillStyle(1,Mau);
      HiDeMouse;
      case QuanCo of
      Q_Vua:
           VeQuanVua(X+10,Y,Mau);
      Q_Hau:
            VeQuanHau(X+10,Y,Mau);
      Q_Tuong:
           VeQuanTuong(X+10,Y,Mau);
      Q_Xe:
           VeQuanXe(X+10,Y,Mau);
      Q_Ma:
           VeQuanMa(X+10,Y,Mau);
      Q_Tot:
           VeQuanTot(X+10,Y,Mau);
                  end;
      ShowMouse;
 End;

 Procedure ChuanBiTot(X,Y,Mau: integer);
 Begin
      if Mau = Red then
      begin
           if X < 7 then
           begin
           if OCo[X+1,Y].TuThe = T_Trong then OCo[X+1,Y].TuThe := T_ChuanBi;
           if Y > 0 then
           if (OCo[X+1,Y-1].TuThe <> T_Trong) and (OCo[X+1,Y-1].MauCo = Black)
           then OCo[X+1,Y-1].TuThe := T_ChuanBi;
           if (OCo[X+1,Y+1].TuThe <> T_Trong) and (OCo[X+1,Y+1].MauCo = Black)
           then OCo[X+1,Y+1].TuThe := T_ChuanBi;
           end;
           if (X = 1) and (OCo[3,Y].TuThe = T_Trong) then
           OCo[3,Y].TuThe := T_ChuanBi;
      end
      else
      begin
           if X > 0 then
           begin
           if OCo[X-1,Y].TuThe = T_Trong then OCo[X-1,Y].TuThe := T_ChuanBi;
           if Y > 0 then
           if (OCo[X-1,Y-1].TuThe <> T_Trong) and (OCo[X-1,Y-1].MauCo = Red)
           then OCo[X-1,Y-1].TuThe := T_ChuanBi;
           if (OCo[X-1,Y+1].TuThe <> T_Trong) and (OCo[X-1,Y+1].MauCo = Red)
           then OCo[X-1,Y+1].TuThe := T_ChuanBi;
           if (X = 6) and (OCo[4,Y].TuThe = T_Trong) then
           OCo[4,Y].TuThe := T_ChuanBi;
           end;
      end;
 End;

 Procedure ChuanBiXe(X,Y,Mau: integer);
 var i: integer;
 Begin
      for i := X+1 to 7 do
      begin
           if OCo[i,Y].Tuthe = T_Trong then
           OCo[i,Y].TuThe := T_ChuanBi
           else if OCo[i,Y].MauCo <> Mau then
           begin
           OCo[i,Y].TuThe := T_ChuanBi;
           break;
           end
           else break;
      end;
      for i := X-1 downto 0 do
      begin
           if OCo[i,Y].Tuthe = T_Trong then
           OCo[i,Y].TuThe := T_ChuanBi
           else if OCo[i,Y].MauCo <> Mau then
           begin
           OCo[i,Y].TuThe := T_ChuanBi;
           break;
           end
           else break;
      end;
      for i := Y+1 to 7 do
      begin
           if OCo[X,i].Tuthe = T_Trong then
           OCo[X,i].TuThe := T_ChuanBi
           else if OCo[X,i].MauCo <> Mau then
           begin
           OCo[X,i].TuThe := T_ChuanBi;
           break;
           end
           else break;
      end;
      for i := Y-1 downto 0 do
      begin
           if OCo[X,i].Tuthe = T_Trong then
           OCo[X,i].TuThe := T_ChuanBi
           else if OCo[X,i].MauCo <> Mau then
           begin
           OCo[X,i].TuThe := T_ChuanBi;
           break;
           end
           else break;
      end;
 End;

 Procedure ChuanBiMa(X,Y,Mau: integer);
 Begin
      if (OCo[X+2,Y-1].TuThe = T_Trong) or
      ((OCo[X+2,Y-1].TuThe <> T_Trong) and (OCo[X+2,Y-1].MauCo <> Mau)) then
      OCo[X+2,Y-1].TuThe := T_ChuanBi;

      if (OCo[X-2,Y-1].TuThe = T_Trong) or
      ((OCo[X-2,Y-1].TuThe <> T_Trong) and (OCo[X-2,Y-1].MauCo <> Mau)) then
      OCo[X-2,Y-1].TuThe := T_ChuanBi;

      if (OCo[X+2,Y+1].TuThe = T_Trong) or
      ((OCo[X+2,Y+1].TuThe <> T_Trong) and (OCo[X+2,Y+1].MauCo <> Mau)) then
      OCo[X+2,Y+1].TuThe := T_ChuanBi;

      if (OCo[X-2,Y+1].TuThe = T_Trong) or
      ((OCo[X-2,Y+1].TuThe <> T_Trong) and (OCo[X-2,Y+1].MauCo <> Mau)) then
      OCo[X-2,Y+1].TuThe := T_ChuanBi;

      if (OCo[X+1,Y-2].TuThe = T_Trong) or
      ((OCo[X+1,Y-2].TuThe <> T_Trong) and (OCo[X+1,Y-2].MauCo <> Mau)) then
      OCo[X+1,Y-2].TuThe := T_ChuanBi;

      if (OCo[X+1,Y+2].TuThe = T_Trong) or
      ((OCo[X+1,Y+2].TuThe <> T_Trong) and (OCo[X+1,Y+2].MauCo <> Mau)) then
      OCo[X+1,Y+2].TuThe := T_ChuanBi;

      if (OCo[X-1,Y-2].TuThe = T_Trong) or
      ((OCo[X-1,Y-2].TuThe <> T_Trong) and (OCo[X-1,Y-2].MauCo <> Mau)) then
      OCo[X-1,Y-2].TuThe := T_ChuanBi;

      if (OCo[X-1,Y+2].TuThe = T_Trong) or
      ((OCo[X-1,Y+2].TuThe <> T_Trong) and (OCo[X-1,Y+2].MauCo <> Mau)) then
      OCo[X-1,Y+2].TuThe := T_ChuanBi;
 End;

 Procedure ChuanBiTuong(X,Y,Mau: integer);
 var i: integer;
 Begin
      for i := 1 to 7 do
      begin
           if (X - i >= 0) and (Y - i >= 0) then
           begin
           if (OCo[X-i,Y-i].TuThe = T_Trong) then
           OCo[X-i,Y-i].TuThe := T_ChuanBi
           else if (OCo[X-i,Y-i].MauCo <> Mau) then
           begin
           OCo[X-i,Y-i].TuThe := T_ChuanBi;
           break;
           end;
           end
           else break;
      end;
      for i := 1 to 7 do
      begin
           if (X + i <= 7) and (Y + i <= 7) then
           begin
           if (OCo[X+i,Y+i].TuThe = T_Trong) then
           OCo[X+i,Y+i].TuThe := T_ChuanBi
           else if (OCo[X+i,Y+i].MauCo <> Mau) then
           begin
           OCo[X+i,Y+i].TuThe := T_ChuanBi;
           break;
           end;
           end
           else break;
      end;
      for i := 1 to 7 do
      begin
           if (X - i >= 0) and (Y + i <= 7) then
           begin
           if (OCo[X-i,Y+i].TuThe = T_Trong) then
           OCo[X-i,Y+i].TuThe := T_ChuanBi
           else if (OCo[X-i,Y+i].MauCo <> Mau) then
           begin
           OCo[X-i,Y+i].TuThe := T_ChuanBi;
           break;
           end;
           end
           else break;
      end;
      for i := 1 to 7 do
      begin
           if (X + i <= 7) and (Y - i >= 0) then
           begin
           if (OCo[X+i,Y-i].TuThe = T_Trong) then
           OCo[X+i,Y-i].TuThe := T_ChuanBi
           else if (OCo[X+i,Y-i].MauCo <> Mau) then
           begin
           OCo[X+i,Y-i].TuThe := T_ChuanBi;
           break;
           end;
           end
           else break;
      end;
 End;

 Procedure ChuanBiHau(X,Y,Mau: integer);
 Begin
      ChuanBiXe(X,Y,Mau);
      ChuanBiTuong(X,Y,Mau);
 End;

 Procedure ChuanBiVua(X,Y,Mau: integer);
 var i,j : integer;
 Begin
      for i := X-1 to X+1 do
          for j := Y-1 to Y+1 do
          begin
               if (i <> X) or (j <> Y) then
               if (OCo[i,j].TuThe = T_Trong) or ((OCo[i,j].TuThe = T_QuanCo)
               and (OCo[i,j].MauCo <> Mau)) then
               OCo[i,j].TuThe := T_ChuanBi;
          end;
 End;

 Procedure ChuanBiQuanCo(X,Y,QuanCo,Mau: integer);
 Begin
      case QuanCo of
      Q_Tot: ChuanBiTot(X,Y,Mau);
      Q_Xe: ChuanBiXe(X,Y,Mau);
      Q_Ma: ChuanBiMa(X,Y,Mau);
      Q_Tuong: ChuanBiTuong(X,Y,Mau);
      Q_Hau: ChuanBiHau(X,Y,Mau);
      Q_Vua: ChuanBiVua(X,Y,Mau);
                  end;
 End;

 Procedure HuyChuanBi;
 var i,j: integer;
 Begin
      for i := 0 to 7 do
          for j := 0 to 7 do
          begin
          if OCo[i,j].TuThe = T_ChuanBi then
          begin
          if OCo[i,j].QuanCo = Q_Khong then OCo[i,j].TuThe := T_Trong
          else OCo[i,j].TuThe := T_QuanCo;
          end;
          end;
 End;

 Procedure TaoBanCo;
 var i,j,k: integer;
 Begin
      for i := 0 to 7 do
      begin
           if k = Green then k := White
           else k := Green;
           for j := 0 to 7 do
           begin
                SetFillStyle(1,k);
                Bar(i*_KT,j*_KT,(i+1)*_KT,(j+1)*_KT);
                OCo[i,j].Tuthe := T_Trong;
                OCo[i,j].MauO := k;
                OCo[i,j].X := i;
                OCo[i,j].Y := j;
                OCo[i,j].QuanCo := Q_Khong;
                if k = Green then k := White
                else k := Green;
           end;
      end;

      { In Chu }
      SetColor(Red);
      SetTextStyle(DefaultFont, HorizDir,4);
      OutTextXy(8*_KT+10,20,'GAME');
      SetColor(LightGreen);
      OutTextXY(8*_KT+70,60,'CHESS');
      InQuanCo(8*_KT+10,120,Q_Vua,White);
      InQuanCo(8*_KT+80,120,Q_Hau,White);
      InQuanCo(8*_KT+160,120,Q_Xe,White);
      InQuanCo(8*_KT+10,230,Q_Ma,White);
      InQuanCo(8*_KT+80,230,Q_Tuong,White);
      InQuanCo(8*_KT+160,230,Q_Tot,White);
      SetFillStyle(7,Brown);
      Bar(8*_KT+30,320,8*_KT+200,400);
      SetColor(Cyan);
      OutTextXy(8*_KT+60,345,'EXIT');
 End;

 Procedure KhoiTaoGame;
 var i,j: integer;
 Begin
      OCo[0,0].QuanCo := Q_Xe;
      OCo[0,1].QuanCo := Q_Ma;
      OCo[0,2].QuanCo := Q_Tuong;
      OCo[0,3].QuanCo := Q_Hau;
      OCo[0,4].QuanCo := Q_Vua;
      OCo[0,5].QuanCo := Q_Tuong;
      OCo[0,6].QuanCo := Q_Ma;
      OCo[0,7].QuanCo := Q_Xe;

      OCo[7,0].QuanCo := Q_Xe;
      OCo[7,1].QuanCo := Q_Ma;
      OCo[7,2].QuanCo := Q_Tuong;
      OCo[7,3].QuanCo := Q_Hau;
      OCo[7,4].QuanCo := Q_Vua;
      OCo[7,5].QuanCo := Q_Tuong;
      OCo[7,6].QuanCo := Q_Ma;
      OCo[7,7].QuanCo := Q_Xe;
      for i := 0 to 7 do
      begin
           Oco[1,i].QuanCo := Q_Tot;
           OCo[6,i].QuanCo := Q_Tot;
      end;
      for i := 0 to 1 do
      for j := 0 to 7 do
      begin
           OCo[i,j].MauCo := Red;
           OCo[i,j].Tuthe := T_QuanCo;
           InQuanCo(i*_KT,j*_KT,OCo[i,j].QuanCo,OCo[i,j].MauCo);

           OCo[7-i,j].MauCo := Black;
           OCo[7-i,j].TuThe := T_QuanCo;
           InQuanCo((7-i)*_KT,j*_KT,OCo[7-i,j].QuanCo,OCo[7-i,j].MauCo);
      end;
 End;

 Procedure MouseEnter;
 var X,Y: integer;
     St: string;
 Begin
      X := mousex div _KT;
      Y := mousey div _KT;
      if (X < 8) and (Y < 8) and LeftClick then
      begin
           if not DangChon and (OCo[X,Y].MauCo = Luot) and
           (LaOCo.X = X) and (LaOCo.Y = Y) and (LaOCo.tuThe = T_QuanCo) then
           begin
           HideMouse;
           SetFillStyle(1,LaOCo.MauO);
           Bar(LaOCo.X*_KT,LaOCo.Y*_KT,(LaOCo.X + 1)*_KT,(LaOCo.Y + 1)*_KT);
           OCo[LaOCo.X,LaOCo.Y].Tuthe := LaOCo.TuThe;
           SetFillStyle(1,Yellow);
           Bar(X*_KT,Y*_KT,(X+1)*_KT,(Y+1)*_KT);
           InQuanCo(LaOCo.X*_KT,LaOCo.Y*_KT,LaOCo.quanCo,LaOCo.MauCo);
           OChon := OCo[X,Y];
           OCo[X,Y].TuThe := T_Chon;
           LaOCo := OCo[X,Y];
           ShowMouse;
           Dangchon := True;
           ChuanBiQuanCo(X,Y,OCo[X,Y].QuanCo,OCo[X,Y].MauCo);
           end
           else
           if (OCo[X,Y].TuThe = T_Chon) then
           begin
           HideMouse;
           SetFillStyle(1,LaOCo.MauO);
           Bar(LaOCo.X*_KT,LaOCo.Y*_KT,(LaOCo.X + 1)*_KT,(LaOCo.Y + 1)*_KT);
           OCo[LaOCo.X,LaOCo.Y].Tuthe := LaOCo.TuThe;
           SetFillStyle(1,Yellow);
           Bar(X*_KT,Y*_KT,(X+1)*_KT,(Y+1)*_KT);
           if LaOCo.TuThe <> T_Trong then
           InQuanCo(LaOCo.X*_KT,LaOCo.Y*_KT,LaOCo.quanCo,LaOCo.MauCo);
           OCo[X,Y].TuThe := T_QuanCo;
           LaOCo := OCo[X,Y];
           ShowMouse;
           DangChon := False;
           HuyChuanBi;
           end
           else
           if (LaOCo.X = X) and (LaOCo.Y = Y) and (LaOCo.TuThe = T_ChuanBi) then
           begin
           HuyChuanBi;
           HideMouse;
           if OCo[X,Y].QuanCo = Q_Vua then
           begin
                SetColor(Blue);
                SetTextStyle(DefaultFont, HorizDir, 2);
                if OCo[X,Y].MauCo = Red then
                OutTextXY(2*_KT,4*_KT,'Ben Do Thua Roi!')
                else
                OutTextXY(2*_KT,4*_KT,'Ben Den Thua Roi!');
                EndGame := True;
           end;
           OCo[X,Y].QuanCo := OChon.QuanCo;
           OCo[X,Y].MauCo := OChon.MauCo;
           SetFillStyle(1,OCo[X,Y].MauO);
           Bar(X*_KT,Y*_KT,(X+1)*_KT,(Y+1)*_KT);
           SetFillStyle(1,OChon.MauO);
           Bar(OChon.X*_KT,OChon.Y*_KT,(OChon.X+1)*_KT,(Ochon.Y+1)*_KT);
           InQuanCo(X*_KT,Y*_KT,OChon.QuanCo,OChon.MauCo);
           OCo[OChon.X,OChon.Y].TuThe := T_Trong;
           OCo[Ochon.X,OChon.Y].QuanCo := Q_Khong;
           OCo[X,Y].TuThe := T_QuanCo;
           LaOCo := OCo[OChon.X,Ochon.Y];
           ShowMouse;
           DangChon := False;
           if Luot = Red then Luot := Black
           else Luot := Red;
           end;
      end
      else
      if (X < 8) and (Y < 8) then
      begin
      case OCo[X,Y].TuThe of
      T_Trong:
      begin
           HideMouse;
           SetFillStyle(1,LaOCo.MauO);
           if LaOCo.TuThe <> T_Chon then
           begin
           Bar(LaOCo.X*_KT,LaOCo.Y*_KT,(LaOCo.X + 1)*_KT,(LaOCo.Y + 1)*_KT);
           OCo[LaOCo.X,LaOCo.Y].Tuthe := LaOCo.TuThe;
           end;
           if LaOco.TuThe <> T_Trong then
           InQuanCo(LaOCo.X*_KT,LaOCo.Y*_KT,LaOCo.quanCo,LaOCo.MauCo);
           SetFillStyle(1,Cyan);
           Bar(X*_KT,Y*_KT,(X+1)*_KT,(Y+1)*_KT);
           LaOCo := OCo[X,Y];
           OCo[X,Y].TuThe := T_Vao;
           ShowMouse;
      end;
      T_QuanCo:
      begin
           HideMouse;
           SetFillStyle(1,LaOCo.MauO);
           if LaOCo.TuThe <> T_Chon then
           begin
           Bar(LaOCo.X*_KT,LaOCo.Y*_KT,(LaOCo.X + 1)*_KT,(LaOCo.Y + 1)*_KT);
           OCo[LaOCo.X,LaOCo.Y].Tuthe := LaOCo.TuThe;
           end;
           if LaOco.TuThe <> T_Trong then
           InQuanCo(LaOCo.X*_KT,LaOCo.Y*_KT,LaOCo.quanCo,LaOCo.MauCo);
           SetFillStyle(1,Blue);
           Bar(X*_KT,Y*_KT,(X+1)*_KT,(Y+1)*_KT);
           InQuanCo(X*_KT,Y*_KT,OCo[X,Y].QuanCo,OCo[X,Y].MauCo);
           LaOCo := OCo[X,Y];
           OCo[X,Y].TuThe := T_Vao;
           ShowMouse;
      end;
      T_ChuanBi:
      begin
           HideMouse;
           SetFillStyle(1,LaOCo.MauO);
           if LaOCo.TuThe <> T_Chon then
           begin
           Bar(LaOCo.X*_KT,LaOCo.Y*_KT,(LaOCo.X + 1)*_KT,(LaOCo.Y + 1)*_KT);
           OCo[LaOCo.X,LaOCo.Y].Tuthe := LaOCo.TuThe;
           end;
           if LaOco.TuThe <> T_Trong then
           InQuanCo(LaOCo.X*_KT,LaOCo.Y*_KT,LaOCo.quanCo,LaOCo.MauCo);
           SetFillStyle(1,Brown);
           Bar(X*_KT,Y*_KT,(X+1)*_KT,(Y+1)*_KT);
           InQuanCo(X*_KT,Y*_KT,OCo[X,Y].QuanCo,OCo[X,Y].MauCo);
           LaOCo := OCo[X,Y];
           OCo[X,Y].TuThe := T_Vao;
           ShowMouse;
      end;
                        end;
      end;
 End;

 BEGIN
      InitGraph(gd,gm,'');
      MX := GetMaxX;
      MY := GetMaxY;
      InitMouse;
      Luot := Red;
      TaoBanCo;
      KhoiTaoGame;
      LaOCo := OCo[0,0];
      DangChon := False;
      EndGame := False;
      ShowMouse;
      repeat
      MouseEnter;
      until MouseAreA(8*_KT+30,320,8*_KT+200,400) or EndGame;
      if EndGame then readln;
      CloseGraph;
 END.
@ka1412
Gõ nguyên cái đoạn code này vào ấy hả anh Nghĩa....? Vì Pascal thì đâu có copy-paste được như văn bản bình thường.....
 

trà nguyễn hữu nghĩa

Cựu Mod Vật Lí |Cây bút Thơ|Thần tượng VH
Thành viên
14 Tháng năm 2017
3,974
7,623
744
22
Phú Yên
Trường THPT Lương Văn Chánh
  • Like
Reactions: Quang Đông

Axiore_Ro

Học sinh
Thành viên
18 Tháng ba 2020
101
85
36
16
Hà Nội
Roblox - Power of Imagination
Ăn được quân Vua là thắng nha :p không cần phải chiếu hết.
View attachment 56260

Code đây nhá (Phải có thư viện Graph và phải dùng TP mới được):

Mã:
 Program Co_Vua;
 uses crt,graph,dos;

 const _KT = 50;
       Q_Vua = 0;
       Q_Hau = 1;
       Q_Tuong = 2;
       Q_Ma = 3;
       Q_Xe = 4;
       Q_Tot = 5;
       Q_Khong =  6;

       T_Trong = 0;
       T_Vao = 1;
       T_ChuanBi = 2;
       T_QuanCo = 3;
       T_Chon = 4;

 type TOCo = record
                   QuanCo: integer;
                   TuThe: integer;
                   MauO,MauCo: Word;
                   X,Y: integer;
             end;

 var gd,gm: integer;
     MX,MY: integer;
     OCo: array[-2..7,-2..7] of TOCo;
     LaOCo,OChon : TOCo;
     DangChon,EndGame: Boolean;
     Luot: integer;

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

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

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

 function MouseArea(x1,y1,x2,y2:word):boolean;
 begin
 if     (LeftClick)
        and (mousex >=x1)
        and (mousex <=x2)
        and (mousey >=y1)
        and (mousey <=y2)
 then mousearea:=true
 else mousearea:=false;
 end;

 Function InitMouse : boolean;
 var r: registers;
 Begin
 r.ax:=$00;intr($33,r);
 if r.ax<>0 then InitMouse:=true
 else InitMouse:=false;
 End;

 Procedure ShowMouse;
 Var r: registers;
 begin
 r.ax:=$01;intr($33,r);
 End;

 Procedure HideMouse;
 Var r:registers;
 Begin
 r.ax:=$002;
 intr($33,r);
 End;

 Procedure VeQuanVua(X,Y,Mau: integer);
 Begin
           Line(X,Y+48,X+30,Y+48);
           Line(X,Y+48,X+7,Y+24);
           Line(X+30,Y+48,X+23,Y+24);
           Line(X+7,Y+24,X,Y+24);
           Line(X+23,Y+24,X+30,Y+24);
           Line(X,Y+24,X,Y+21);
           Line(X+30,Y+24,X+30,Y+21);
           Line(X,Y+21,X+7,Y+21);
           Line(X+30,Y+21,X+23,Y+21);
           Line(X+7,Y+21,X,Y+16);
           Line(X+23,Y+21,X+30,Y+16);
           Line(X,Y+16,X+12,Y+16);
           Line(X+30,Y+16,X+18,Y+16);
           Line(X+12,Y+16,X+12,Y+10);
           Line(X+18,Y+16,X+18,Y+10);
           Line(X+12,Y+10,X+8,Y+10);
           Line(X+18,Y+10,X+22,Y+10);
           Line(X+8,Y+10,X+8,Y+6);
           Line(X+22,Y+10,X+22,Y+6);
           Line(X+8,Y+6,X+12,Y+6);
           Line(X+22,Y+6,X+18,Y+6);
           Line(X+12,Y+6,X+12,Y+3);
           Line(X+18,Y+6,X+18,Y+3);
           Line(X+12,Y+3,X+18,Y+3);
           CirCle(X+15,Y+22,3);
           FloodFill(X+15,Y+28,Mau);
 End;

 Procedure VeQuanHau(X,Y,Mau: integer);
 Begin
           Line(X,Y+48,X+30,Y+48);
           Line(X,Y+48,X+7,Y+24);
           Line(X+30,Y+48,X+23,Y+24);
           Line(X+7,Y+24,X,Y+24);
           Line(X+23,Y+24,X+30,Y+24);
           Line(X,Y+24,X,Y+21);
           Line(X+30,Y+24,X+30,Y+21);
           Line(X,Y+21,X+7,Y+21);
           Line(X+30,Y+21,X+23,Y+21);
           Line(X+7,Y+21,X,Y+16);
           Line(X+23,Y+21,X+30,Y+16);
           Line(X,Y+16,X+15,Y+10);
           Line(X+30,Y+16,X+15,Y+10);
           Line(X+15,Y+10,X+15,Y+3);
           FloodFill(X+15,Y+28,Mau);
 End;

 Procedure VeQuanTuong(X,Y,Mau: integer);
 Begin
           Line(X,Y+48,X+30,Y+48);
           Line(X,Y+48,X+7,Y+35);
           Line(X+30,Y+48,X+23,Y+35);
           Line(X+7,Y+35,X+7,Y+16);
           Line(X+23,Y+35,X+23,Y+16);
           Line(X+7,Y+16,X+15,Y+6);
           Line(X+23,Y+16,X+15,Y+6);
           FillEllipse(X+15,Y+4,2,2);
           Line(X+7,Y+21,X+17,Y+9);
           FloodFill(X+15,Y+28,Mau);
 End;

 Procedure VeQuanXe(X,Y,Mau: integer);
 Begin
           Line(X,Y+48,X+30,Y+48);
           Line(X,Y+48,X+7,Y+35);
           Line(X+30,Y+48,X+23,Y+35);
           Line(X+7,Y+35,X+7,Y+16);
           Line(X+23,Y+35,X+23,Y+16);
           Line(X+7,Y+16,X,Y+16);
           Line(X+23,Y+16,X+30,Y+16);
           Line(X,Y+16,X,Y+6);
           Line(X+30,Y+16,X+30,Y+6);
           Line(X,Y+6,X+6,Y+6);
           Line(X+30,Y+6,X+24,Y+6);
           Line(X+6,Y+6,X+6,Y+10);
           Line(X+24,Y+6,X+24,Y+10);
           Line(X+6,Y+10,X+12,Y+10);
           Line(X+24,Y+10,X+18,Y+10);
           Line(X+12,Y+10,X+12,Y+6);
           Line(X+18,Y+10,X+18,Y+6);
           Line(X+12,Y+6,X+18,Y+6);
           FloodFill(X+15,Y+28,Mau);
 End;

 Procedure VeQuanMa(X,Y,Mau: integer);
 Begin
           Line(X,Y+48,X+30,Y+48);
           Line(X,Y+48,X+7,Y+35);
           Line(X+30,Y+48,X+23,Y+35);
           Line(X+7,Y+35,X+13,Y+25);
           Line(X+13,Y+25,X+7,Y+17);
           Line(X+7,Y+17,X,Y+23);
           Line(X,Y+23,X-3,Y+20);
           Line(X-3,Y+20,X+2,Y+8);
           Line(X+2,Y+8,X+13,Y+5);
           Line(X+13,Y+5,X+23,Y+10);
           Line(X+23,Y+10,X+25,Y+30);
           Line(X+25,Y+30,X+23,Y+35);
           Circle(X+11,Y+12,2);
           FloodFill(X+15,Y+28,Mau);
 End;

 Procedure VeQuanTot(X,Y,Mau: integer);
 Begin
           Line(X,Y+48,X+30,Y+48);
           Line(X,Y+48,X+7,Y+35);
           Line(X+30,Y+48,X+23,Y+35);
           Line(X+7,Y+35,X+10,Y+20);
           Line(X+10,Y+20,X+7,Y+13);
           Line(X+23,Y+35,X+20,Y+20);
           Line(X+20,Y+20,X+23,Y+13);
           Line(X+7,Y+13,X+23,Y+13);
           FillEllipse(X+15,Y+7,6,6);
           FloodFill(X+15,Y+25,Mau);
 End;

 Procedure InQuanCo(X,Y,Quanco,Mau: integer);
 Begin
      SetColor(Mau);
      SetFillStyle(1,Mau);
      HiDeMouse;
      case QuanCo of
      Q_Vua:
           VeQuanVua(X+10,Y,Mau);
      Q_Hau:
            VeQuanHau(X+10,Y,Mau);
      Q_Tuong:
           VeQuanTuong(X+10,Y,Mau);
      Q_Xe:
           VeQuanXe(X+10,Y,Mau);
      Q_Ma:
           VeQuanMa(X+10,Y,Mau);
      Q_Tot:
           VeQuanTot(X+10,Y,Mau);
                  end;
      ShowMouse;
 End;

 Procedure ChuanBiTot(X,Y,Mau: integer);
 Begin
      if Mau = Red then
      begin
           if X < 7 then
           begin
           if OCo[X+1,Y].TuThe = T_Trong then OCo[X+1,Y].TuThe := T_ChuanBi;
           if Y > 0 then
           if (OCo[X+1,Y-1].TuThe <> T_Trong) and (OCo[X+1,Y-1].MauCo = Black)
           then OCo[X+1,Y-1].TuThe := T_ChuanBi;
           if (OCo[X+1,Y+1].TuThe <> T_Trong) and (OCo[X+1,Y+1].MauCo = Black)
           then OCo[X+1,Y+1].TuThe := T_ChuanBi;
           end;
           if (X = 1) and (OCo[3,Y].TuThe = T_Trong) then
           OCo[3,Y].TuThe := T_ChuanBi;
      end
      else
      begin
           if X > 0 then
           begin
           if OCo[X-1,Y].TuThe = T_Trong then OCo[X-1,Y].TuThe := T_ChuanBi;
           if Y > 0 then
           if (OCo[X-1,Y-1].TuThe <> T_Trong) and (OCo[X-1,Y-1].MauCo = Red)
           then OCo[X-1,Y-1].TuThe := T_ChuanBi;
           if (OCo[X-1,Y+1].TuThe <> T_Trong) and (OCo[X-1,Y+1].MauCo = Red)
           then OCo[X-1,Y+1].TuThe := T_ChuanBi;
           if (X = 6) and (OCo[4,Y].TuThe = T_Trong) then
           OCo[4,Y].TuThe := T_ChuanBi;
           end;
      end;
 End;

 Procedure ChuanBiXe(X,Y,Mau: integer);
 var i: integer;
 Begin
      for i := X+1 to 7 do
      begin
           if OCo[i,Y].Tuthe = T_Trong then
           OCo[i,Y].TuThe := T_ChuanBi
           else if OCo[i,Y].MauCo <> Mau then
           begin
           OCo[i,Y].TuThe := T_ChuanBi;
           break;
           end
           else break;
      end;
      for i := X-1 downto 0 do
      begin
           if OCo[i,Y].Tuthe = T_Trong then
           OCo[i,Y].TuThe := T_ChuanBi
           else if OCo[i,Y].MauCo <> Mau then
           begin
           OCo[i,Y].TuThe := T_ChuanBi;
           break;
           end
           else break;
      end;
      for i := Y+1 to 7 do
      begin
           if OCo[X,i].Tuthe = T_Trong then
           OCo[X,i].TuThe := T_ChuanBi
           else if OCo[X,i].MauCo <> Mau then
           begin
           OCo[X,i].TuThe := T_ChuanBi;
           break;
           end
           else break;
      end;
      for i := Y-1 downto 0 do
      begin
           if OCo[X,i].Tuthe = T_Trong then
           OCo[X,i].TuThe := T_ChuanBi
           else if OCo[X,i].MauCo <> Mau then
           begin
           OCo[X,i].TuThe := T_ChuanBi;
           break;
           end
           else break;
      end;
 End;

 Procedure ChuanBiMa(X,Y,Mau: integer);
 Begin
      if (OCo[X+2,Y-1].TuThe = T_Trong) or
      ((OCo[X+2,Y-1].TuThe <> T_Trong) and (OCo[X+2,Y-1].MauCo <> Mau)) then
      OCo[X+2,Y-1].TuThe := T_ChuanBi;

      if (OCo[X-2,Y-1].TuThe = T_Trong) or
      ((OCo[X-2,Y-1].TuThe <> T_Trong) and (OCo[X-2,Y-1].MauCo <> Mau)) then
      OCo[X-2,Y-1].TuThe := T_ChuanBi;

      if (OCo[X+2,Y+1].TuThe = T_Trong) or
      ((OCo[X+2,Y+1].TuThe <> T_Trong) and (OCo[X+2,Y+1].MauCo <> Mau)) then
      OCo[X+2,Y+1].TuThe := T_ChuanBi;

      if (OCo[X-2,Y+1].TuThe = T_Trong) or
      ((OCo[X-2,Y+1].TuThe <> T_Trong) and (OCo[X-2,Y+1].MauCo <> Mau)) then
      OCo[X-2,Y+1].TuThe := T_ChuanBi;

      if (OCo[X+1,Y-2].TuThe = T_Trong) or
      ((OCo[X+1,Y-2].TuThe <> T_Trong) and (OCo[X+1,Y-2].MauCo <> Mau)) then
      OCo[X+1,Y-2].TuThe := T_ChuanBi;

      if (OCo[X+1,Y+2].TuThe = T_Trong) or
      ((OCo[X+1,Y+2].TuThe <> T_Trong) and (OCo[X+1,Y+2].MauCo <> Mau)) then
      OCo[X+1,Y+2].TuThe := T_ChuanBi;

      if (OCo[X-1,Y-2].TuThe = T_Trong) or
      ((OCo[X-1,Y-2].TuThe <> T_Trong) and (OCo[X-1,Y-2].MauCo <> Mau)) then
      OCo[X-1,Y-2].TuThe := T_ChuanBi;

      if (OCo[X-1,Y+2].TuThe = T_Trong) or
      ((OCo[X-1,Y+2].TuThe <> T_Trong) and (OCo[X-1,Y+2].MauCo <> Mau)) then
      OCo[X-1,Y+2].TuThe := T_ChuanBi;
 End;

 Procedure ChuanBiTuong(X,Y,Mau: integer);
 var i: integer;
 Begin
      for i := 1 to 7 do
      begin
           if (X - i >= 0) and (Y - i >= 0) then
           begin
           if (OCo[X-i,Y-i].TuThe = T_Trong) then
           OCo[X-i,Y-i].TuThe := T_ChuanBi
           else if (OCo[X-i,Y-i].MauCo <> Mau) then
           begin
           OCo[X-i,Y-i].TuThe := T_ChuanBi;
           break;
           end;
           end
           else break;
      end;
      for i := 1 to 7 do
      begin
           if (X + i <= 7) and (Y + i <= 7) then
           begin
           if (OCo[X+i,Y+i].TuThe = T_Trong) then
           OCo[X+i,Y+i].TuThe := T_ChuanBi
           else if (OCo[X+i,Y+i].MauCo <> Mau) then
           begin
           OCo[X+i,Y+i].TuThe := T_ChuanBi;
           break;
           end;
           end
           else break;
      end;
      for i := 1 to 7 do
      begin
           if (X - i >= 0) and (Y + i <= 7) then
           begin
           if (OCo[X-i,Y+i].TuThe = T_Trong) then
           OCo[X-i,Y+i].TuThe := T_ChuanBi
           else if (OCo[X-i,Y+i].MauCo <> Mau) then
           begin
           OCo[X-i,Y+i].TuThe := T_ChuanBi;
           break;
           end;
           end
           else break;
      end;
      for i := 1 to 7 do
      begin
           if (X + i <= 7) and (Y - i >= 0) then
           begin
           if (OCo[X+i,Y-i].TuThe = T_Trong) then
           OCo[X+i,Y-i].TuThe := T_ChuanBi
           else if (OCo[X+i,Y-i].MauCo <> Mau) then
           begin
           OCo[X+i,Y-i].TuThe := T_ChuanBi;
           break;
           end;
           end
           else break;
      end;
 End;

 Procedure ChuanBiHau(X,Y,Mau: integer);
 Begin
      ChuanBiXe(X,Y,Mau);
      ChuanBiTuong(X,Y,Mau);
 End;

 Procedure ChuanBiVua(X,Y,Mau: integer);
 var i,j : integer;
 Begin
      for i := X-1 to X+1 do
          for j := Y-1 to Y+1 do
          begin
               if (i <> X) or (j <> Y) then
               if (OCo[i,j].TuThe = T_Trong) or ((OCo[i,j].TuThe = T_QuanCo)
               and (OCo[i,j].MauCo <> Mau)) then
               OCo[i,j].TuThe := T_ChuanBi;
          end;
 End;

 Procedure ChuanBiQuanCo(X,Y,QuanCo,Mau: integer);
 Begin
      case QuanCo of
      Q_Tot: ChuanBiTot(X,Y,Mau);
      Q_Xe: ChuanBiXe(X,Y,Mau);
      Q_Ma: ChuanBiMa(X,Y,Mau);
      Q_Tuong: ChuanBiTuong(X,Y,Mau);
      Q_Hau: ChuanBiHau(X,Y,Mau);
      Q_Vua: ChuanBiVua(X,Y,Mau);
                  end;
 End;

 Procedure HuyChuanBi;
 var i,j: integer;
 Begin
      for i := 0 to 7 do
          for j := 0 to 7 do
          begin
          if OCo[i,j].TuThe = T_ChuanBi then
          begin
          if OCo[i,j].QuanCo = Q_Khong then OCo[i,j].TuThe := T_Trong
          else OCo[i,j].TuThe := T_QuanCo;
          end;
          end;
 End;

 Procedure TaoBanCo;
 var i,j,k: integer;
 Begin
      for i := 0 to 7 do
      begin
           if k = Green then k := White
           else k := Green;
           for j := 0 to 7 do
           begin
                SetFillStyle(1,k);
                Bar(i*_KT,j*_KT,(i+1)*_KT,(j+1)*_KT);
                OCo[i,j].Tuthe := T_Trong;
                OCo[i,j].MauO := k;
                OCo[i,j].X := i;
                OCo[i,j].Y := j;
                OCo[i,j].QuanCo := Q_Khong;
                if k = Green then k := White
                else k := Green;
           end;
      end;

      { In Chu }
      SetColor(Red);
      SetTextStyle(DefaultFont, HorizDir,4);
      OutTextXy(8*_KT+10,20,'GAME');
      SetColor(LightGreen);
      OutTextXY(8*_KT+70,60,'CHESS');
      InQuanCo(8*_KT+10,120,Q_Vua,White);
      InQuanCo(8*_KT+80,120,Q_Hau,White);
      InQuanCo(8*_KT+160,120,Q_Xe,White);
      InQuanCo(8*_KT+10,230,Q_Ma,White);
      InQuanCo(8*_KT+80,230,Q_Tuong,White);
      InQuanCo(8*_KT+160,230,Q_Tot,White);
      SetFillStyle(7,Brown);
      Bar(8*_KT+30,320,8*_KT+200,400);
      SetColor(Cyan);
      OutTextXy(8*_KT+60,345,'EXIT');
 End;

 Procedure KhoiTaoGame;
 var i,j: integer;
 Begin
      OCo[0,0].QuanCo := Q_Xe;
      OCo[0,1].QuanCo := Q_Ma;
      OCo[0,2].QuanCo := Q_Tuong;
      OCo[0,3].QuanCo := Q_Hau;
      OCo[0,4].QuanCo := Q_Vua;
      OCo[0,5].QuanCo := Q_Tuong;
      OCo[0,6].QuanCo := Q_Ma;
      OCo[0,7].QuanCo := Q_Xe;

      OCo[7,0].QuanCo := Q_Xe;
      OCo[7,1].QuanCo := Q_Ma;
      OCo[7,2].QuanCo := Q_Tuong;
      OCo[7,3].QuanCo := Q_Hau;
      OCo[7,4].QuanCo := Q_Vua;
      OCo[7,5].QuanCo := Q_Tuong;
      OCo[7,6].QuanCo := Q_Ma;
      OCo[7,7].QuanCo := Q_Xe;
      for i := 0 to 7 do
      begin
           Oco[1,i].QuanCo := Q_Tot;
           OCo[6,i].QuanCo := Q_Tot;
      end;
      for i := 0 to 1 do
      for j := 0 to 7 do
      begin
           OCo[i,j].MauCo := Red;
           OCo[i,j].Tuthe := T_QuanCo;
           InQuanCo(i*_KT,j*_KT,OCo[i,j].QuanCo,OCo[i,j].MauCo);

           OCo[7-i,j].MauCo := Black;
           OCo[7-i,j].TuThe := T_QuanCo;
           InQuanCo((7-i)*_KT,j*_KT,OCo[7-i,j].QuanCo,OCo[7-i,j].MauCo);
      end;
 End;

 Procedure MouseEnter;
 var X,Y: integer;
     St: string;
 Begin
      X := mousex div _KT;
      Y := mousey div _KT;
      if (X < 8) and (Y < 8) and LeftClick then
      begin
           if not DangChon and (OCo[X,Y].MauCo = Luot) and
           (LaOCo.X = X) and (LaOCo.Y = Y) and (LaOCo.tuThe = T_QuanCo) then
           begin
           HideMouse;
           SetFillStyle(1,LaOCo.MauO);
           Bar(LaOCo.X*_KT,LaOCo.Y*_KT,(LaOCo.X + 1)*_KT,(LaOCo.Y + 1)*_KT);
           OCo[LaOCo.X,LaOCo.Y].Tuthe := LaOCo.TuThe;
           SetFillStyle(1,Yellow);
           Bar(X*_KT,Y*_KT,(X+1)*_KT,(Y+1)*_KT);
           InQuanCo(LaOCo.X*_KT,LaOCo.Y*_KT,LaOCo.quanCo,LaOCo.MauCo);
           OChon := OCo[X,Y];
           OCo[X,Y].TuThe := T_Chon;
           LaOCo := OCo[X,Y];
           ShowMouse;
           Dangchon := True;
           ChuanBiQuanCo(X,Y,OCo[X,Y].QuanCo,OCo[X,Y].MauCo);
           end
           else
           if (OCo[X,Y].TuThe = T_Chon) then
           begin
           HideMouse;
           SetFillStyle(1,LaOCo.MauO);
           Bar(LaOCo.X*_KT,LaOCo.Y*_KT,(LaOCo.X + 1)*_KT,(LaOCo.Y + 1)*_KT);
           OCo[LaOCo.X,LaOCo.Y].Tuthe := LaOCo.TuThe;
           SetFillStyle(1,Yellow);
           Bar(X*_KT,Y*_KT,(X+1)*_KT,(Y+1)*_KT);
           if LaOCo.TuThe <> T_Trong then
           InQuanCo(LaOCo.X*_KT,LaOCo.Y*_KT,LaOCo.quanCo,LaOCo.MauCo);
           OCo[X,Y].TuThe := T_QuanCo;
           LaOCo := OCo[X,Y];
           ShowMouse;
           DangChon := False;
           HuyChuanBi;
           end
           else
           if (LaOCo.X = X) and (LaOCo.Y = Y) and (LaOCo.TuThe = T_ChuanBi) then
           begin
           HuyChuanBi;
           HideMouse;
           if OCo[X,Y].QuanCo = Q_Vua then
           begin
                SetColor(Blue);
                SetTextStyle(DefaultFont, HorizDir, 2);
                if OCo[X,Y].MauCo = Red then
                OutTextXY(2*_KT,4*_KT,'Ben Do Thua Roi!')
                else
                OutTextXY(2*_KT,4*_KT,'Ben Den Thua Roi!');
                EndGame := True;
           end;
           OCo[X,Y].QuanCo := OChon.QuanCo;
           OCo[X,Y].MauCo := OChon.MauCo;
           SetFillStyle(1,OCo[X,Y].MauO);
           Bar(X*_KT,Y*_KT,(X+1)*_KT,(Y+1)*_KT);
           SetFillStyle(1,OChon.MauO);
           Bar(OChon.X*_KT,OChon.Y*_KT,(OChon.X+1)*_KT,(Ochon.Y+1)*_KT);
           InQuanCo(X*_KT,Y*_KT,OChon.QuanCo,OChon.MauCo);
           OCo[OChon.X,OChon.Y].TuThe := T_Trong;
           OCo[Ochon.X,OChon.Y].QuanCo := Q_Khong;
           OCo[X,Y].TuThe := T_QuanCo;
           LaOCo := OCo[OChon.X,Ochon.Y];
           ShowMouse;
           DangChon := False;
           if Luot = Red then Luot := Black
           else Luot := Red;
           end;
      end
      else
      if (X < 8) and (Y < 8) then
      begin
      case OCo[X,Y].TuThe of
      T_Trong:
      begin
           HideMouse;
           SetFillStyle(1,LaOCo.MauO);
           if LaOCo.TuThe <> T_Chon then
           begin
           Bar(LaOCo.X*_KT,LaOCo.Y*_KT,(LaOCo.X + 1)*_KT,(LaOCo.Y + 1)*_KT);
           OCo[LaOCo.X,LaOCo.Y].Tuthe := LaOCo.TuThe;
           end;
           if LaOco.TuThe <> T_Trong then
           InQuanCo(LaOCo.X*_KT,LaOCo.Y*_KT,LaOCo.quanCo,LaOCo.MauCo);
           SetFillStyle(1,Cyan);
           Bar(X*_KT,Y*_KT,(X+1)*_KT,(Y+1)*_KT);
           LaOCo := OCo[X,Y];
           OCo[X,Y].TuThe := T_Vao;
           ShowMouse;
      end;
      T_QuanCo:
      begin
           HideMouse;
           SetFillStyle(1,LaOCo.MauO);
           if LaOCo.TuThe <> T_Chon then
           begin
           Bar(LaOCo.X*_KT,LaOCo.Y*_KT,(LaOCo.X + 1)*_KT,(LaOCo.Y + 1)*_KT);
           OCo[LaOCo.X,LaOCo.Y].Tuthe := LaOCo.TuThe;
           end;
           if LaOco.TuThe <> T_Trong then
           InQuanCo(LaOCo.X*_KT,LaOCo.Y*_KT,LaOCo.quanCo,LaOCo.MauCo);
           SetFillStyle(1,Blue);
           Bar(X*_KT,Y*_KT,(X+1)*_KT,(Y+1)*_KT);
           InQuanCo(X*_KT,Y*_KT,OCo[X,Y].QuanCo,OCo[X,Y].MauCo);
           LaOCo := OCo[X,Y];
           OCo[X,Y].TuThe := T_Vao;
           ShowMouse;
      end;
      T_ChuanBi:
      begin
           HideMouse;
           SetFillStyle(1,LaOCo.MauO);
           if LaOCo.TuThe <> T_Chon then
           begin
           Bar(LaOCo.X*_KT,LaOCo.Y*_KT,(LaOCo.X + 1)*_KT,(LaOCo.Y + 1)*_KT);
           OCo[LaOCo.X,LaOCo.Y].Tuthe := LaOCo.TuThe;
           end;
           if LaOco.TuThe <> T_Trong then
           InQuanCo(LaOCo.X*_KT,LaOCo.Y*_KT,LaOCo.quanCo,LaOCo.MauCo);
           SetFillStyle(1,Brown);
           Bar(X*_KT,Y*_KT,(X+1)*_KT,(Y+1)*_KT);
           InQuanCo(X*_KT,Y*_KT,OCo[X,Y].QuanCo,OCo[X,Y].MauCo);
           LaOCo := OCo[X,Y];
           OCo[X,Y].TuThe := T_Vao;
           ShowMouse;
      end;
                        end;
      end;
 End;

 BEGIN
      InitGraph(gd,gm,'');
      MX := GetMaxX;
      MY := GetMaxY;
      InitMouse;
      Luot := Red;
      TaoBanCo;
      KhoiTaoGame;
      LaOCo := OCo[0,0];
      DangChon := False;
      EndGame := False;
      ShowMouse;
      repeat
      MouseEnter;
      until MouseAreA(8*_KT+30,320,8*_KT+200,400) or EndGame;
      if EndGame then readln;
      CloseGraph;
 END.
@ka1412
anh trà xanh ơi, em vào mục BIN và làm đúng như lời anh dặn mà sao nó ERROR là:
upload_2020-4-7_22-32-47.png
đó anh xử lý giúp em
 

nhatnguyen195@gmail.com

Học sinh mới
Thành viên
15 Tháng tư 2020
3
5
6
program Oan_tu_ti;
uses crt;
var N,p,ai,s,y,i,z:integer;
begin
clrscr;
textbackground(7);
textcolor(12);
writeln('Xin chao!');
delay(2000);
writeln('Ban se choi oan tu ti voi tri tue nhan tao!');
delay(2000);
writeln('Phe nao duoc 10 diem truoc se chien thang!!!');
delay(2000);
writeln('CHUC BAN CHOI GAME VUI VE!!!');
delay(2000);
writeln('Nhan Enter de choi!!!');
readln;
s:=0;
y:=0;
repeat
clrscr;
randomize;
textcolor(1);
writeln('Ban chon gi?');
writeln('1: keo');
writeln('2: bua');
writeln('3: bao');
readln(p);
ai:=random(2)+1;
clrscr;
for z:=1 to 2 do begin
writeln('May dang chon.');
delay(500);
clrscr;
writeln('May dang chon..');
delay(500);
clrscr;
writeln('May dang chon...');
delay(500);
clrscr;
end;
if ((p=ai) and (p=1)) then begin
s:=s+1;
y:=y+1;
writeln('Ban chon keo ||| May chon keo => HOA!');
delay(2000);
clrscr;
writeln('TI SO: Ban:',s-1,' May:',y-1);
delay(1000);
clrscr;
writeln('TI SO: Ban:',s,' May:',y);
delay(1400);
end;
if (p=ai) and (p=2) then begin
s:=s+1;
y:=y+1;
writeln('Ban chon bua ||| May chon bua => HOA!');
delay(2000);
clrscr;
writeln('TI SO: Ban:',s-1,' May:',y-1);
delay(1000);
clrscr;
writeln('TI SO: Ban:',s,' May:',y);
delay(1400);
end;
if (p=ai) and (p=3) then begin
s:=s+1;
y:=y+1;
writeln('Ban chon bao ||| May chon bao => HOA!');
delay(2000);
clrscr;
writeln('TI SO: Ban:',y-1,' May:',s-1);
delay(1000);
clrscr;
writeln('TI SO: Ban:',y,' May:',s);
delay(1400);
end;
if (p-ai=1) and (p=3) then begin
s:=s+1;
y:=y;
writeln('Ban chon bao ||| May chon bua => BAN THANG!');
delay(2000);
clrscr;
writeln('TI SO: Ban:',s-1,' May:',y);
delay(1000);
clrscr;
writeln('TI SO: Ban:',s,' May:',y);
delay(1400);
end;
if (p-ai=1) and (p=2) then begin
s:=s+1;
y:=y;
writeln('Ban chon bua ||| May chon keo => BAN THANG!');
delay(2000);
clrscr;
writeln('TI SO: Ban:',s-1,' May:',y);
delay(1000);
clrscr;
writeln('TI SO: Ban:',s,' May:',y);
delay(1400);
end;
if (p=1) and (ai=3) then begin
s:=s+1;
y:=y;
writeln('Ban chon keo ||| May chon bao => BAN THANG!');
delay(2000);
clrscr;
writeln('TI SO: Ban:',s-1,' May:',y);
delay(1000);
clrscr;
writeln('TI SO: Ban:',s,' May:',y);
delay(1400);
end;
if (p-ai=-1) and (ai=3) then begin
s:=s;
y:=y+1;
writeln('Ban chon bua ||| May chon bao => MAY THANG!');
delay(2000);
clrscr;
writeln('TI SO: Ban:',s,' May:',y-1);
delay(1000);
clrscr;
writeln('TI SO: Ban:',s,' May:',y);
delay(1400);
end;
if (p-ai=-1) and (ai=2) then begin
s:=s;
y:=y+1;
writeln('Ban chon keo ||| May chon bua => MAY THANG!');
delay(1000);
clrscr;
writeln('TI SO: Ban:',s,' May:',y-1);
delay(1000);
clrscr;
writeln('TI SO: Ban:',s,' May:',y);
delay(1000);
end;
if (p=3) and (ai=1) then begin
s:=s;
y:=y+1;
writeln('Ban chon bao ||| May chon keo => MAY THANG!');
delay(1000);
clrscr;
writeln('TI SO: Ban:',s,' May:',y-1);
delay(1000);
clrscr;
writeln('TI SO: Ban:',s,' May:',y);
delay(1000);
end;
writeln('Nhan Enter de tiep tuc!');
readln;
until (s=10) or (y=10);
if s=10 then begin
clrscr;
writeln('CONGRATULATION! BAN DA THANG DUOC TRI TUE NHAN TAO');
end;
if (y=10) then begin
clrscr;
writeln('CHUC BAN MAY MAN LAN SAU');
end;
if (s=10) and (y=10) then begin
writeln;
writeln('CHUC MUNG!!! Ban da co duoc tri tue nhan tao!!!');
end;
for i:=10 downto 1 do
begin
writeln;
writeln('Chuong trinh se ket thuc sau:',i);
delay(1000);
clrscr;
end;
writeln('Tac gia: NGUYEN DANG KHOI');
readln;
end.

Mình đã nâng cấp chương trình game oẳn tù tì mà mình tình cờ xem được.
Mong các bạn cho mình xin ý kiến.
 

trà nguyễn hữu nghĩa

Cựu Mod Vật Lí |Cây bút Thơ|Thần tượng VH
Thành viên
14 Tháng năm 2017
3,974
7,623
744
22
Phú Yên
Trường THPT Lương Văn Chánh
program Oan_tu_ti;
uses crt;
var N,p,ai,s,y,i,z:integer;
begin
clrscr;
textbackground(7);
textcolor(12);
writeln('Xin chao!');
delay(2000);
writeln('Ban se choi oan tu ti voi tri tue nhan tao!');
delay(2000);
writeln('Phe nao duoc 10 diem truoc se chien thang!!!');
delay(2000);
writeln('CHUC BAN CHOI GAME VUI VE!!!');
delay(2000);
writeln('Nhan Enter de choi!!!');
readln;
s:=0;
y:=0;
repeat
clrscr;
randomize;
textcolor(1);
writeln('Ban chon gi?');
writeln('1: keo');
writeln('2: bua');
writeln('3: bao');
readln(p);
ai:=random(2)+1;
clrscr;
for z:=1 to 2 do begin
writeln('May dang chon.');
delay(500);
clrscr;
writeln('May dang chon..');
delay(500);
clrscr;
writeln('May dang chon...');
delay(500);
clrscr;
end;
if ((p=ai) and (p=1)) then begin
s:=s+1;
y:=y+1;
writeln('Ban chon keo ||| May chon keo => HOA!');
delay(2000);
clrscr;
writeln('TI SO: Ban:',s-1,' May:',y-1);
delay(1000);
clrscr;
writeln('TI SO: Ban:',s,' May:',y);
delay(1400);
end;
if (p=ai) and (p=2) then begin
s:=s+1;
y:=y+1;
writeln('Ban chon bua ||| May chon bua => HOA!');
delay(2000);
clrscr;
writeln('TI SO: Ban:',s-1,' May:',y-1);
delay(1000);
clrscr;
writeln('TI SO: Ban:',s,' May:',y);
delay(1400);
end;
if (p=ai) and (p=3) then begin
s:=s+1;
y:=y+1;
writeln('Ban chon bao ||| May chon bao => HOA!');
delay(2000);
clrscr;
writeln('TI SO: Ban:',y-1,' May:',s-1);
delay(1000);
clrscr;
writeln('TI SO: Ban:',y,' May:',s);
delay(1400);
end;
if (p-ai=1) and (p=3) then begin
s:=s+1;
y:=y;
writeln('Ban chon bao ||| May chon bua => BAN THANG!');
delay(2000);
clrscr;
writeln('TI SO: Ban:',s-1,' May:',y);
delay(1000);
clrscr;
writeln('TI SO: Ban:',s,' May:',y);
delay(1400);
end;
if (p-ai=1) and (p=2) then begin
s:=s+1;
y:=y;
writeln('Ban chon bua ||| May chon keo => BAN THANG!');
delay(2000);
clrscr;
writeln('TI SO: Ban:',s-1,' May:',y);
delay(1000);
clrscr;
writeln('TI SO: Ban:',s,' May:',y);
delay(1400);
end;
if (p=1) and (ai=3) then begin
s:=s+1;
y:=y;
writeln('Ban chon keo ||| May chon bao => BAN THANG!');
delay(2000);
clrscr;
writeln('TI SO: Ban:',s-1,' May:',y);
delay(1000);
clrscr;
writeln('TI SO: Ban:',s,' May:',y);
delay(1400);
end;
if (p-ai=-1) and (ai=3) then begin
s:=s;
y:=y+1;
writeln('Ban chon bua ||| May chon bao => MAY THANG!');
delay(2000);
clrscr;
writeln('TI SO: Ban:',s,' May:',y-1);
delay(1000);
clrscr;
writeln('TI SO: Ban:',s,' May:',y);
delay(1400);
end;
if (p-ai=-1) and (ai=2) then begin
s:=s;
y:=y+1;
writeln('Ban chon keo ||| May chon bua => MAY THANG!');
delay(1000);
clrscr;
writeln('TI SO: Ban:',s,' May:',y-1);
delay(1000);
clrscr;
writeln('TI SO: Ban:',s,' May:',y);
delay(1000);
end;
if (p=3) and (ai=1) then begin
s:=s;
y:=y+1;
writeln('Ban chon bao ||| May chon keo => MAY THANG!');
delay(1000);
clrscr;
writeln('TI SO: Ban:',s,' May:',y-1);
delay(1000);
clrscr;
writeln('TI SO: Ban:',s,' May:',y);
delay(1000);
end;
writeln('Nhan Enter de tiep tuc!');
readln;
until (s=10) or (y=10);
if s=10 then begin
clrscr;
writeln('CONGRATULATION! BAN DA THANG DUOC TRI TUE NHAN TAO');
end;
if (y=10) then begin
clrscr;
writeln('CHUC BAN MAY MAN LAN SAU');
end;
if (s=10) and (y=10) then begin
writeln;
writeln('CHUC MUNG!!! Ban da co duoc tri tue nhan tao!!!');
end;
for i:=10 downto 1 do
begin
writeln;
writeln('Chuong trinh se ket thuc sau:',i);
delay(1000);
clrscr;
end;
writeln('Tac gia: NGUYEN DANG KHOI');
readln;
end.

Mình đã nâng cấp chương trình game oẳn tù tì mà mình tình cờ xem được.
Mong các bạn cho mình xin ý kiến.
Về ý tưởng thì khá tốt, nhưng code em viết dài với xét quá nhiều trường hợp. Em có thể đặt điểm cho búa kéo bao, cái nào nhiều điểm hơn sẽ thắng.
Vd: bua=0, bao=1, keo=2
Rồi so sánh điểm của hai người chơi, chỉ cần xét một trường hợp đặc biệt.
Tiếp đến là đặt tên cho búa kéo bao và in ra màn hình thôi. Một trò chơi đơn giản nhưng e viết quá nhiều sẽ khó hiểu và khó nâng cấp lắm em.
Có thể chơi ăn gian bằng việc xét điểm người chơi rồi cho máy điểm cao hơn.
 
  • Like
Reactions: Timeless time

trà nguyễn hữu nghĩa

Cựu Mod Vật Lí |Cây bút Thơ|Thần tượng VH
Thành viên
14 Tháng năm 2017
3,974
7,623
744
22
Phú Yên
Trường THPT Lương Văn Chánh
kiểm tra lỗi thì không sai nhưng chạy thì ko thấy gì
lm sao đây ad
Game Cờ Vua này mình viết bằng graph và hiện tại thì Pascal nó không hỗ trợ nữa. Ngay cả free Pascal cũng thế.
Việc soạn code sẽ hơi cồng kềnh nên bạn có thể xem cho đỡ "thèm" ha :p
 
Top Bottom