SCAR Code:
program New;
const
ScrollIntoView = True;
var
Client: TBox;
Target: Integer;
TargetSize: TPoint;
procedure appa_UpdateBitmap;
var
p: TPoint;
begin
if (not appa_Showing) then
Exit;
p := appa_GetSize; //Get the size of the browser
if (p.x <> TargetSize.x) or (p.y <> TargetSize.y) then //If it has changed -> New bitmap
begin
try FreeBitmap(Target); except end;
Target := BitmapFromString(p.x, p.y, '');
TargetSize := p;
SetTargetBitmap(Target);
end;
appa_CopyContentToBitmap(Target); //Update the bitmap
//DisplayDebugImgWindow(p.x, p.y);
//SafeDrawBitmap(Target, GetDebugCanvas, 0, 0);
end;
function appa_NavigateTo(URL: string; TimeOut: Integer): Boolean;
var
t: Integer;
begin
Result := False;
if (not appa_Showing) then
Exit;
if (URL <> '') then
appa_Navigate(URL);
t := GetSystemTime + TimeOut;
while (not appa_PageLoaded) and appa_Showing and (GetSystemTime < t) do
Wait(250);
Result := appa_PageState >= 3;
end;
procedure GetClientBox; //Because you can only get the bitmap of the whole page, you need to know where the client is
var
e: TAppaElementArray;
i: Integer;
begin
if (not appa_Showing) then
Exit;
e := appa_GetElements; //Get all elements
for i := 0 to High(e) do
if (e[i].Tag = 'OBJECT') then //Search for the applet
begin
Client := e[i].Box;
if ScrollIntoView then
begin
appa_ScrollTo(0, Client.y1);
Client.y2 := Client.y2 - Client.y1;
Client.y1 := 0;
end;
Break;
end;
end;
procedure ScriptTerminate;
begin
try FreeBitmap(Target); except end;
end;
procedure ClickSquare(x, y: Integer);
begin
//No offset here, because it is sent directly to the applet
x := 285 + (100 * x);
y := 67 + (100 * y);
appa_MoveMouse(x, y);
appa_HoldMouse(x, y, True);
Wait(40);
appa_ReleaseMouse(x, y, True);
end;
procedure HandleScreen;
begin
GetClientBox;
appa_UpdateBitmap; //Update the target bitmap
while (GetColor(Client.x1 + 160, Client.y1 + 285) = clWhite) do //Relative coordinates
begin
Wait(500);
appa_UpdateBitmap; //Update the target bitmap
end;
if (GetColor(Client.x1 + 190, Client.y1 + 223) = 1776513) then //All colorchecking is relative
begin
appa_MoveMouse(180, 225); //Not relative here -- Directly sent to applet
appa_HoldMouse(180, 225, True);
Wait(40);
appa_ReleaseMouse(180, 225, True);
Wait(2000);
appa_MoveMouse(300, 355);
appa_HoldMouse(300, 355, True);
Wait(40);
appa_ReleaseMouse(300, 355, True);
Wait(2000);
appa_UpdateBitmap;
end;
if (CountColor(39423, Client.x1 + 475, Client.y1 + 358, Client.x1 + 510, Client.y1 + 380) > 0) then
begin
appa_MoveMouse(490, 375);
appa_HoldMouse(490, 375, True);
Wait(40);
appa_ReleaseMouse(490, 375, True);
Wait(2000);
appa_UpdateBitmap;
end;
while (GetColor(Client.x1 + 246, Client.y1 + 368) = 13421568) do
begin
Wait(100);
appa_UpdateBitmap;
end;
end;
procedure NextMove;
var
PlayField: array[0..2] of array[0..2] of Integer;
x, y, c: Integer;
begin
GetClientBox;
appa_UpdateBitmap; //Update the target bitmap
c := 0;
for x := 0 to 2 do
for y := 0 to 2 do
begin
PlayField[x][y] := CountColor(10092543, 240 + (100 * x) + Client.x1, 30 + (100 * y) + Client.y1, 320 + (100 * x) + Client.x1, 110 + (100 * y) + Client.y1);
//FindColors/CountColors always with offset (Client.x1)
case PlayField[x][y] of
4144: PlayField[x][y] := 2; //Computer
4160: PlayField[x][y] := 5; //You
else PlayField[x][y] := 0; //Empty
end;
if (PlayField[x][y] = 0) then
c := 1;
end;
if (c <> 1) then
Exit;
for y := 0 to 2 do
begin
c := 0;
for x := 0 to 2 do
c := c + PlayField[x][y];
if (c = 4) or (c = 10) then
for x := 0 to 2 do
if (PlayField[x][y] = 0) then
begin
ClickSquare(x, y);
Exit;
end;
end;
for x := 0 to 2 do
begin
c := 0;
for y := 0 to 2 do
c := c + PlayField[x][y];
if (c = 4) or (c = 10) then
for y := 0 to 2 do
if (PlayField[x][y] = 0) then
begin
ClickSquare(x, y);
Exit;
end;
end;
c := PlayField[0][0] + PlayField[1][1] + PlayField[2][2];
if (c = 4) or (c = 10) then
begin
if (PlayField[0][0] = 0) then
ClickSquare(0, 0)
else if (PlayField[1][1] = 0) then
ClickSquare(1, 1)
else if (PlayField[2][2] = 0) then
ClickSquare(2, 2);
Exit;
end;
c := PlayField[0][2] + PlayField[1][1] + PlayField[2][0];
if (c = 4) or (c = 10) then
begin
if (PlayField[0][2] = 0) then
ClickSquare(0, 2)
else if (PlayField[1][1] = 0) then
ClickSquare(1, 1)
else if (PlayField[2][0] = 0) then
ClickSquare(2, 0);
Exit;
end;
while True do
begin
x := Random(3);
y := Random(3);
if (PlayField[x][y] = 0) then
Break;
end;
ClickSquare(x, y);
end;
begin
appa_ShowForm;
appa_NavigateTo('', 10000);
appa_NavigateTo('http://www.novelgames.com/flashgames/game.php?id=30', 10000);
appa_SetTargetName('MacromediaFlashPlayerActiveX'); //Set target to first flash applet
repeat
HandleScreen;
NextMove;
Wait(50);
until IsFKeyDown(3) or (not appa_Showing);
end.