【问题标题】:Advanced screen scraping?高级屏幕抓取?
【发布时间】:2013-06-07 00:41:58
【问题描述】:

我在 yahoo、pogo 等游戏中看到了一些游戏机器人网站。您使用什么/如何编写检测屏幕上项目的软件?例如,在 java 中,您如何检测动态游戏窗口并识别出正在播放的方块(例如在俄罗斯方块中)。您如何从屏幕上的项目飞跃到让软件识别它? ?

【问题讨论】:

    标签: java image screen screen-scraping processing


    【解决方案1】:

    首先,在 Java/Processing 中,您通常会在网站中嵌入 Applet。 Java Frame 类为您提供屏幕 XY 起点(左上角,即 0,0)和屏幕边界(右下角,即“宽度”和“高度”)。这类似于 Python、JavaScript 和任何其他软件——网络或其他软件——使用“画布”即工作。一个屏幕。

    其次,您在屏幕上绘制的任何内容都是您自己创作的 - 因此您可以通过编程方式访问您绘制的任何内容的 XY 坐标。这可以由全局变量控制,或者更好的是,一个类的对象具有返回坐标的方法。

    例子:

    Ball ball;
    
    void setup() {
      size(640, 480);
      smooth();
    
      ball = new Ball(width/2, height/2, 60);
    }
    
    void draw() {
      background(0, 255, 0);
      ball.move();
      ball.boundsDetect();
      ball.draw();
    
      println("The X Position is " + getX() + " and the Y Position is " + getY());
    }
    
    class Ball {
    
      float x, y;
      float xSpeed = 2.8;
      float ySpeed = 2.2;
      int bSize, bRadius;
      int xDirection = 1;
      int yDirection = 1;
    
      Ball(int _x, int _y, int _size) {
        x = _x;
        y = _y;
        bSize = _size;
        bRadius = bSize/2;
      } 
    
      void move() {
        x = x + (xSpeed * xDirection);
        y = x + (ySpeed * yDirection);
      }
    
      void draw() {
        fill(255, 0, 0);
        stroke(255);
        ellipse(x, y, bSize, bSize); 
        println("here");
      }
    
      void boundsDetect() {
        if (x > width - bRadius || x < bRadius) {
          xDirection *= -1;
        }
        if (y > height - bRadius || y < bRadius) {
          yDirection *= -1;
        }
    
      }
    
      float getX() {
        return x;
      }
    
      float getY() {
        return y;
      }
    
    }
    

    【讨论】:

    • @Shawn 这回答了你的问题吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-20
    • 1970-01-01
    • 1970-01-01
    • 2019-01-17
    • 2011-06-03
    • 2014-07-29
    相关资源
    最近更新 更多