【发布时间】:2017-05-25 13:54:09
【问题描述】:
我和我的朋友制作了一个机器人来玩游戏,但是当我们尝试运行它时,它显示无效语法。我们对 Python 了解不多,我想请教更有经验的人。 这是脚本:
#include <iostream>
#include <windows.h>
#include <stdio.h>
#include <sys/time.h>
using namespace std;
int main() {
POINT p;
POINT coords[4];
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
printf("Move cursor to following tiles and press enter to select the coordinates:\n\n");
for(int i = 0; i < 4; i++) {
printf("%i. tile:", (i+1));
getchar();
GetCursorPos(&p);
coords[i] = p;
printf("- X: %d, Y: %d\n\n", p.x, p.y);
}
COLORREF currColor;
HDC dc = GetDC(NULL);
while(true) {
if(GetAsyncKeyState(VK_ESCAPE)) {
printf("\rPaused, press ENTER to continue ...");
getchar();
printf("Continue ...\n\n");
}
bool countFound = 0;
for(int i = 0; i < 4; i++) {
COLORREF color = GetPixel(dc, coords[i].x, coords[i].y);
if(color <= 3000000) {
printf("\r");
for(int j = 0; j < i; j++) {
printf("[ ] ");
}
printf("[X] ");
for(int j = 0; j < (3-i); j++) {
printf("[ ] ");
}
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
SetCursorPos(coords[i].x, coords[i].y);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
if(color > 100000) {
Sleep(50);
} else {
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}
}
}
}
ReleaseDC(NULL, dc);
return 0;
}
提前谢谢你!
【问题讨论】:
-
那是 C++,不是 Python。难怪你会遇到语法错误......
-
那不是 Python 脚本,它是 C++。难怪它在 Python 下不起作用。
-
"Me and my friends made a bot"不,你没有。您从互联网上下载了一些随机代码,甚至不了解 它是用什么语言编写的 并盲目地尝试运行它。这就是您传播病毒和破坏计算机的方式。请从这个小插曲中学习 - 并非所有在线代码都是它所说的那样。 -
另外,补充一点@MattDMo 已经说过的内容,这甚至不像机器人的代码看起来。这看起来像与图形相关的代码。你们真的应该更加小心。
标签: python