当前位置: 移动技术网 > IT编程>开发语言>C/C++ > 王者荣耀刷金币小程序

王者荣耀刷金币小程序

2019年03月26日  | 移动技术网IT编程  | 我要评论

孙维世金山,中餐烹调技术,北京vps

前两天让同学帮我上个王者(没办法,自己技术不行),他需要英雄,而我没有金币,买不起(钱多重要!!!),就只好云刷金币,但是我这么懒,哪愿意手动刷呀……所以,就想办法呗。经过长时间的战斗(好像也没有多长),最终完成!

代码是用c写的:

  1 #include <stdio.h>
  2 #include <windows.h>
  3 #include <time.h>
  4 #include <stdlib.h>
  5 
  6 char *basestr = "adb shell input tap ";
  7 int info[8][3] = {
  8     {0, 0, 0},
  9     {0, 0, 0},
 10     {0, 0, 0},
 11     {0, 0, 0},
 12     {0, 0, 0},
 13     {0, 0, 0},
 14     {0, 0, 0},
 15     {0, 0, 0},
 16 };
 17 
 18 /**
 19  * 自定义乘方函数,求a的b次方
 20  * @param  int a
 21  * @param  int b
 22  * @return int r
 23  */
 24 int power(int a, int b)
 25 {
 26     int i, r = 1;
 27     for (i = 0; i < b; i++) r *= a;
 28     return r;
 29 }
 30 
 31 /**
 32  * 自定义执行函数
 33  * @param int dx    x 坐标
 34  * @param int dy    y 坐标
 35  */
 36 void func(int dx, int dy)
 37 {
 38     char dxstr[10];             // x 坐标字符串
 39     char dystr[10];             // y 坐标字符串
 40     char str[100];              // adb 命令字符串
 41     
 42     strcpy(str, basestr);
 43     // 数字转换为字符串
 44     itoa(dx, dxstr, 10);
 45     itoa(dy, dystr, 10);
 46     // 字符串拼接
 47     strcat(str, dxstr);
 48     strcat(str, " ");
 49     strcat(str, dystr);
 50     system(str);                // 调用 system
 51     system("cls");              // 使用模拟器会出现警告
 52 }
 53 
 54 /**
 55  * 写文件
 56  */
 57 void wfile(char *filename)
 58 {
 59     int flag = 1, flag2 = 1;                                // 标志
 60     file *fp;
 61     int startx, starty;                                     // 参考坐标
 62     int dx, dy;                                             // 相对坐标
 63     point pt = {0, 0};
 64     int startt = 0, t;                                      // 开始时间和时间间隔
 65     int i = 0;
 66     
 67     fp = fopen(filename, "w");
 68     while (getch() == ' ')                                  // 按下空格键,执行循环
 69     {
 70         getcursorpos(&pt);                                  // 获取当前位置坐标
 71         if (flag)                                           // 获取参考坐标
 72         {
 73             startx = (&pt)->x;
 74             starty = (&pt)->y;
 75             printf("参考坐标为:x=%d,y=%d", startx, starty);
 76             flag = 0;
 77         }
 78         else
 79         {
 80             t = flag2 ? 0 : (clock() - startt);             // 延时时间
 81             if(flag2) flag2 = 0;
 82             dx = (&pt)->x - startx;
 83             dy = (&pt)->y - starty;
 84             startt = clock();                               // 获取当前时间,作为下一次开始时间
 85             // 给数组赋值
 86             if (t == 0) info[i][0] = t;
 87             else info[i][0] = t - 500;
 88             info[i][1] = dx;
 89             info[i++][2] = dy;
 90             fprintf(fp, "%d,%d,%d\n", (t - 500), dx, dy);           // 将信息存储在 info.log 文件中
 91             func(dx, dy);                                   // 运行执行函数
 92         }
 93     }
 94     fclose(fp);                                             // 关闭文件
 95 }
 96 
 97 int main()
 98 {
 99     file *out;                                              // 要读取的文件
100     char temp[10];
101     char sc, nc, rc;
102     int i = 0, j, k;                                        // 循环变量
103     char ch;                                                // 文件读取后的存储值
104     int flag = 1;                                           // 标志
105     
106     // 更改窗口大小
107     system("mode con cols=40 lines=20");
108     
109     system("adb devices");
110     printf("如果设备不存在,不建议继续执行\n是否需要继续执行?y/n?");
111     scanf(" %c", &sc);
112     if (sc != 'y' && sc != 'y') exit(0);
113     
114     // 判断文件是否存在
115     if ((out = fopen("info.log", "r")) == null)
116     {
117         printf("当前文件夹下未检测到记录文件,是否需要新建?(文件录入方式请参照readme.txt)y/n?");
118         scanf(" %c", &nc);
119         if (nc == 'y' || nc == 'y')
120         {
121             wfile("info.log");                              // 写入文件 info.log
122             flag = 0;                                       // 将 flag 置0
123         }
124         else exit(0);
125     }
126     
127     // 判断是否需要从文件中读取
128     if (flag)
129     {
130         i = 0;
131         j = 0;
132         printf("已找到记录文件,是否重新录入?y/n?");
133         scanf(" %c", &rc);
134         if (rc == 'y' || rc == 'y') wfile("info.log");      // 重新写入文件
135         // 读取文件中的内容,给 info 数组赋值
136         while ((ch = fgetc(out)) != eof)
137         {
138             // 判断是否是 ',' 或者换行
139             if (ch != ',' && ch != '\n') temp[i++] = ch;
140             else
141             {
142                 i = 0;                                      // i置0
143                 info[j / 3][j % 3] = atoi(temp);            // 给数组赋值
144                 for (k = 0; k < 10; k++) temp[k] = '\n';    // 清空 temp
145                 j++;
146             }
147         }
148     }
149     fclose(out);                                            // 关闭文件
150     
151     // 执行操作
152     while (1)
153     {
154         for (i = 0; i < 8; i++)
155         {
156             sleep(info[i][0]);                              // 延时
157             func(info[i][1], info[i][2]);                   // 执行
158         }
159         sleep(3000);
160     }
161     return 0;
162 }

怎么说呢,感谢谭浩强教授,哈哈。

链接:https://pan.baidu.com/s/18rlpbahcp0nw7i5cswrgta
提取码:yslx

有些不务正业,哈哈,学习还是为了玩,那将毫无意义 (^_^)

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网