Game Đá bóng 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,619
744
21
Phú Yên
Trường THPT Lương Văn Chánh
[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.

Game hơi khó chơi vì trình độ của mình có hạn. Bạn nào có thể cải tiến nó giúp mình không (Có thể chỉ cho mình cách để các đối tượng hoạt động song song không phụ thuộc vào thứ tự)
Đây là code Game:

Program Game_Bong_Da;
uses crt,dos;
const
ChieuRong = 60;
ChieuCao = 23;
KhoangCachDong = 1;
KhoangCachCot = 0;
ChieuRongKhungThanh = 8;

SoCauThu = 8;

Front = 1;
BeHind = 2;
Left = 3;
Right = 4;

Tocdo = 15;

type
TSanBong = object
Procedure VeSanBong;
Procedure KhoiTaoCauThu;
end;
TViTri = object
X, Y : integer;
Procedure SetViTri(vtX, vtY: integer);
end;
TGioiHan = object
X1, X2, Y1, Y2 : integer;
Procedure SetGioiHan(vtX1, vtY1, vtX2, vtY2 : integer);
end;

TBong = object
Sohuu : array[0..2,0..SoCauThu] of Boolean;
Vitri : TVitri;
Procedure SetSoHuu(doi, ten : integer);
Procedure InBong(doi, caut, Huong : integer);
Procedure CanBong;
Procedure SutBong(Huong : integer);
Function HuongChuyenBong(doi, caut : integer) : integer;
Procedure XuLi;
end;

TCauThu = object
Doi : integer;
Ten : integer;
GioiHan : TGioiHan;
Vitri : TVitri;
MauAo : Word;
KeyPress : Char;

Procedure SetCauThuHT;
Procedure InHinh(vtX,vtY : integer);
Procedure GianhBong;
Procedure DichuyenNgauNhien;
Procedure DiChuyen(Key : char);
end;
TMayTinh = object
CauThuHT : array[1..2] of integer;
PT : Boolean;
Procedure KiemTra;
Procedure TanCong;
Procedure PhongThu;
end;

var
LastHuong,HuongChuyen,CauThuHT : integer;
san : TSanBong;
cauthu : array[1..2,1..SoCauThu] of TCauThu;
QBong : TBong;
DangSut,vtMax,DangChuyen : Boolean;
DiemSo : array[1..2] of integer;
MayTinh : TMayTinh;

procedure setcusor(bot,top: byte);
var regs : registers;
begin
regs.ah := 1;
regs.ch:= bot;
regs.cl:= top;
intr($10, regs);
end;

Procedure TViTri.SetVitri(vtX, vtY : integer);
Begin
X := vtX;
Y := vtY;
End;

Procedure TGioiHan.SetGioiHan(vtX1, vtY1, vtX2, vtY2 : integer);
Begin
X1 := vtX1;
Y1 := vtY1;
X2 := vtX2;
Y2 := vtY2;
End;

(*==============S Bong===============================*)
Procedure TBong.SetSoHuu(doi, ten: integer);
var d,t : integer;
Begin
for d := 0 to 2 do
for t := 0 to SoCauThu do
begin
if (d = doi) and (t = ten) then
SoHuu[d, t] := True
else
SoHuu[d, t] := False;
end;
End;

Procedure TBong.InBong(doi, caut, Huong : integer);
Begin
if (QBong.SoHuu[doi, caut]) and (not DangSut) then
begin
if LastHuong <> Huong then
begin
GotoXy(Vitri.X,Vitri.Y);
Write(#32);
end;
case Huong of
Front : begin
TextColor(white);
Vitri.X := CauThu[doi,caut].Vitri.X;
Vitri.Y := CauThu[doi,caut].Vitri.Y-1;
GotoXy(Vitri.X,Vitri.Y);
Write(#265);
end;
BeHind : begin
TextColor(white);
Vitri.X := CauThu[doi,caut].Vitri.X;
Vitri.Y := CauThu[doi,caut].Vitri.Y+1;
GotoXy(Vitri.X,Vitri.Y);
Write(#265);
end;
Left : begin
TextColor(white);
Vitri.X := CauThu[doi,caut].Vitri.X - 1;
Vitri.Y := CauThu[doi,caut].Vitri.Y;
GotoXy(Vitri.X,Vitri.Y);
Write(#265);
end;
Right : begin
TextColor(white);
Vitri.X := CauThu[doi,caut].Vitri.X + 1;
Vitri.Y := CauThu[doi,caut].Vitri.Y;
GotoXy(Vitri.X,Vitri.Y);
Write(#265);
end;
end;
LastHuong := Huong;
if (Vitri.Y <= Khoangcachdong+1) or
(Vitri.Y >= KhoangCachDong+ChieuCao) or
(Vitri.X <= KhoangCachcot+1) or
(Vitri.X >= KhoangCachcot + chieurong) then
begin
vtMax := True;
DangSut := True;
end;
CanBong;
end;
End;

Procedure TBong.SutBong(Huong : integer);
Begin
if not vtMax then
begin
GotoXy(Vitri.X,Vitri.Y);
Write(#32);
end;
case Huong of
Front : if Vitri.Y > Khoangcachdong+1 then
begin
TextColor(white);
Vitri.X := Vitri.X;
Vitri.Y := Vitri.Y-2;
GotoXy(Vitri.X,Vitri.Y);
Write(#265);
end;
BeHind :if Vitri.Y < Khoangcachdong+ChieuCao then
begin
TextColor(white);
Vitri.X := Vitri.X;
Vitri.Y := Vitri.Y+2;
GotoXy(Vitri.X,Vitri.Y);
Write(#265);
end;
Left :if Vitri.X > KhoangcachCot+1 then
begin
TextColor(white);
Vitri.X := Vitri.X - 2;
Vitri.Y := Vitri.Y;
GotoXy(Vitri.X,Vitri.Y);
Write(#265);
end;
Right :if Vitri.X < KhoangcachCot+ChieuRong then
begin
TextColor(white);
Vitri.X := Vitri.X + 2;
Vitri.Y := Vitri.Y;
GotoXy(Vitri.X,Vitri.Y);
Write(#265);
end;
end;
if (Vitri.Y <= Khoangcachdong+1) or
(Vitri.Y >= KhoangCachDong+ChieuCao) or
(Vitri.X <= KhoangCachcot+1) or
(Vitri.X >= KhoangCachcot + chieurong) then
begin
vtMax := True;
end;
CanBong;
Cauthu[1,1].SetCauThuHT;
End;

Procedure TBong.CanBong;
var doi,caut : integer;
Begin
for doi := 1 to 2 do
for caut := 1 to Socauthu do
begin
if (CauThu[doi,caut].Vitri.X = Vitri.X)
and (CauThu[doi,caut].Vitri.Y = Vitri.Y) then
begin
SetSoHuu(doi,caut);
if CauThu[doi,caut].Vitri.Y > ChieuCao div 2 then
begin
InBong(doi,caut,Front);
Cauthu[doi,caut].Vitri.Y := Cauthu[doi,caut].Vitri.Y-1;
end
else
begin
InBong(doi,caut,Behind);
Cauthu[doi,caut].Vitri.Y := Cauthu[doi,caut].Vitri.Y+1;
end;
TextColor(Cauthu[doi,caut].MauAo);
GotoXy(Cauthu[doi,caut].Vitri.X,CauThu[doi,caut].Vitri.Y);
Write(#258);
DangSut := False;
DangChuyen := False;
end;
end;
end;

Function TBong.HuongChuyenBong(doi, caut : integer) : integer;

var ct,Min,Tam,Huong : integer;
Begin
Min := ChieuRong+ChieuCao;
for ct := 1 to SoCauThu do
if ct <> caut then
begin
Tam := Cauthu[doi, ct].Vitri.X - Cauthu[doi, caut].Vitri.X;
if Abs(Min) > Abs(Tam) then
begin
Min := Tam;
if Min < 0 then Huong := Left
else if Min > 0 then Huong := Right;
end;
Tam := Cauthu[doi, ct].Vitri.Y - Cauthu[doi, caut].Vitri.Y;
if Abs(Min) > Abs(Tam) then
begin
Min := Tam;
if Min < 0 then Huong := Front
else if Min > 0 then Huong := BeHind;
end;
HuongChuyenBong := Huong;
end;

End;

Procedure TBong.XuLi;
Begin
if (vtMax) and (Vitri.X >= CauThu[1,1].GioiHan.X1)
and (Vitri.X <= CauThu[1,1].GioiHan.X2)
and (DangSut or Dangchuyen) then
begin
DangSut := False;
DangChuyen := False;
vtMax := False;

if (Vitri.Y > ChieuCao div 2) then
begin
Inc(DiemSo[2]);
SetSoHuu(1,1);
Cauthu[1,CauThuHT].MauAo := Green;
CauThuHT:=1;
InBong(1,CauThuHT,Front);
end
else
begin
Inc(DiemSo[1]);
SetSoHuu(2,1);
InBong(2,1,BeHind);
end;
San.VeSanBong;
TextColor(Cyan);
GoToXy(65,7); Write(' Cau Thu : ',CauThuHT);
goToxy(65,9); Write(' May : ',DiemSo[2]);
goToxy(65,11);Write('Nguoi Choi : ',DiemSo[1]);
end
else
if vtMax then
begin
SetSoHuu(0,0);
ViTri.SetVitri(ChieuRong div 2 + KhoangCachCot,
chieuCao div 2 + KhoangCachDong);
Textcolor(White);
GotoXy(Vitri.X,Vitri.Y);write(#265);
San.VeSanBong;
DangSut := False;
DangChuyen := False;
vtMax := False;
end;
Textcolor(Red);
GotoXy((ChieuRong + KhoangCachCot - 20) div 2,(ChieuCao + KhoangCachDong) div 2);
if diemSo[1] >= 10 then
begin
Write('Nguoi Choi Thang Roi.');
readln;
Cauthu[1,CauThuHT].KeyPress := #27;
end
else if diemso[2] >= 10 then
begin
Write('May Thang Roi.');
readln;
Cauthu[1,CauThuHT].KeyPress := #27;
end;
end;
(*==============E Bong===============================*)

(*==============S San Bong===========================*)
Procedure TSanBong.KhoiTaoCauThu;
var Vt : TViTri;
i : integer;
Begin
CauThu[2,1].Doi := 2;
CauThu[1,1].Doi := 1;
CauThu[1,1].Ten := 1;
CauThu[2,1].Ten := 1;
for i := 2 to SoCauThu do
begin
CauThu[1,i].GioiHan.SetGioiHan(KhoangCachCot+2,KhoangCachDong+2,
KhoangCachCot+ChieuRong-1,KhoangCachDong+ChieuCao-1);
CauThu[1,i].MauAo := Green;
Cauthu[1,i].Doi := 1;
CauThu[1,i].Ten := i;
CauThu[2,i].GioiHan.SetGioiHan(KhoangCachCot+2,KhoangCachDong+2,
KhoangCachCot+ChieuRong-1,KhoangCachDong+ChieuCao-1);
CauThu[2,i].MauAo := Blue;
Cauthu[2,i].Doi := 2;
CauThu[2,i].Ten := i;
end;
for i := 1 to SoCauThu do
begin
repeat
Vt.X := RanDom(Cauthu[1,i].GioiHan.X2+1) + KhoangCachCot;
Vt.Y := Random(CauThu[1,i].GioiHan.Y2+1) + KhoangCachDong;
until (Vt.X >= Cauthu[1,i].GioiHan.X1)
and (Vt.X <= CauThu[1,i].GioiHan.X2)
and (Vt.Y >= CauThu[1,i].GioiHan.Y1)
and (Vt.Y <= Cauthu[1,i].GioiHan.Y2);
CauThu[1,i].Vitri := Vt;
Vt.SetViTri(0, 0);
end;

for i := 1 to SoCauThu do
begin
repeat
Vt.X := RanDom(Cauthu[2,i].GioiHan.X2+1) + KhoangCachCot;
Vt.Y := Random(Cauthu[2,i].GioiHan.Y2+1) + KhoangCachDong;
until (Vt.X >= Cauthu[2,i].GioiHan.X1)
and (Vt.X <= CauThu[2,i].GioiHan.X2)
and (Vt.Y >= CauThu[2,i].GioiHan.Y1)
and (Vt.Y <= Cauthu[2,i].GioiHan.Y2);
CauThu[2,i].Vitri := Vt;
Vt.SetViTri(0, 0);
end;
for i := 1 to SoCauThu do
begin
TextColor(cauthu[1,i].MauAo);
gotoxy(cauthu[1,i].vitri.X,cauthu[1,i].Vitri.Y);
Write(#258);
TextColor(cauthu[2,i].MauAo);
gotoxy(cauthu[2,i].vitri.X,cauthu[2,i].Vitri.Y);
Write(#258);
end;
End;

Procedure TSanBong.VeSanBong;
var i: integer;
Begin
clrscr;
TextColor(Yellow);
for i := 1 to ChieuRong do
begin
GotoXy(KhoangCachCot + i,KhoangCachDong);
Write(#177);
GotoXy(KhoangCachCot + i,KhoangCachDong+ChieuCao+1);
Write(#177);
end; { Ve Khung Ngang }

for i := 1 to ChieuCao do
begin
GotoXy(KhoangCachCot + 1,KhoangCachDong + i);
Write(#177);
GotoXy(KhoangCachCot + ChieuRong,KhoangCachDong+i);
Write(#177);
end; { Ve Khung Doc }

TextColor(LightGreen);
i := (ChieuRong - ChieuRongKhungThanh) div 2 + KhoangCachCot;
GotoXy(i,KhoangCachDong+1);
CauThu[1,1].GioiHan.SetGioiHan(i,KhoangCachDong+ChieuCao -
1 - ChieuRongKhungThanh div 2,
i+ChieuRongKhungThanh-1,KhoangCachDong+ChieuCao - 1);
{ Set Gioi Han Thu Mon}
CauThu[1,1].MauAo := LightGreen;
for i := 1 to ChieuRongKhungThanh do
Write(#177);
{ Ve Khung Thanh May}
TextColor(Cyan);
i := (ChieuRong - ChieuRongKhungThanh) div 2 + KhoangCachCot;
GotoXy(i,KhoangCachDong+ChieuCao);
CauThu[2,1].GioiHan.SetGioiHan(i,KhoangCachDong+2,
i+ChieuRongKhungthanh-1,ChieuRongKhungThanh div 2+KhoangCachDong+2);
{Set Gioi Han Thu Mon}
CauThu[2,1].MauAo := Cyan;
for i := 1 to ChieuRongKhungThanh do
Write(#177); { Ve Khung Thanh Nguoi Choi}
KhoiTaoCauThu;
TextColor(Cyan);
GoToXy(65,7); Write(' Cau Thu : ',CauThuHT);
goToxy(65,9); Write(' May : ',DiemSo[1]);
goToxy(65,11);Write('Nguoi Choi : ',DiemSo[2]);
Delay(1000);
End;
(*==============E San Bong===========================*)

(*==============S Cau Thu============================*)
Procedure TCauThu.SetCauThuHT;
var i,min,tamthoi1,tamthoi2,cautht: integer;
TroLai : boolean;
Begin
TroLai := True;
if (not Qbong.Sohuu[1,CauThuHT]) or (QBong.soHuu[0,0]) then
TroLai := False;
if not TroLai then
begin
Min := ChieuRong + ChieuCao;
cautht := CauThuHT;
for i := 1 to SoCauThu do
begin
tamthoi1 := Cauthu[doi,i].Vitri.X - QBong.Vitri.X;
tamthoi2 := Cauthu[doi,i].Vitri.Y - QBong.Vitri.Y;
if ABs(Min) > (ABs(TamThoi1)+Abs(Tamthoi2)) then
begin
Min := TamThoi1+Tamthoi2;
cautht := i;
end;
end;
if (cautht = 1) and ((QBong.Vitri.X < Cauthu[doi,cautht].GioiHan.X1)
or (QBong.Vitri.X > Cauthu[doi,cautht].GioiHan.X2) or
(QBong.Vitri.Y < Cauthu[doi,cautht].GioiHan.Y1) or
(QBong.Vitri.Y > Cauthu[doi,cautht].GioiHan.Y2)) then
cautht := 2;

if (CauThuHT = 1) and (doi = 2) then
CauThu[doi,CauThuHT].MauAo := Cyan
else if (CauThuHT <> 1) and (doi = 2) then
CauThu[doi,CauThuHT].MauAo := Blue
else if (CauThuHT = 1) and (doi = 1) then
CauThu[doi,CauThuHT].MauAo := LightGreen
else if (CauThuHT <> 1) and (doi = 1) then
CauThu[doi,CauThuHT].MauAo := Green;
CauThuHT := cautht;
TextColor(Cyan);
GoToXy(65,7);Write(' Cau Thu : ',CauThuHT);
end;
end;

Procedure TCauThu.InHinh(vtX, vtY : integer);
Begin
GotoXy(Vitri.X,Vitri.Y);
Write(#32);
Vitri.X := vtX;
Vitri.Y := vtY;
TextColor(MauAo);
GotoXy(Vitri.X,Vitri.Y);
Write(#258);
End;

Procedure TCauThu.GianhBong;
Begin
if not Qbong.SoHuu[Doi,Ten] then
begin
if (Qbong.Vitri.X = Vitri.X-1) and (Qbong.Vitri.Y = Vitri.Y) then
begin
SetCauthuHT;
Qbong.SetSoHuu(Doi,Ten);
Qbong.InBong(Doi,Ten,Front);
end
else if (Qbong.Vitri.X = Vitri.X+1) and (Qbong.Vitri.Y = Vitri.Y) then
begin
SetCauthuHT;
Qbong.SetSoHuu(Doi,Ten);
Qbong.InBong(Doi,Ten,Front);
end
else if (Qbong.Vitri.X = Vitri.X) and (Qbong.Vitri.Y = Vitri.Y-1) then
begin
SetCauthuHT;
Qbong.SetSoHuu(Doi,Ten);
Qbong.InBong(Doi,Ten,Front);
end
else if (Qbong.Vitri.X = Vitri.X) and (Qbong.Vitri.Y = Vitri.Y+1) then
begin
SetCauthuHT;
Qbong.SetSoHuu(Doi,Ten);
Qbong.InBong(Doi,Ten,Front);
end;
end;
end;

Procedure TCauThu.DiChuyenNgauNhien;
var Phim : integer;
Key : Char;
Begin
Phim := Random(7);
case Phim of
1 : begin
Key := #72;
end;
2 : begin
Key := #75;
end;
3 : begin
Key := #77;
end;
4 : begin
Key := #80;
end;
5 : begin
Key := #32;
end;
6 : begin
Key := #13;
end;
end;
KeyPress := Key;
End;

Procedure TCauThu.DiChuyen(Key : char);
Begin
case Key of
#72,#119:if (vitri.Y > GioiHan.Y1) then
begin
InHinh(Vitri.X,ViTri.Y - 1);
QBong.InBong(Doi,Ten, Front);
GianhBong;
delay(Tocdo);
end;
#80,#115:if (Vitri.Y < GioiHan.Y2) then
begin
InHinh(Vitri.X,Vitri.Y+1);
QBong.InBong(Doi,Ten, BeHind);
GianhBong;
delay(Tocdo);
end;
#75,#97: if (vitri.X > GioiHan.X1) then
begin
InHinh(Vitri.X-1,vitri.Y);
QBong.InBong(Doi,Ten, Left);
GianhBong;
delay(Tocdo);
end;
#77,#100:if (Vitri.X < GioiHan.X2) then
begin
InHinh(ViTri.X+1,ViTri.Y);
QBong.InBong(Doi,Ten, Right);
GianhBong;
delay(Tocdo);
end;
#13 : if QBong.SoHuu[doi,ten] then begin
QBong.SetSoHuu(0, 0);
DangSut := True;
end;
#32 : if QBong.SoHuu[doi,ten] then begin
QBong.SetSoHuu(0, 0);
DangChuyen := True;
HuongChuyen := QBong.HuongChuyenBong(doi,ten);
end;
end;
End;
(*==============E Cau Thu============================*)
(*==============S May Tinh===========================*)
Procedure TMayTinh.KiemTra;
var ct,Min,Tamthoi,caut : integer;
Begin
Min := ChieuCao + ChieuRong;
for ct := 1 to SoCauThu do
begin
TamThoi := Abs(CauThu[2,ct].Vitri.X - QBong.Vitri.X)
+ Abs(CauThu[2,ct].Vitri.Y - QBong.Vitri.Y);
if (Min) > TamThoi then
begin
Min := TamThoi;
caut := ct;
end;
end;
CauThuHT[1] := caut;

Min := ChieuCao + ChieuRong;
for ct := 1 to SoCauThu do
if (ct <> CauthuHT[1]) then
begin
TamThoi := Abs(CauThu[2,ct].Vitri.X - QBong.Vitri.X)
+ Abs(CauThu[2,ct].Vitri.Y - QBong.Vitri.Y);
if (Min > TamThoi) then
begin
Min := TamThoi;
caut := ct;
end;
end;
CauThuHT[2] := caut;
end;

Procedure TMayTinh.TanCong;
var i,ct,j : integer;
begin
ct := 0;
KiemTra;
for i := 1 to 2 do
if QBong.Sohuu[2,CauThuHT] then
ct := i;
i := ct;
PT := True;
if i <> 0 then
begin
PT := False;
if (CauThu[2,CauThuHT].Vitri.Y < CauThu[1,1].GioiHan.Y2) then
begin
CauThu[2,CauThuHT].DiChuyen(#80);
end
else
if (CauThu[2,CauThuHT].Vitri.X < (CauThu[1,1].GioiHan.X2
+ CauThu[1,1].GioiHan.X1) div 2) then
begin
CauThu[2,CauThuHT].DiChuyen(#77);
end
else
if (CauThu[2,CauThuHT].Vitri.X > (CauThu[1,1].GioiHan.X2
+ CauThu[1,1].GioiHan.X1) div 2) then
begin
CauThu[2,CauThuHT].DiChuyen(#75);
end;
for j := 1 to SoCauthu do
if j <> i then
Begin
CauThu[2,j].DiChuyenNgauNhien;
CauThu[2,j].Dichuyen(Cauthu[2,j].KeyPress)
end;
end;
end;

Procedure TMayTinh.PhongThu;
var i,j: integer;
Begin
KiemTra;
PT := False;
for i := 1 to 2 do
if (not QBong.Sohuu[2,CauThuHT]) and (not QBong.SoHuu[1,1]) then
begin
if (CauThu[2,CauThuHT].Vitri.Y < QBong.Vitri.Y) then
begin
CauThu[2,CauThuHT].DiChuyen(#80);
end
else
if (CauThu[2,CauThuHT].Vitri.Y > QBong.Vitri.Y) then
begin
CauThu[2,CauThuHT].DiChuyen(#72);
end
else
if (CauThu[2,CauThuHT].Vitri.X < QBong.Vitri.X-1) then
begin
CauThu[2,CauThuHT].DiChuyen(#77);
end
else
if (CauThu[2,CauThuHT].Vitri.X > QBong.Vitri.X+1) then
begin
CauThu[2,CauThuHT].DiChuyen(#75);
end;
PT := True;
for j := 1 to SoCauthu do
if j <> i then
Begin
CauThu[2,j].DiChuyenNgauNhien;
CauThu[2,j].Dichuyen(Cauthu[2,j].KeyPress)
end;
end;
end;

(*==============E May Tinh===========================*)

Procedure NewGame;
Begin
clrscr;
SetCusor(32,0);
San.VeSanBong;
QBong.SetSoHuu(0, 0);
TextColor(White);
Qbong.vitri.SetVitri(ChieuRong div 2 + KhoangCachCot,
chieuCao div 2 + KhoangCachDong);
GotoXy(QBong.Vitri.X,QBong.Vitri.Y);
Write(#265);
CauthuHT := 2;
DangSut := False;
DangChuyen := False;
end;

Procedure PlayerPlay;
var i : integer;
Begin
Cauthu[1,CauThuHT].MauAo := Red;
if Keypressed then
begin
Cauthu[1,CauThuHT].KeyPress := readkey;
for i := 1 To SoCauThu do
if i <> CauThuHT then
Cauthu[1,i].DichuyenNgauNhien;
end;
Cauthu[1,CauThuHT].DiChuyen(Cauthu[1,CauThuHT].KeyPress);
for i := 1 To SoCauThu do
if i <> CauThuHT then
Cauthu[1,i].Dichuyen(Cauthu[1,i].KeyPress);
if Dangsut then QBong.SutBong(LastHuong)
else if DangChuyen then QBong.SutBong(HuongChuyen);
MayTinh.PhongThu;
MayTinh.TanCong;
QBong.XuLi;
Cauthu[1,1].SetCauThuHT;
end;

BEGIN
NewGame;
repeat
PlayerPlay;
if MayTinh.PT then
until Cauthu[1,CauThuHT].KeyPress = #27;
END.
 

Blue Plus

Cựu TMod Toán|Quán quân WC18
Thành viên
TV ấn tượng nhất 2017
7 Tháng tám 2017
4,506
10,437
1,114
Khánh Hòa
$\color{Blue}{\text{Bỏ học}}$
Game hơi khó chơi vì trình độ của mình có hạn. Bạn nào có thể cải tiến nó giúp mình không (Có thể chỉ cho mình cách để các đối tượng hoạt động song song không phụ thuộc vào thứ tự)
Đây là code Game:

Program Game_Bong_Da;
uses crt,dos;
const
ChieuRong = 60;
ChieuCao = 23;
KhoangCachDong = 1;
KhoangCachCot = 0;
ChieuRongKhungThanh = 8;

SoCauThu = 8;

Front = 1;
BeHind = 2;
Left = 3;
Right = 4;

Tocdo = 15;

type
TSanBong = object
Procedure VeSanBong;
Procedure KhoiTaoCauThu;
end;
TViTri = object
X, Y : integer;
Procedure SetViTri(vtX, vtY: integer);
end;
TGioiHan = object
X1, X2, Y1, Y2 : integer;
Procedure SetGioiHan(vtX1, vtY1, vtX2, vtY2 : integer);
end;

TBong = object
Sohuu : array[0..2,0..SoCauThu] of Boolean;
Vitri : TVitri;
Procedure SetSoHuu(doi, ten : integer);
Procedure InBong(doi, caut, Huong : integer);
Procedure CanBong;
Procedure SutBong(Huong : integer);
Function HuongChuyenBong(doi, caut : integer) : integer;
Procedure XuLi;
end;

TCauThu = object
Doi : integer;
Ten : integer;
GioiHan : TGioiHan;
Vitri : TVitri;
MauAo : Word;
KeyPress : Char;

Procedure SetCauThuHT;
Procedure InHinh(vtX,vtY : integer);
Procedure GianhBong;
Procedure DichuyenNgauNhien;
Procedure DiChuyen(Key : char);
end;
TMayTinh = object
CauThuHT : array[1..2] of integer;
PT : Boolean;
Procedure KiemTra;
Procedure TanCong;
Procedure PhongThu;
end;

var
LastHuong,HuongChuyen,CauThuHT : integer;
san : TSanBong;
cauthu : array[1..2,1..SoCauThu] of TCauThu;
QBong : TBong;
DangSut,vtMax,DangChuyen : Boolean;
DiemSo : array[1..2] of integer;
MayTinh : TMayTinh;

procedure setcusor(bot,top: byte);
var regs : registers;
begin
regs.ah := 1;
regs.ch:= bot;
regs.cl:= top;
intr($10, regs);
end;

Procedure TViTri.SetVitri(vtX, vtY : integer);
Begin
X := vtX;
Y := vtY;
End;

Procedure TGioiHan.SetGioiHan(vtX1, vtY1, vtX2, vtY2 : integer);
Begin
X1 := vtX1;
Y1 := vtY1;
X2 := vtX2;
Y2 := vtY2;
End;

(*==============S Bong===============================*)
Procedure TBong.SetSoHuu(doi, ten: integer);
var d,t : integer;
Begin
for d := 0 to 2 do
for t := 0 to SoCauThu do
begin
if (d = doi) and (t = ten) then
SoHuu[d, t] := True
else
SoHuu[d, t] := False;
end;
End;

Procedure TBong.InBong(doi, caut, Huong : integer);
Begin
if (QBong.SoHuu[doi, caut]) and (not DangSut) then
begin
if LastHuong <> Huong then
begin
GotoXy(Vitri.X,Vitri.Y);
Write(#32);
end;
case Huong of
Front : begin
TextColor(white);
Vitri.X := CauThu[doi,caut].Vitri.X;
Vitri.Y := CauThu[doi,caut].Vitri.Y-1;
GotoXy(Vitri.X,Vitri.Y);
Write(#265);
end;
BeHind : begin
TextColor(white);
Vitri.X := CauThu[doi,caut].Vitri.X;
Vitri.Y := CauThu[doi,caut].Vitri.Y+1;
GotoXy(Vitri.X,Vitri.Y);
Write(#265);
end;
Left : begin
TextColor(white);
Vitri.X := CauThu[doi,caut].Vitri.X - 1;
Vitri.Y := CauThu[doi,caut].Vitri.Y;
GotoXy(Vitri.X,Vitri.Y);
Write(#265);
end;
Right : begin
TextColor(white);
Vitri.X := CauThu[doi,caut].Vitri.X + 1;
Vitri.Y := CauThu[doi,caut].Vitri.Y;
GotoXy(Vitri.X,Vitri.Y);
Write(#265);
end;
end;
LastHuong := Huong;
if (Vitri.Y <= Khoangcachdong+1) or
(Vitri.Y >= KhoangCachDong+ChieuCao) or
(Vitri.X <= KhoangCachcot+1) or
(Vitri.X >= KhoangCachcot + chieurong) then
begin
vtMax := True;
DangSut := True;
end;
CanBong;
end;
End;

Procedure TBong.SutBong(Huong : integer);
Begin
if not vtMax then
begin
GotoXy(Vitri.X,Vitri.Y);
Write(#32);
end;
case Huong of
Front : if Vitri.Y > Khoangcachdong+1 then
begin
TextColor(white);
Vitri.X := Vitri.X;
Vitri.Y := Vitri.Y-2;
GotoXy(Vitri.X,Vitri.Y);
Write(#265);
end;
BeHind :if Vitri.Y < Khoangcachdong+ChieuCao then
begin
TextColor(white);
Vitri.X := Vitri.X;
Vitri.Y := Vitri.Y+2;
GotoXy(Vitri.X,Vitri.Y);
Write(#265);
end;
Left :if Vitri.X > KhoangcachCot+1 then
begin
TextColor(white);
Vitri.X := Vitri.X - 2;
Vitri.Y := Vitri.Y;
GotoXy(Vitri.X,Vitri.Y);
Write(#265);
end;
Right :if Vitri.X < KhoangcachCot+ChieuRong then
begin
TextColor(white);
Vitri.X := Vitri.X + 2;
Vitri.Y := Vitri.Y;
GotoXy(Vitri.X,Vitri.Y);
Write(#265);
end;
end;
if (Vitri.Y <= Khoangcachdong+1) or
(Vitri.Y >= KhoangCachDong+ChieuCao) or
(Vitri.X <= KhoangCachcot+1) or
(Vitri.X >= KhoangCachcot + chieurong) then
begin
vtMax := True;
end;
CanBong;
Cauthu[1,1].SetCauThuHT;
End;

Procedure TBong.CanBong;
var doi,caut : integer;
Begin
for doi := 1 to 2 do
for caut := 1 to Socauthu do
begin
if (CauThu[doi,caut].Vitri.X = Vitri.X)
and (CauThu[doi,caut].Vitri.Y = Vitri.Y) then
begin
SetSoHuu(doi,caut);
if CauThu[doi,caut].Vitri.Y > ChieuCao div 2 then
begin
InBong(doi,caut,Front);
Cauthu[doi,caut].Vitri.Y := Cauthu[doi,caut].Vitri.Y-1;
end
else
begin
InBong(doi,caut,Behind);
Cauthu[doi,caut].Vitri.Y := Cauthu[doi,caut].Vitri.Y+1;
end;
TextColor(Cauthu[doi,caut].MauAo);
GotoXy(Cauthu[doi,caut].Vitri.X,CauThu[doi,caut].Vitri.Y);
Write(#258);
DangSut := False;
DangChuyen := False;
end;
end;
end;

Function TBong.HuongChuyenBong(doi, caut : integer) : integer;

var ct,Min,Tam,Huong : integer;
Begin
Min := ChieuRong+ChieuCao;
for ct := 1 to SoCauThu do
if ct <> caut then
begin
Tam := Cauthu[doi, ct].Vitri.X - Cauthu[doi, caut].Vitri.X;
if Abs(Min) > Abs(Tam) then
begin
Min := Tam;
if Min < 0 then Huong := Left
else if Min > 0 then Huong := Right;
end;
Tam := Cauthu[doi, ct].Vitri.Y - Cauthu[doi, caut].Vitri.Y;
if Abs(Min) > Abs(Tam) then
begin
Min := Tam;
if Min < 0 then Huong := Front
else if Min > 0 then Huong := BeHind;
end;
HuongChuyenBong := Huong;
end;

End;

Procedure TBong.XuLi;
Begin
if (vtMax) and (Vitri.X >= CauThu[1,1].GioiHan.X1)
and (Vitri.X <= CauThu[1,1].GioiHan.X2)
and (DangSut or Dangchuyen) then
begin
DangSut := False;
DangChuyen := False;
vtMax := False;

if (Vitri.Y > ChieuCao div 2) then
begin
Inc(DiemSo[2]);
SetSoHuu(1,1);
Cauthu[1,CauThuHT].MauAo := Green;
CauThuHT:=1;
InBong(1,CauThuHT,Front);
end
else
begin
Inc(DiemSo[1]);
SetSoHuu(2,1);
InBong(2,1,BeHind);
end;
San.VeSanBong;
TextColor(Cyan);
GoToXy(65,7); Write(' Cau Thu : ',CauThuHT);
goToxy(65,9); Write(' May : ',DiemSo[2]);
goToxy(65,11);Write('Nguoi Choi : ',DiemSo[1]);
end
else
if vtMax then
begin
SetSoHuu(0,0);
ViTri.SetVitri(ChieuRong div 2 + KhoangCachCot,
chieuCao div 2 + KhoangCachDong);
Textcolor(White);
GotoXy(Vitri.X,Vitri.Y);write(#265);
San.VeSanBong;
DangSut := False;
DangChuyen := False;
vtMax := False;
end;
Textcolor(Red);
GotoXy((ChieuRong + KhoangCachCot - 20) div 2,(ChieuCao + KhoangCachDong) div 2);
if diemSo[1] >= 10 then
begin
Write('Nguoi Choi Thang Roi.');
readln;
Cauthu[1,CauThuHT].KeyPress := #27;
end
else if diemso[2] >= 10 then
begin
Write('May Thang Roi.');
readln;
Cauthu[1,CauThuHT].KeyPress := #27;
end;
end;
(*==============E Bong===============================*)

(*==============S San Bong===========================*)
Procedure TSanBong.KhoiTaoCauThu;
var Vt : TViTri;
i : integer;
Begin
CauThu[2,1].Doi := 2;
CauThu[1,1].Doi := 1;
CauThu[1,1].Ten := 1;
CauThu[2,1].Ten := 1;
for i := 2 to SoCauThu do
begin
CauThu[1,i].GioiHan.SetGioiHan(KhoangCachCot+2,KhoangCachDong+2,
KhoangCachCot+ChieuRong-1,KhoangCachDong+ChieuCao-1);
CauThu[1,i].MauAo := Green;
Cauthu[1,i].Doi := 1;
CauThu[1,i].Ten := i;
CauThu[2,i].GioiHan.SetGioiHan(KhoangCachCot+2,KhoangCachDong+2,
KhoangCachCot+ChieuRong-1,KhoangCachDong+ChieuCao-1);
CauThu[2,i].MauAo := Blue;
Cauthu[2,i].Doi := 2;
CauThu[2,i].Ten := i;
end;
for i := 1 to SoCauThu do
begin
repeat
Vt.X := RanDom(Cauthu[1,i].GioiHan.X2+1) + KhoangCachCot;
Vt.Y := Random(CauThu[1,i].GioiHan.Y2+1) + KhoangCachDong;
until (Vt.X >= Cauthu[1,i].GioiHan.X1)
and (Vt.X <= CauThu[1,i].GioiHan.X2)
and (Vt.Y >= CauThu[1,i].GioiHan.Y1)
and (Vt.Y <= Cauthu[1,i].GioiHan.Y2);
CauThu[1,i].Vitri := Vt;
Vt.SetViTri(0, 0);
end;

for i := 1 to SoCauThu do
begin
repeat
Vt.X := RanDom(Cauthu[2,i].GioiHan.X2+1) + KhoangCachCot;
Vt.Y := Random(Cauthu[2,i].GioiHan.Y2+1) + KhoangCachDong;
until (Vt.X >= Cauthu[2,i].GioiHan.X1)
and (Vt.X <= CauThu[2,i].GioiHan.X2)
and (Vt.Y >= CauThu[2,i].GioiHan.Y1)
and (Vt.Y <= Cauthu[2,i].GioiHan.Y2);
CauThu[2,i].Vitri := Vt;
Vt.SetViTri(0, 0);
end;
for i := 1 to SoCauThu do
begin
TextColor(cauthu[1,i].MauAo);
gotoxy(cauthu[1,i].vitri.X,cauthu[1,i].Vitri.Y);
Write(#258);
TextColor(cauthu[2,i].MauAo);
gotoxy(cauthu[2,i].vitri.X,cauthu[2,i].Vitri.Y);
Write(#258);
end;
End;

Procedure TSanBong.VeSanBong;
var i: integer;
Begin
clrscr;
TextColor(Yellow);
for i := 1 to ChieuRong do
begin
GotoXy(KhoangCachCot + i,KhoangCachDong);
Write(#177);
GotoXy(KhoangCachCot + i,KhoangCachDong+ChieuCao+1);
Write(#177);
end; { Ve Khung Ngang }

for i := 1 to ChieuCao do
begin
GotoXy(KhoangCachCot + 1,KhoangCachDong + i);
Write(#177);
GotoXy(KhoangCachCot + ChieuRong,KhoangCachDong+i);
Write(#177);
end; { Ve Khung Doc }

TextColor(LightGreen);
i := (ChieuRong - ChieuRongKhungThanh) div 2 + KhoangCachCot;
GotoXy(i,KhoangCachDong+1);
CauThu[1,1].GioiHan.SetGioiHan(i,KhoangCachDong+ChieuCao -
1 - ChieuRongKhungThanh div 2,
i+ChieuRongKhungThanh-1,KhoangCachDong+ChieuCao - 1);
{ Set Gioi Han Thu Mon}
CauThu[1,1].MauAo := LightGreen;
for i := 1 to ChieuRongKhungThanh do
Write(#177);
{ Ve Khung Thanh May}
TextColor(Cyan);
i := (ChieuRong - ChieuRongKhungThanh) div 2 + KhoangCachCot;
GotoXy(i,KhoangCachDong+ChieuCao);
CauThu[2,1].GioiHan.SetGioiHan(i,KhoangCachDong+2,
i+ChieuRongKhungthanh-1,ChieuRongKhungThanh div 2+KhoangCachDong+2);
{Set Gioi Han Thu Mon}
CauThu[2,1].MauAo := Cyan;
for i := 1 to ChieuRongKhungThanh do
Write(#177); { Ve Khung Thanh Nguoi Choi}
KhoiTaoCauThu;
TextColor(Cyan);
GoToXy(65,7); Write(' Cau Thu : ',CauThuHT);
goToxy(65,9); Write(' May : ',DiemSo[1]);
goToxy(65,11);Write('Nguoi Choi : ',DiemSo[2]);
Delay(1000);
End;
(*==============E San Bong===========================*)

(*==============S Cau Thu============================*)
Procedure TCauThu.SetCauThuHT;
var i,min,tamthoi1,tamthoi2,cautht: integer;
TroLai : boolean;
Begin
TroLai := True;
if (not Qbong.Sohuu[1,CauThuHT]) or (QBong.soHuu[0,0]) then
TroLai := False;
if not TroLai then
begin
Min := ChieuRong + ChieuCao;
cautht := CauThuHT;
for i := 1 to SoCauThu do
begin
tamthoi1 := Cauthu[doi,i].Vitri.X - QBong.Vitri.X;
tamthoi2 := Cauthu[doi,i].Vitri.Y - QBong.Vitri.Y;
if ABs(Min) > (ABs(TamThoi1)+Abs(Tamthoi2)) then
begin
Min := TamThoi1+Tamthoi2;
cautht := i;
end;
end;
if (cautht = 1) and ((QBong.Vitri.X < Cauthu[doi,cautht].GioiHan.X1)
or (QBong.Vitri.X > Cauthu[doi,cautht].GioiHan.X2) or
(QBong.Vitri.Y < Cauthu[doi,cautht].GioiHan.Y1) or
(QBong.Vitri.Y > Cauthu[doi,cautht].GioiHan.Y2)) then
cautht := 2;

if (CauThuHT = 1) and (doi = 2) then
CauThu[doi,CauThuHT].MauAo := Cyan
else if (CauThuHT <> 1) and (doi = 2) then
CauThu[doi,CauThuHT].MauAo := Blue
else if (CauThuHT = 1) and (doi = 1) then
CauThu[doi,CauThuHT].MauAo := LightGreen
else if (CauThuHT <> 1) and (doi = 1) then
CauThu[doi,CauThuHT].MauAo := Green;
CauThuHT := cautht;
TextColor(Cyan);
GoToXy(65,7);Write(' Cau Thu : ',CauThuHT);
end;
end;

Procedure TCauThu.InHinh(vtX, vtY : integer);
Begin
GotoXy(Vitri.X,Vitri.Y);
Write(#32);
Vitri.X := vtX;
Vitri.Y := vtY;
TextColor(MauAo);
GotoXy(Vitri.X,Vitri.Y);
Write(#258);
End;

Procedure TCauThu.GianhBong;
Begin
if not Qbong.SoHuu[Doi,Ten] then
begin
if (Qbong.Vitri.X = Vitri.X-1) and (Qbong.Vitri.Y = Vitri.Y) then
begin
SetCauthuHT;
Qbong.SetSoHuu(Doi,Ten);
Qbong.InBong(Doi,Ten,Front);
end
else if (Qbong.Vitri.X = Vitri.X+1) and (Qbong.Vitri.Y = Vitri.Y) then
begin
SetCauthuHT;
Qbong.SetSoHuu(Doi,Ten);
Qbong.InBong(Doi,Ten,Front);
end
else if (Qbong.Vitri.X = Vitri.X) and (Qbong.Vitri.Y = Vitri.Y-1) then
begin
SetCauthuHT;
Qbong.SetSoHuu(Doi,Ten);
Qbong.InBong(Doi,Ten,Front);
end
else if (Qbong.Vitri.X = Vitri.X) and (Qbong.Vitri.Y = Vitri.Y+1) then
begin
SetCauthuHT;
Qbong.SetSoHuu(Doi,Ten);
Qbong.InBong(Doi,Ten,Front);
end;
end;
end;

Procedure TCauThu.DiChuyenNgauNhien;
var Phim : integer;
Key : Char;
Begin
Phim := Random(7);
case Phim of
1 : begin
Key := #72;
end;
2 : begin
Key := #75;
end;
3 : begin
Key := #77;
end;
4 : begin
Key := #80;
end;
5 : begin
Key := #32;
end;
6 : begin
Key := #13;
end;
end;
KeyPress := Key;
End;

Procedure TCauThu.DiChuyen(Key : char);
Begin
case Key of
#72,#119:if (vitri.Y > GioiHan.Y1) then
begin
InHinh(Vitri.X,ViTri.Y - 1);
QBong.InBong(Doi,Ten, Front);
GianhBong;
delay(Tocdo);
end;
#80,#115:if (Vitri.Y < GioiHan.Y2) then
begin
InHinh(Vitri.X,Vitri.Y+1);
QBong.InBong(Doi,Ten, BeHind);
GianhBong;
delay(Tocdo);
end;
#75,#97: if (vitri.X > GioiHan.X1) then
begin
InHinh(Vitri.X-1,vitri.Y);
QBong.InBong(Doi,Ten, Left);
GianhBong;
delay(Tocdo);
end;
#77,#100:if (Vitri.X < GioiHan.X2) then
begin
InHinh(ViTri.X+1,ViTri.Y);
QBong.InBong(Doi,Ten, Right);
GianhBong;
delay(Tocdo);
end;
#13 : if QBong.SoHuu[doi,ten] then begin
QBong.SetSoHuu(0, 0);
DangSut := True;
end;
#32 : if QBong.SoHuu[doi,ten] then begin
QBong.SetSoHuu(0, 0);
DangChuyen := True;
HuongChuyen := QBong.HuongChuyenBong(doi,ten);
end;
end;
End;
(*==============E Cau Thu============================*)
(*==============S May Tinh===========================*)
Procedure TMayTinh.KiemTra;
var ct,Min,Tamthoi,caut : integer;
Begin
Min := ChieuCao + ChieuRong;
for ct := 1 to SoCauThu do
begin
TamThoi := Abs(CauThu[2,ct].Vitri.X - QBong.Vitri.X)
+ Abs(CauThu[2,ct].Vitri.Y - QBong.Vitri.Y);
if (Min) > TamThoi then
begin
Min := TamThoi;
caut := ct;
end;
end;
CauThuHT[1] := caut;

Min := ChieuCao + ChieuRong;
for ct := 1 to SoCauThu do
if (ct <> CauthuHT[1]) then
begin
TamThoi := Abs(CauThu[2,ct].Vitri.X - QBong.Vitri.X)
+ Abs(CauThu[2,ct].Vitri.Y - QBong.Vitri.Y);
if (Min > TamThoi) then
begin
Min := TamThoi;
caut := ct;
end;
end;
CauThuHT[2] := caut;
end;

Procedure TMayTinh.TanCong;
var i,ct,j : integer;
begin
ct := 0;
KiemTra;
for i := 1 to 2 do
if QBong.Sohuu[2,CauThuHT] then
ct := i;
i := ct;
PT := True;
if i <> 0 then
begin
PT := False;
if (CauThu[2,CauThuHT].Vitri.Y < CauThu[1,1].GioiHan.Y2) then
begin
CauThu[2,CauThuHT].DiChuyen(#80);
end
else
if (CauThu[2,CauThuHT].Vitri.X < (CauThu[1,1].GioiHan.X2
+ CauThu[1,1].GioiHan.X1) div 2) then
begin
CauThu[2,CauThuHT].DiChuyen(#77);
end
else
if (CauThu[2,CauThuHT].Vitri.X > (CauThu[1,1].GioiHan.X2
+ CauThu[1,1].GioiHan.X1) div 2) then
begin
CauThu[2,CauThuHT].DiChuyen(#75);
end;
for j := 1 to SoCauthu do
if j <> i then
Begin
CauThu[2,j].DiChuyenNgauNhien;
CauThu[2,j].Dichuyen(Cauthu[2,j].KeyPress)
end;
end;
end;

Procedure TMayTinh.PhongThu;
var i,j: integer;
Begin
KiemTra;
PT := False;
for i := 1 to 2 do
if (not QBong.Sohuu[2,CauThuHT]) and (not QBong.SoHuu[1,1]) then
begin
if (CauThu[2,CauThuHT].Vitri.Y < QBong.Vitri.Y) then
begin
CauThu[2,CauThuHT].DiChuyen(#80);
end
else
if (CauThu[2,CauThuHT].Vitri.Y > QBong.Vitri.Y) then
begin
CauThu[2,CauThuHT].DiChuyen(#72);
end
else
if (CauThu[2,CauThuHT].Vitri.X < QBong.Vitri.X-1) then
begin
CauThu[2,CauThuHT].DiChuyen(#77);
end
else
if (CauThu[2,CauThuHT].Vitri.X > QBong.Vitri.X+1) then
begin
CauThu[2,CauThuHT].DiChuyen(#75);
end;
PT := True;
for j := 1 to SoCauthu do
if j <> i then
Begin
CauThu[2,j].DiChuyenNgauNhien;
CauThu[2,j].Dichuyen(Cauthu[2,j].KeyPress)
end;
end;
end;

(*==============E May Tinh===========================*)

Procedure NewGame;
Begin
clrscr;
SetCusor(32,0);
San.VeSanBong;
QBong.SetSoHuu(0, 0);
TextColor(White);
Qbong.vitri.SetVitri(ChieuRong div 2 + KhoangCachCot,
chieuCao div 2 + KhoangCachDong);
GotoXy(QBong.Vitri.X,QBong.Vitri.Y);
Write(#265);
CauthuHT := 2;
DangSut := False;
DangChuyen := False;
end;

Procedure PlayerPlay;
var i : integer;
Begin
Cauthu[1,CauThuHT].MauAo := Red;
if Keypressed then
begin
Cauthu[1,CauThuHT].KeyPress := readkey;
for i := 1 To SoCauThu do
if i <> CauThuHT then
Cauthu[1,i].DichuyenNgauNhien;
end;
Cauthu[1,CauThuHT].DiChuyen(Cauthu[1,CauThuHT].KeyPress);
for i := 1 To SoCauThu do
if i <> CauThuHT then
Cauthu[1,i].Dichuyen(Cauthu[1,i].KeyPress);
if Dangsut then QBong.SutBong(LastHuong)
else if DangChuyen then QBong.SutBong(HuongChuyen);
MayTinh.PhongThu;
MayTinh.TanCong;
QBong.XuLi;
Cauthu[1,1].SetCauThuHT;
end;

BEGIN
NewGame;
repeat
PlayerPlay;
if MayTinh.PT then
until Cauthu[1,CauThuHT].KeyPress = #27;
END.
a ơi, lỗi ở đây khắc phục thế nào à
upload_2017-8-12_14-45-45.png
 

Ray Kevin

Học sinh chăm học
Thành viên
2 Tháng năm 2017
462
348
81
Quảng Trị
...
làm sao để copy mà không cần phải gõ lại code này ?
 

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,619
744
21
Phú Yên
Trường THPT Lương Văn Chánh
  • Like
Reactions: Kulibadao

Kirigaya Kazuto.

Học sinh tiến bộ
Thành viên
11 Tháng tư 2017
514
1,192
219
Nghệ An
HM Forum
Bạn sửa đoạn đó lại như thế này:
if QBong.Sohuu[2,CauThuHT[(i)] then
Chữ i bạn đặt trong ngoặc vuông nhé. Do Mình đánh 2 dấu ngoặc vuông không được
Bạn chỉ cho mình đoạn lỗi trên hình được không, mình nhìn hoa cả mắt rồi mà không thấy :confused:
 
  • Like
Reactions: Tuansuper

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,619
744
21
Phú Yên
Trường THPT Lương Văn Chánh
Bạn chỉ cho mình đoạn lỗi trên hình được không, mình nhìn hoa cả mắt rồi mà không thấy :confused:
Procedure TMayTinh.TanCong;
var i,ct,j : integer;
begin
ct := 0;
KiemTra;
for i := 1 to 2 do
if QBong.Sohuu[2,CauThuHT] then
ct := i;
i := ct;
PT := True;
if i <> 0 then
begin
PT := False;
if (CauThu[2,CauThuHT].Vitri.Y < CauThu[1,1].GioiHan.Y2) then
begin
CauThu[2,CauThuHT].DiChuyen(#80);
end
else
if (CauThu[2,CauThuHT].Vitri.X < (CauThu[1,1].GioiHan.X2
+ CauThu[1,1].GioiHan.X1) div 2) then
begin
CauThu[2,CauThuHT].DiChuyen(#77);
end
else
if (CauThu[2,CauThuHT].Vitri.X > (CauThu[1,1].GioiHan.X2
+ CauThu[1,1].GioiHan.X1) div 2) then
begin
CauThu[2,CauThuHT].DiChuyen(#75);
end;
for j := 1 to SoCauthu do
if j <> i then
Begin
CauThu[2,j].DiChuyenNgauNhien;
CauThu[2,j].Dichuyen(Cauthu[2,j].KeyPress)
end;
end;
end;


Mấy cái đoạn CauThuHT bạn chuyển sang CauThuHT(i) *i đặt trong ngoặc vuông* hết nhé!
Dù sao thì Game này cũng khó chơi lắm
 

damdamty

Học sinh tiến bộ
Thành viên
10 Tháng năm 2017
1,909
1,637
291
Nghệ An
Trường Tâm
Procedure TMayTinh.TanCong;
var i,ct,j : integer;
begin
ct := 0;
KiemTra;
for i := 1 to 2 do
if QBong.Sohuu[2,CauThuHT] then
ct := i;
i := ct;
PT := True;
if i <> 0 then
begin
PT := False;
if (CauThu[2,CauThuHT].Vitri.Y < CauThu[1,1].GioiHan.Y2) then
begin
CauThu[2,CauThuHT].DiChuyen(#80);
end
else
if (CauThu[2,CauThuHT].Vitri.X < (CauThu[1,1].GioiHan.X2
+ CauThu[1,1].GioiHan.X1) div 2) then
begin
CauThu[2,CauThuHT].DiChuyen(#77);
end
else
if (CauThu[2,CauThuHT].Vitri.X > (CauThu[1,1].GioiHan.X2
+ CauThu[1,1].GioiHan.X1) div 2) then
begin
CauThu[2,CauThuHT].DiChuyen(#75);
end;
for j := 1 to SoCauthu do
if j <> i then
Begin
CauThu[2,j].DiChuyenNgauNhien;
CauThu[2,j].Dichuyen(Cauthu[2,j].KeyPress)
end;
end;
end;


Mấy cái đoạn CauThuHT bạn chuyển sang CauThuHT(i) *i đặt trong ngoặc vuông* hết nhé!
Dù sao thì Game này cũng khó chơi lắm
Vậy ạ, nhưng cách thức chơi thì chơi kiểu gì ạ
 

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,619
744
21
Phú Yên
Trường THPT Lương Văn Chánh
Vậy ạ, nhưng cách thức chơi thì chơi kiểu gì ạ
Di chuyển Quả bóng về phía khung thành đối thủ là được nha bạn.
Nhưng tùy máy thì tốc độ của nó sẽ khác nhau. Máy mình nó chậm cực kì, chơi không được gì cả.
 

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,619
744
21
Phú Yên
Trường THPT Lương Văn Chánh
có tới 25 lỗi lận nè
nhân tiện mik chỉ cách copy vào nhé:
mn bôi đen mã => vào phần mềm lập trình => ấn Edit => Paste from Windows
thế là ok nhé
cái này lâu rồi, mình chưa test lại nên cũng không biết nó lỗi gì :)
 
  • Like
Reactions: Linh Junpeikuraki
Top Bottom