private List <LobbyTable> IdentifyLobbyTables(LobbyIdentifier lobbyIdentifier, LobbyLayout layout, Iterator <Image> screen, Point offset) { for (int tries = 0; tries < 10; tries++) { // time DateTime startLobby = DateTime.Now; // select last row mouse.MoveAndLeftClick(offset.X + layout.LastRow.X, offset.Y + layout.LastRow.Y, 20, 5); // move mouse mouse.Move(offset.X + layout.Mouse.X, offset.Y + layout.Mouse.Y); Thread.Sleep(100); // shot Image screenshot = screen.next(); // crop Image window = screenshot.crop(offset.X, screenshot.width, offset.Y, screenshot.height); Image tableList = window.crop(layout.TableList.X, layout.TableList.X + layout.TableList.Width, layout.TableList.Y, layout.TableList.Y + layout.TableList.Height); try { List <LobbyTable> lobbyTables = lobbyIdentifier.identifyLobbyTables(tableList, offset); // log Log.Info("identified " + lobbyTables.Count + " joinable lobby tables"); // nothing found? if (lobbyTables.Count == 0) { throw new Exception("identified 0 lobby tables, trying again"); } return(lobbyTables); } catch (Exception ex) { // handle error ErrorHandler.ReportExceptionWithImage(ex, "lobby identifier error", tableList); // sleep Thread.Sleep(1000); // focus lobby FocusLobby(layout, screen); continue; } } throw new Exception("cannot identify lobby table list"); }
public static void Main(string[] args) { Thread.Sleep(10 * 1000); LobbyIdentifier identifier = new LobbyIdentifier(); DeviceControl device = new Win32Control(); Image screenshot = new ScreenImageIterator(device).next(); Point offset = PatternLocator.locateLobby(screenshot); LobbyLayout layout = new LobbyLayout(); Image window = screenshot.crop(offset.X, screenshot.width, offset.Y, screenshot.height); Image tableList = window.crop(layout.TableList.X, layout.TableList.X + layout.TableList.Width, layout.TableList.Y, layout.TableList.Y + layout.TableList.Height); List <LobbyTable> lobbyTables = identifier.identifyLobbyTables(tableList, offset); foreach (LobbyTable lobby in lobbyTables) { Console.WriteLine(lobby.ToString()); } }