📄 四国军旗控件(源码) (2001年4月23日).txt
字号:
//FGameBoard := StartPlaying;
//FGameBoard := CheckPlay;
if assigned(FPieceBitmaps) then
PainPieceBitmap;
end;
end;
end;
function TSiGuo.CheckIfHavePiece(starpos, endpos: TPoint): boolean;
var
i,i0,j0:byte;
begin
result:=false;
if starpos.x=endpos.x then //没有转弯 //纵向移动
begin
if abs(starpos.y-endpos.y)>1 then
begin
if starpos.y begin
i0:=starpos.y+1;
j0:=endpos.y-1;
end else
begin
j0:=starpos.y-1;
i0:=endpos.y+1;
end;
for I:=i0 to j0 do
begin
if FGameBoard[starpos.x,I].PieceType<>15 then ///有旗子
begin
result:=false;
exit;
end else
begin ///没棋子但是否受控
if ( ((starpos.x=9) and (i=7)) or ((starpos.x=7) and (i=9)) ) then
begin
result:=false;
exit;
end;
end;
end;
result:=true;
exit;
end else
begin
result:=true;
exit;
end;
end;
if starpos.y=endpos.y then //没有转弯 横向移动
begin
if abs(starpos.x-endpos.x)>1 then
begin
if starpos.x begin
i0:=starpos.x+1;
j0:=endpos.x-1;
end else
begin
j0:=starpos.x-1;
i0:=endpos.x+1;
end;
for I:=i0 to j0 do
begin
if FGameBoard[I,endpos.y].PieceType<>15 then ///有旗子
begin
result:=false;
exit;
end else
begin ///没棋子但是否受控
if ( ((endpos.y=7) and (i=9)) or ((endpos.y=9) and (i=7)) ) then
begin
result:=false;
exit;
end;
end;
end;
result:=true;
exit;
end else
begin
result:=true;
exit;
end;
end;
end;
function TSiGuo.IfDiXian(starpos,endpos:TPoint): boolean;
begin
if ( (starpos.x=0) or (starpos.y=16) or (starpos.x=16) or (starpos.y=0) //底线点
or (endpos.x=0) or (endpos.y=16) or (endpos.x=16) or (endpos.y=0) )then
result:=true else
result:=false;
end;
function TSiGuo.IfJunying(starpos, endpos: TPoint): boolean;
begin
if ( ((starpos.x=7) and (starpos.y=12)) or ((starpos.x=9) and (starpos.y=12)) //军营
or ((starpos.x=7) and (starpos.y=14)) or ((starpos.x=9) and (starpos.y=14))
or ((starpos.x=8) and (starpos.y=13)) or ((starpos.x=2) and (starpos.y=7))
or ((starpos.x=2) and (starpos.y=9)) or ((starpos.x=4) and (starpos.y=7))
or ((starpos.x=4) and (starpos.y=9)) or ((starpos.x=3) and (starpos.y=8))
or ((starpos.x=7) and (starpos.y=2)) or ((starpos.x=9) and (starpos.y=2))
or ((starpos.x=7) and (starpos.y=4)) or ((starpos.x=9) and (starpos.y=4))
or ((starpos.x=8) and (starpos.y=3)) or ((starpos.x=13) and (starpos.y=8))
or ((starpos.x=12) and (starpos.y=7)) or ((starpos.x=12) and (starpos.y=9))
or ((starpos.x=14) and (starpos.y=7)) or ((starpos.x=14) and (starpos.y=9))
or ((endpos.x=7) and (endpos.y=12)) or ((endpos.x=9) and (endpos.y=12))
or ((endpos.x=7) and (endpos.y=14)) or ((endpos.x=9) and (endpos.y=14))
or ((endpos.x=8) and (endpos.y=13)) or ((endpos.x=2) and (endpos.y=7))
or ((endpos.x=2) and (endpos.y=9)) or ((endpos.x=4) and (endpos.y=7))
or ((endpos.x=4) and (endpos.y=9)) or ((endpos.x=3) and (endpos.y=8))
or ((endpos.x=7) and (endpos.y=2)) or ((endpos.x=9) and (endpos.y=2))
or ((endpos.x=7) and (endpos.y=4)) or ((endpos.x=9) and (endpos.y=4))
or ((endpos.x=8) and (endpos.y=3)) or ((endpos.x=13) and (endpos.y=8))
or ((endpos.x=12) and (endpos.y=7)) or ((endpos.x=12) and (endpos.y=9))
or ((endpos.x=14) and (endpos.y=7)) or ((endpos.x=14) and (endpos.y=9)) ) then
result:=true else
result:=false;
end;
function TSiGuo.IfYewo(starpos, endpos: TPoint): boolean;
begin
if( ((starpos.x=8) and (starpos.y=12)) or ((starpos.x=8) and (starpos.y=14)) //掖窝点
or ((starpos.x=7) and (starpos.y=13)) or ((starpos.x=9) and (starpos.y=13))
or ((starpos.x=2) and (starpos.y=8)) or ((starpos.x=4) and (starpos.y=8))
or ((starpos.x=3) and (starpos.y=7)) or ((starpos.x=3) and (starpos.y=9))
or ((starpos.x=7) and (starpos.y=3)) or ((starpos.x=9) and (starpos.y=3))
or ((starpos.x=8) and (starpos.y=2)) or ((starpos.x=8) and (starpos.y=4))
or ((starpos.x=12) and (starpos.y=8)) or ((starpos.x=14) and (starpos.y=8))
or ((starpos.x=13) and (starpos.y=7)) or ((starpos.x=13) and (starpos.y=9))
or ((endpos.x=8) and (endpos.y=12)) or ((endpos.x=8) and (endpos.y=14))
or ((endpos.x=7) and (endpos.y=13)) or ((endpos.x=9) and (endpos.y=13))
or ((endpos.x=2) and (endpos.y=8)) or ((endpos.x=4) and (endpos.y=8))
or ((endpos.x=3) and (endpos.y=7)) or ((endpos.x=3) and (endpos.y=9))
or ((endpos.x=7) and (endpos.y=3)) or ((endpos.x=9) and (endpos.y=3))
or ((endpos.x=8) and (endpos.y=2)) or ((endpos.x=8) and (endpos.y=4))
or ((endpos.x=12) and (endpos.y=8)) or ((endpos.x=14) and (endpos.y=8))
or ((endpos.x=13) and (endpos.y=7)) or ((endpos.x=13) and (endpos.y=9)) ) then
result:=true else
result:=false;
end;
procedure TSiGuo.UndoMove;
var
temppt:TPoint;
begin
FGameBoard[TempPieceX,TempPieceY]:=TempPiece;
TEMPPT.x:=TempPieceX;
TEMPPT.y:=TempPieceY;
DrawPiece(Canvas,temppt,TempPiece);
end;
function TSiGuo.IfWin(MovePiece, EndposPiece: TPieceInfo): TWarResult;
var
temp:byte;
begin
if EndposPiece.PieceType=11 then //军旗被扛,输掉
begin
result:=wrNone;
temp:=EndposPiece.Color;
Becaptured(temp);
exit;
end;
if (MovePiece.PieceType=9) or (EndposPiece.PieceType=9) then //如果双方其一是炸弹
begin
result:=wrSame;
exit;
end;
if EndposPiece.PieceType=10 then //如果被打棋子是地雷
begin
if MovePiece.PieceType<>8 then //如果不是工兵
begin
if ZhadDilei then
result:=wrSame else
result:=wrDefeated;
exit;
end else //是工兵
begin
result:=wrWin;
exit;
end;
end;
if MovePiece.PieceType result:=wrWin;
if MovePiece.PieceType>EndposPiece.PieceType then
result:=wrDefeated;
if MovePiece.PieceType=EndposPiece.PieceType then
result:=wrSame;
end;
procedure TSiGuo.Becaptured(color: byte);
var
i,j:byte;
temp:TPoint;
begin
//清除全部旗子
for i:=0 to 16 do
for j:=0 to 16 do
begin
if FGameBoard[i,j].PieceType<>15 then
if FGameBoard[i,j].Color=color then
begin
FGameBoard[i,j].PieceType:=15;
temp.x :=i; temp.y:=j;
ClearBoardPos(temp);
end;
end;
if Assigned(FOnBecaptured) then FOnBecaptured(color);
end;
function TSiGuo.GBValidLine(starpos, endpos: TPoint): boolean;
var
TempArray:array[0..16,0..16] of boolean;
pcFourPoint,pcOldArrayDb:array[0..18] of TPoint;
i,j,i0,j0,pcNumber:byte;
temppt,tmp1:TPoint;
label dothisGb1;
label dothisGb2;
label dothisGb3;
label dothisGb4;
begin
result:=false;
for i:=0 to 16 do
for j:=0 to 16 do
begin
temppt.x:=i; temppt.y:=j;
if (not CheckValidPoint(i,j)) or IfYewo(temppt,temppt)
or IfDixian(temppt,temppt) or IfJunying(temppt,temppt) or (FGameBoard[i,j].PieceType<>15) then
TempArray[i,j]:=false else
TempArray[i,j]:=true;
if IfYinhan(temppt) or ((i=endpos.x) and (j=endpos.y)) then
TempArray[i,j]:=true;
if (i=starpos.x) and (j=starpos.y) then
TempArray[i,j]:=false;
end;
j:=1 ;
pcOldArrayDb[0]:=starpos;
pcFourPoint[0]:= starpos;
repeat
pcNumber:=0;
for i:=0 to j-1 do
begin
i0:=pcOldArrayDb[i].x; j0:=pcOldArrayDb[i].y;
temppt.x:=i0; temppt.y:=j0;
if (endpos.x=i0) and (endpos.y=j0) then
begin
result:=true;
exit;
end;
if TempArray[i0+1,j0] then
begin
tmp1.x:=i0+1; tmp1.y:=j0;
if IfYinhan(temppt) then //隐含点不能到两臂
if IfLiangbi(tmp1) then
goto dothisgb1;
if IfLiangbi(temppt) then //两臂点不能到隐含点
if IfYinhan(tmp1) then
goto dothisgb1;
inc(pcNumber);
TempArray[i0+1,j0]:=false;
pcFourPoint[pcNumber-1]:= tmp1;
end;
dothisGb1:
if TempArray[i0-1,j0] then
begin
tmp1.x:=i0-1; tmp1.y:=j0;
if IfYinhan(temppt) then //隐含点不能到两臂
if IfLiangbi(tmp1) then
goto dothisgb2;
if IfLiangbi(temppt) then //两臂点不能到隐含点
if IfYinhan(tmp1) then
goto dothisgb2;
inc(pcNumber);
TempArray[i0-1,j0]:=false;
pcFourPoint[pcNumber-1]:= tmp1;
end;
dothisGb2:
if TempArray[i0,j0+1] then
begin
tmp1.x:=i0; tmp1.y:=j0+1;
if IfYinhan(temppt) then //隐含点不能到两臂
if IfLiangbi(tmp1) then
goto dothisgb3;
if IfLiangbi(temppt) then //两臂点不能到隐含点
if IfYinhan(tmp1) then
goto dothisgb3;
inc(pcNumber);
TempArray[i0,j0+1]:=false;
pcFourPoint[pcNumber-1]:= tmp1;
end;
dothisGb3:
if TempArray[i0,j0-1] then
begin
tmp1.x:=i0; tmp1.y:=j0-1;
if IfYinhan(temppt) then //隐含点不能到两臂
if IfLiangbi(tmp1) then
goto dothisgb4;
if IfLiangbi(temppt) then //两臂点不能到隐含点
if IfYinhan(tmp1) then
goto dothisgb4;
inc(pcNumber);
TempArray[i0,j0-1]:=false;
pcFourPoint[pcNumber-1]:= tmp1;
end;
dothisGb4:
if ((temppt.x=6) and (temppt.y=11))then //8顶点可以拐弯 下左
begin
if TempArray[5,10] then
begin
inc(pcNumber);
TempArray[5,10]:=false;
tmp1.x:=5; tmp1.y:=10;
pcFourPoint[pcNumber-1]:=tmp1;
end;
end;
if ((temppt.x=10) and (temppt.y=11))then //8顶点可以拐弯 下右
begin
if TempArray[11,10] then
begin
inc(pcNumber);
TempArray[11,10]:=false;
tmp1.x:=11; tmp1.y:=10;
pcFourPoint[pcNumber-1]:=tmp1;
end;
end;
if ((temppt.x=11) and (temppt.y=10))then //8顶点可以拐弯 右 下
begin
if TempArray[10,11] then
begin
inc(pcNumber);
TempArray[10,11]:=false;
tmp1.x:=10; tmp1.y:=11;
pcFourPoint[pcNumber-1]:=tmp1;
end;
end;
if ((temppt.x=11) and (temppt.y=6))then //8顶点可以拐弯 右 上
begin
if TempArray[10,5] then
begin
inc(pcNumber);
TempArray[10,5]:=false;
tmp1.x:=10; tmp1.y:=5;
pcFourPoint[pcNumber-1]:=tmp1;
end;
end;
if ((temppt.x=6) and (temppt.y=5))then //8顶点可以拐弯 上 左
begin
if TempArray[5,6] then
begin
inc(pcNumber);
TempArray[5,6]:=false;
tmp1.x:=5; tmp1.y:=6;
pcFourPoint[pcNumber-1]:=tmp1;
end;
end;
if ((temppt.x=10) and (temppt.y=5))then //8顶点可以拐弯 上 右
begin
if TempArray[11,6] then
begin
inc(pcNumber);
TempArray[11,6]:=false;
tmp1.x:=11; tmp1.y:=6;
pcFourPoint[pcNumber-1]:=tmp1;
end;
end;
if ((temppt.x=5) and (temppt.y=10))then //8顶点可以拐弯 左 下
begin
if TempArray[6,11] then
begin
inc(pcNumber);
TempArray[6,11]:=false;
tmp1.x:=6; tmp1.y:=11;
pcFourPoint[pcNumber-1]:=tmp1;
end;
end;
if ((temppt.x=5) and (temppt.y=6))then //8顶点可以拐弯 左 上
begin
if TempArray[6,5] then
begin
inc(pcNumber);
TempArray[6,5]:=false;
tmp1.x:=6; tmp1.y:=5;
pcFourPoint[pcNumber-1]:=tmp1;
end;
end;
end; //for i:0 to j-1 do
if pcNumber>0 then
begin
j:=pcNumber;
for i:=0 to j-1 do
pcOldArrayDb[i]:= pcFourPoint[i];
end;
until
pcNumber=0;
end;
function TSiGuo.IfLiangbi(pcTmp: TPoint): boolean;
begin
if ((pcTmp.x=7) and (pcTmp.y=11)) or ((pcTmp.x=9) and (pcTmp.y=11))
or ((pcTmp.x=5) and (pcTmp.y=7)) or ((pcTmp.x=5) and (pcTmp.y=9))
or ((pcTmp.x=7) and (pcTmp.y=5)) or ((pcTmp.x=9) and (pcTmp.y=5))
or ((pcTmp.x=11) and (pcTmp.y=7)) or ((pcTmp.x=11) and (pcTmp.y=9)) then
result:=true else
result:=false;
end;
function TSiGuo.IfYinhan(pcTmp: TPoint): boolean;
begin
if ((pcTmp.x=6) and (pcTmp.y=7)) or ((pcTmp.x=6) and (pcTmp.y=9))
or ((pcTmp.x=8) and (pcTmp.y=7)) or ((pcTmp.x=8) and (pcTmp.y=9))
or ((pcTmp.x=10) and (pcTmp.y=7))or ((pcTmp.x=10) and (pcTmp.y=9))
or ((pcTmp.x=7) and (pcTmp.y=6)) or ((pcTmp.x=9) and (pcTmp.y=6))
or ((pcTmp.x=7) and (pcTmp.y=8)) or ((pcTmp.x=9) and (pcTmp.y=8))
or ((pcTmp.x=7) and (pcTmp.y=10)) or ((pcTmp.x=9) and (pcTmp.y=10)) then
result:=true else
result:=false;
end;
function TSiGuo.IfSiding(pcTmp: TPoint): boolean;
begin
if ((pcTmp.x=6) and (pcTmp.y=6)) or ((pcTmp.x=6) and (pcTmp.y=10))
or ((pcTmp.x=10) and (pcTmp.y=6)) or ((pcTmp.x=10) and (pcTmp.y=10)) then
result:=true else
result:=false;
end;
function TSiGuo.GetSingleMapData: string;
var
tempstr:string;
i,j:byte;
tempps:TPieceInfo;
begin //main 1:player array leixing:2
tempstr:='';
tempstr:=inttostr(FPlayerColor);
for i:=6 to 10 do
for j:=11 to 16 do
begin
tempps:=FGameBoard[i,j];
if tempps.PieceType<>15 then
begin
if tempps.PieceType<=9 then
tempstr:=tempstr+'0'+inttostr(tempps.PieceType) else
tempstr:=tempstr+inttostr(tempps.PieceType) ;
end else
tempstr:=tempstr+'FF';
end;
result:=tempstr;
end;
procedure TSiGuo.SetPlayerColor(Value: byte);
var
j,i,tmp:byte;
begin
if (Value>=0) and (Value<=3) then
begin
if Value<>FPlayerColor then
FPlayerColor:=value;
tmp:=12*Value;
if Value<>0 then
begin
for i:=6 to 10 do
for j:=11 to 16 do
begin
FGameBoard[i,j].ImageIndex:=FGameBoard[i,j].ImageIndex+tmp;
FGameBoard[i,j].Color:=Value;
end;
end;
end ;
end;
procedure TSiGuo.SGInishie;
var
i,j:integer;
begin
for i:=0 to 16 do
for j:=0 to 16 do
begin
FGameBoard[i,j].Color:=0;
FGameBoard[i,j].PieceType:=15;
FGameBoard[i,j].ImageIndex:=6;
end;
FGameBoard[6,11].PieceType:=0; //x=6
FGameBoard[6,11].ImageIndex:=0;
FGameBoard[6,12].PieceType:=7;
FGameBoard[6,12].ImageIndex:=7;
FGameBoard[6,13].PieceType:=2;
FGameBoard[6,13].ImageIndex:=2;
FGameBoard[6,14].PieceType:=4;
FGameBoard[6,14].ImageIndex:=4;
FGameBoard[6,15].PieceType:=3;
FGameBoard[6,15].ImageIndex:=3;
FGameBoard[6,16].PieceType:=10;
FGameBoard[6,16].ImageIndex:=10;
FGameBoard[7,11].PieceType:=8; //x=7
FGameBoard[7,11].ImageIndex:=8;
FGameBoard[7,13].PieceType:=9;
FGameBoard[7,13].ImageIndex:=9;
FGameBoard[7,15].PieceType:=10;
FGameBoard[7,15].ImageIndex:=10;
FGameBoard[7,16].PieceType:=11;
FGameBoard[7,16].ImageIndex:=11;
FGameBoard[8,11].PieceType:=4; //x=8
FGameBoard[8,11].ImageIndex:=4;
FGameBoard[8,12].PieceType:=6;
FGameBoard[8,12].ImageIndex:=6;
FGameBoard[8,14].PieceType:=5;
FGameBoard[8,14].ImageIndex:=5;
FGameBoard[8,15].PieceType:=7;
FGameBoard[8,15].ImageIndex:=7;
FGameBoard[8,16].PieceType:=10;
FGameBoard[8,16].ImageIndex:=10;
FGameBoard[9,11].PieceType:=8; //x=9
FGameBoard[9,11].ImageIndex:=8;
FGameBoard[9,13].PieceType:=9;
FGameBoard[9,13].ImageIndex:=9;
FGameBoard[9,15].PieceType:=8;
FGameBoard[9,15].ImageIndex:=8;
FGameBoard[9,16].PieceType:=7;
FGameBoard[9,16].ImageIndex:=7;
FGameBoard[10,11].PieceType:=5; //x=10
FGameBoard[10,11].ImageIndex:=5;
FGameBoard[10,12].PieceType:=6;
FGameBoard[10,12].ImageIndex:=6;
FGameBoard[10,13].PieceType:=2;
FGameBoard[10,13].ImageIndex:=2;
FGameBoard[10,14].PieceType:=1;
FGameBoard[10,14].ImageIndex:=1;
FGameBoard[10,15].PieceType:=3;
FGameBoard[10,15].ImageIndex:=3;
FGameBoard[10,16].PieceType:=6;
FGameBoard[10,15].ImageIndex:=6;
end;
end.
--------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -