Java微信跳一跳操作指南
Java微信跳一跳操作指南,指哪挑哪。
本文的思路是通过adb来控制手机进行操作,通过java写一个jframe覆盖在手机屏幕上,用鼠标获取跳的起点和终点,经过试验获取跳的jframe距离和按压时长的关系(线性关系),然后通过adb来根据计算出的结果操作按下时长,(此处还需要一个第三方工具来实时把画面传送给电脑,将jframe覆盖在电脑上的画面上)。
代码很短,如下:
packagejump; importjava.awt.FlowLayout; importjava.awt.event.MouseAdapter; importjava.awt.event.MouseEvent; importjavax.swing.JFrame; importjavax.swing.JLabel; @SuppressWarnings("serial") publicclassJumpJumpextendsJFrame{ privateJLabellabel; booleanflag=false; intx0,y0,x1,y1; publicJumpJump(){ super("微信跳一跳");//新建窗口 this.setUndecorated(true); this.setOpacity(0.7f); this.setSize(320,580);//宽高自设 this.setVisible(true);//可见 //this.dispose(); this.setLocationRelativeTo(null); this.toFront(); this.setLayout(newFlowLayout(FlowLayout.CENTER)); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabellabel=newJLabel("右键点击"); this.add(label); this.addMouseListener(newMouseAdapter(){ publicvoidmouseClicked(MouseEvente){ if(e.getButton()==MouseEvent.BUTTON3){//3代表右键 if(!flag){ x0=e.getX(); y0=e.getY(); Stringbanner="鼠标当前点击位置的坐标是"+x0+","+y0; label.setText(banner); flag=true; } else{ x1=e.getX(); y1=e.getY(); double_x=Math.abs(x0-x1); double_y=Math.abs(y0-y1); doubledis=Math.sqrt(_x*_x+_y*_y); label.setText(Math.ceil(dis)*4.8+""); flag=false; Stringcmd="adbshellinputtouchscreenswipe170187170187"+Math.round(dis*4.6); Runtimerun=Runtime.getRuntime(); try{ Processpr=run.exec(cmd); System.out.println(cmd); pr.waitFor(); }catch(Exceptione1){ e1.printStackTrace(); System.out.println(e1); } } } } }); } publicstaticvoidmain(String[]args){ newJumpJump(); } }
下面这段代码是设置透明度的:
this.setUndecorated(true); this.setOpacity(0.7f);
x0y0是鼠标第一次点击的点的坐标,x1y1是第二次坐标,通过flag判断是第一次还是第二次点击。
这一段是代码控制cmd操作,就不用自己在cmd里每次输入了:
Stringcmd="adbshellinputtouchscreenswipe170187170187"+Math.round(dis*4.6); Runtimerun=Runtime.getRuntime(); try{ Processpr=run.exec(cmd); System.out.println(cmd); pr.waitFor(); }catch(Exceptione1){ e1.printStackTrace(); System.out.println(e1); }
这里的系数需要自己通过不断测试来调整,即最后那个系数4.6可自行调整:
Stringcmd="adbshellinputtouchscreenswipe170187170187"+Math.round(dis*4.6);
操作方法很简单,鼠标右键点击一次当前棋子所在位置,然后鼠标右键再点一次落点位置。
更多内容大家可以参考专题《微信跳一跳》进行学习。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。