(*=======================================================
游戏开始
=======================================================*)
procedure Game_Start;
var
H:HWND;
begin
h:=FindWindow(nil,'对对碰角色版');
if H <= 0 then
begin
// ShowMessage('窗口句柄为0!');
Exit;
end
else
begin
PostMessage(h,WM_LBUTTONDOWN,0,MakeLParam(382,385));
PostMessage(h,WM_LBUTTONUP,0,MakeLParam(382,385));
end;
end;
//--------------------
(*=======================================================
更新数组
=======================================================*)
procedure UpdateArray;
var
h:HWND;
theaId,Pid:THandle;
Buffer,tt:DWORD;
const
SitNumBase=$00489e40;
begin
h:=FindWindow(nil,'对对碰角色版');
if h <= 0 then Exit;//ShowMessage('窗口句柄为空');
GetWindowThreadProcessId(h,@theaId);
Pid:=OpenProcess(PROCESS_ALL_ACCESS,False,theaId);
if Pid = 0 then
begin
// ShowMessage('进程ID为空!');
Exit;
end
else
begin
ReadProcessMemory(Pid,Pointer(sitnumbase),@Buffer,4,tt); //读出几号座位
ReadProcessMemory(Pid,Pointer(SitBase[Buffer]),@Game_array,200,tt);
end;
end;
(*=======================================================
交换两点
=======================================================*)
procedure SwapPoint(twoX:TPoint;twoy:TPoint);
var
h:HWND;
// TwoXy:TwoTPoint;
begin
h:=FindWindow(nil,'对对碰角色版');
if h <= 0 then
begin
// ShowMessage('窗口句柄为空!');
exit;
end
else
begin
PostMessage(h,WM_LBUTTONDOWN,0,MakeLParam(twox.X*48+291,twoX.Y*48+116));
PostMessage(h,WM_LBUTTONUP,0,MakeLParam(twox.X*48+291,twoX.Y*48+116));
PostMessage(h,WM_LBUTTONDOWN,0,MakeLParam(twoy.X*48+291,twoy.Y*48+116));
PostMessage(h,WM_LBUTTONUP,0,MakeLParam(twoy.X*48+291,twoy.Y*48+116));
end;
end;
(*=======================================================
测试相联
=======================================================*)
function TestChess(var Temp_Array:Chess_array):BOOL;
var
x,y,tt:Byte;
s:string;
begin
x:=0;
y:=0;
s:='';
Result :=False;
while x <= 7 do
begin
tt:=1 ;
while y <= 6 do
begin
if Temp_array[x][y] = Temp_array[x][y+1] then
begin
tt:=tt+1;
if tt >= 3 then
begin
{ case Temp_Array[x][y] of
0:ShowMessage('TEMP_ARRAY为0!');
1:ShowMessage(inttostr(x + 1)+'列'+inttostr(y+1)+'行'+'与'+inttostr(y+2)+'行'+'交换 青蛙 1');
2:ShowMessage(inttostr(x+1)+'列'+inttostr(y+1)+'行'+'与'+inttostr(y+2)+'行'+'交换 小鸟 2');
3:ShowMessage(inttostr(x+1)+'列'+inttostr(y+1)+'行'+'与'+inttostr(y+2)+'行'+'交换 猫 3');
4:ShowMessage(inttostr(x+1)+'列'+inttostr(y+1)+'行'+'与'+inttostr(y+2)+'行'+'交换 熊猫 4');
5:ShowMessage(inttostr(x+1)+'列'+inttostr(y+1)+'行'+'与'+inttostr(y+2)+'行'+'交换 狐狸 5');
6:ShowMessage(inttostr(x+1)+'列'+inttostr(y+1)+'行'+'与'+inttostr(y+2)+'行'+'交换 牛 6');
7:ShowMessage(inttostr(x+1)+'列'+inttostr(y+1)+'行'+'与'+inttostr(y+2)+'行'+'交换 猴子 7');
end; }
Result:=True;
EXIT;
end;
end
else
begin
tt:=1;
end;
y:=y+1;
end;
x:=x + 1;
y:=0;
end;
X:=0;
Y:=0;
while y <= 7 do
begin
tt:=1 ;
while x <= 6 do
begin
if Temp_array[x][y]=temp_array[x+1][y] then
begin
tt:=tt+1;
if tt >= 3 then
begin
{ case Temp_Array[x][y] of
0:ShowMessage('TEMP_ARRAY为0!');
1:ShowMessage(inttostr(x)+'行'+inttostr(y)+'列'+'与'+inttostr(x+1)+'行'+'交换 青蛙');
2:ShowMessage(inttostr(x)+'行'+inttostr(y)+'列'+'与'+inttostr(x+1)+'行'+'交换 小鸟');
3:ShowMessage(inttostr(x)+'行'+inttostr(y)+'列'+'与'+inttostr(x+1)+'行'+'交换 猫');
4:ShowMessage(inttostr(x)+'行'+inttostr(y)+'列'+'与'+inttostr(x+1)+'行'+'交换 熊猫');
5:ShowMessage(inttostr(x)+'行'+inttostr(y)+'列'+'与'+inttostr(x+1)+'行'+'交换 狐狸');
6:ShowMessage(inttostr(x)+'行'+inttostr(y)+'列'+'与'+inttostr(x+1)+'行'+'交换 牛');
7:ShowMessage(inttostr(x)+'行'+inttostr(y)+'列'+'与'+inttostr(x+1)+'行'+'交换 猴子');
end; }
Result:=True;
Exit;
end;
end
else
begin
tt:=1;
end;
x:=x+1;
end;
y:=y + 1;
x:=0;
end;
end;
(*=======================================================
实现单消
=======================================================*)
procedure ClearOne;
var
Temp_array:Chess_array;
x,y,temp:Byte;
TwoXy:TwoTPoint;
begin
x:=0;
y:=0;
(*
交换两个点,遍历是否有三连,有,鼠标点鸡
*)
//第一步遍历数组
while x <= 7 do
begin
UpdateArray;
Temp_array:=Game_array;
while y <= 6 do
begin
temp:=temp_array[x][y];
Temp_array[x][y]:=temp_array[x][y+1];
Temp_array[x][y+1]:=temp;
// btn2Click(Sender);
if (TestChess(Temp_array)) then//判断是否有三连
begin
TwoXy[0].X:=x;
TwoXy[0].Y:=y;
TwoXy[1].X:=x;
TwoXy[1].Y:=y+1;
SwapPoint(twoxy[0],TWOXY[1]);
Exit;
end
else
begin //交换回来
temp:=temp_array[x][y+1];
Temp_array[x][y+1]:=temp_array[x][y];
Temp_array[x][y]:=temp;
end;
Y:=Y+1;
end;
X:=X+1;
Y:=0;
end;
x:=0;
y:=0;
while y <= 7 do
begin
UpdateArray;
Temp_array:=Game_array;
while x <= 6 do // X
begin
temp:=temp_array[x][y];
Temp_array[x][y]:=temp_array[x+1][y];
Temp_array[x+1][y]:=temp;
if TestChess(Temp_array) then//判断是否有三连
begin
TwoXy[0].X:=x;
TwoXy[0].Y:=y;
TwoXy[1].X:=x+1;
TwoXy[1].Y:=y;
SwapPoint(twoxy[0],TWOXY[1]);
Exit;
end
else
begin //交换回来
temp:=temp_array[x+1][y];
Temp_array[x+1][y]:=temp_array[x][y];
Temp_array[x][y]:=temp;
end;
X:=X+1;
end;
y:=Y+1;
X:=0;
end;
end;