WeChatジャンプが支援する特定のJava実装コードは、参照用です。特定のコンテンツは次のとおりです
1. Zhihuを参照して、Pythonを使用してWeChatをプレイする方法を教えてください。私は常に中途半端なPythonであったことを考えると、Pythonを使用してポイントを獲得することを計画しましたが、Python環境をインストールする以外に選択肢がなく、さまざまなモジュールが欠落し、エラーが報告されました。それで、私はJavaを使用してそれを再実装しました。
2。環境構成と関連する手順:
1)Windowsシステム、私はWin10です
2)AVA環境、JDK7以上をインストールします
3)1つのAndroid電話、1つのデータケーブル
4)ADBドライバーをコンピューターにインストールし、Android電話に接続し、同時にUSBデバッグモードをオンにします
5)WeChat Miniプログラムのジャンプゲームを開き、Javaプログラムが実行を開始し、以下の特定のコードを読む
6)1920x1080の画面解像度で、Meilan Note2 Android電話を使用しています。関連するパラメーターを調整するには、携帯電話のさまざまなモデルが必要になる場合があります。詳細については、コードコメントを参照してください。
7)ポイントのスコアに失敗した後、ゲームを自動的に再起動する機能を追加しました
8)それは単なる娯楽です、真面目にしないでください。 WeChatの役人がそれに注意を払っていると言われています。スコアが高すぎると、クリアされる可能性があります。ハハ
3。これ以上苦労せずに、コードを追加してください:
パッケージcom.yihusitian.gamehelper; java.awt.image.bufferedimageをインポートします。 java.io.bufferedreaderをインポートします。 java.io.fileをインポートします。 java.io.ioexceptionをインポートします。 java.io.inputStreamReaderをインポートします。 java.util.arraysをインポートします。 java.util.concurrent.timeunitをインポートします。 javax.imageio.imageioをインポートします。 /** *参照Zhihu * * @link <a href = "https://zhuanlan.zhihu.com/p/32452473" rel = "external nofollow" rel = "external nofollow"ターゲット= "_blank"> https://zhuanlan.zhihu. * @author leeho */ public class jumpjumphelper {private static final string image_name = "current.png"; private static final string store_dir = "d:/jump_screencapture"; //数量private private static final int imageLengthLength = 5; //画像ストレージのサイズプライベート静的最終long [] imageLength = new long [imageLengthLength];プライベート最終rgbinfo rgbinfo = new rgbinfo();プライベート最終文字列[] ADB_SCREEN_CAPTURE_CMDS = {"ADB SHELL SCREENCAP -P /SDCARD /" + IMAGE_NAME、 "ADB Pull /Sdcard/current.png" + store_dir}; //ゲームスコアディスプレイ領域の下部にあるy座標スクリーンショットのディスプレイ領域、300は1920x1080の値です。実際の状況に応じて、プライベートファイナルint gamescorebottomy = 300を変更します。 //プレスタイム係数は、特定の状況に従って適切に調整できます。プライベートファイナルダブルPressTimeCoefficient = 1.35; //プレスの開始ポイント座標は、次のゲームのプライベートファイナルint swipex = 550の出発点座標でもあります。プライベートファイナルint swipey = 1580; //チェスピースのベースの高さはプライベートファイナルINT HALFBASEBOARDHEIGHT = 20です。 //チェスピースの幅はスクリーンショットから取得され、自分でプライベートファイナルイントを調整しますhalmabodywidth = 74; //ゲームスクリーンショットの2つのスプリングボードのミッドポイント座標は、主に角度の計算に使用されます。 XYの割合は、実際のスクリーンショットに基づいて計算できます。プライベートファイナルInt boardx1 = 813;プライベート最終int boardy1 = 1122;プライベートファイナルInt boardx2 = 310;プライベートファイナルイントボード2 = 813; / ** *次のスプリングボードのチェッカーとセンター座標を取得 * * @return * @author leeho * @throws ioexception * @update 2017年12月31日12:18:22 pm */ private int [] gethalmaandboardxyvalue(file currentimage)Throws ioException int width = bufferedimage.getWidth(); int height = bufferedimage.getheigh(); System.out.println( "width:" + width + "、height:" + height); int halmaxsum = 0; int halmaxcount = 0; int halmaymax = 0; int boardx = 0; int boardy = 0; //スクリーンショットからピクセルポイントを上から下に転送し、位置認識の基礎としてチェスピースの色を使用します。最後に、チェスピースの色の最低行のすべてのピクセルの平均値が取り出されます。つまり、チェスピースの座標を計算します(int y = gamescorebottomy; y <height; y ++){for(int x = 0; x <width; x ++){processrgbinfo(bufferedimage、x、y); int rvalue = this.rgbinfo.getrvalue(); int gValue = this.rgbinfo.getGValue(); int bvalue = this.rgbinfo.getBValue(); // RGBの色に応じてチェスピースの位置を識別します。 halmaxcount ++; // yチェスピースの一番下行の座標halmaymax = y> halmaymax? Y:Halmaymax; }}} if(halmaxsum!= 0 && halmaxcount!= 0){// xチェスピースの一番下行の座標値int halmax = halmaxsum /halmaxcount; //チェスピースの半分を移動しますシャーシの高さはint halmay = halmaymax -halfbaseboardheight; // GAMESCOREBOTTOMYから開始(int y = gamescoreBottomy; y <height; y ++){processRgbinfo(bufferedimage、0、y); int lastpixelr = this.rgbinfo.getrvalue(); int lastpixelg = this.rgbinfo.getGValue(); int lastpixelb = this.rgbinfo.getBValue(); //計算されたBoardX値が0より大きい限り、次のスプリングボードの中心調整x値が取得されたことを意味します。 if(boardx> 0){break; } int boardxsum = 0; int boardxcount = 0; for(int x = 0; x <width; x ++){processrgbinfo(bufferedimage、x、y); int pixelr = this.rgbinfo.getrvalue(); int pixelg = this.rgbinfo.getGValue(); int pixelb = this.rgbinfo.getBValue(); //チェスピースのヘッドが次のスプリングボードよりも高い場合をトレーニングします。 } //上から下、次のスプリングボードの頂点位置までスキャンします。次のスプリングボードは、円または箱です。複数のポイントを取得して平均を見つけます((math.abs(pixelr -lastpixelr) + math.abs(pixelg -lastpixelg) + math.abs(pixelb -lastpixelb))> 10){boardxsum + = x; boardxcount ++; }} if(boardxsum> 0){boardx = boardxsum / boardxcount; }} //実際の角度から、次のボードの中心に近い座標を見つけます。 boardy =(int)(halmay -math.abs(boardx -halmax) * math.abs(boardy1 -boardy2) / math.abs(boardx1 -boardx2)); if(boardx> 0 && boardy> 0){int [] result = new int [4]; // x座標結果[0] = halmax; // y座標結果[1] = halmay; // x座標結果[2] = boardx; // y座標結果[3] =ボード;返品結果; }} nullを返します。 } / ** *コマンドを実行 * * @paramコマンド * @author leeho * @update 2017年12月31日12:13:39 pm * / private void executecommand(string command){process process = null; try {process = runtime.getRuntime()。exec(command); system.out.println( "exec command start:" + command); process.waitfor(); BufferedReader bufferedReader = new BufferedReader(new inputStreamReader(process.getErrorStream())); string line = bufferedreader.readline(); if(line!= null){system.out.println(line); } system.out.println( "exec command end:" + command); } catch(Exception e){e.printstacktrace(); }最後に{if(process!= null){process.destroy(); }}} / ** * ADBはAndroidスクリーンショットを取得します * * @author leeho * @update 2017年12月31日午後12時11:42 pm * / private void executeadbcapturecommands(){for(string:adb_screen_capture_cmds){execumommand(command); }} / ** *ジャンプ * * @param距離 * @author leeho * @update 2017年12月31日12:23:19 pm * / private void dojump(double.out.println( "距離:" +距離); //プレス時間を計算する、最小200ms int presstime =(int)math.max(distance * presstimecoefficient、200); system.out.println( "presstime:" + presstime); //プレス操作string string command = string.format( "adbシェル入力スワイプ%s%s%s%s"、swipex、swipey、swipex、swipey、presstime); System.out.println(command); executeCommand(コマンド); } / ** *別のゲーム * * @author leeho * @update 2017年12月31日12:47:06 pm * / private void replaygame(){string command = string.format( "adb shell input tap s%s"、swipex、swipey); executeCommand(コマンド); } / ** *ジャンプの距離、つまり2つのポイント間の距離を計算します。つまり、2つのポイント間の距離 * * * @param Halmay * @Param Boardx * @Param Boardy * @return * @author leeho * @update 2017年12月31日午後12時27分30分 * Math.sqrt(math.pow(math.abs(boardx -halmax)、2) + math.pow(math.abs(boardy -halmay)、2)); } public static void main(string [] args){try {file storedir = new file(store_dir); if(!storedir.exists()){boolean flag = storedir.mkdir(); if(!flag){system.err.println( "画像ストレージディレクトリの作成に失敗した");戻る; }} JumpJumphelper JumpJumphelper = new JumpJumphelper(); //実行数inteceexecount = 0; for(;;){// ADBコマンドを実行してAndroidスクリーンショットjumpJumphelper.executeadbcapturecommands()を取得します;ファイルcurrentImage = new file(store_dir、image_name); if(!currentImage.exists()){system.out.println( "画像は存在しません");続く; } long length = currentImage.length(); ImageLength [executeCount%yumageLengthLength] = length; // jumpjumphelper.checkdoreplay()を再開する必要があるかどうかを確認します。 executeCount ++; System.out.println( "CurrentThrow" + executeCount + "execution!"); //チェッカーとベースプレートの中心座標を取得しますint [] result = jumpJumphelper.gethalmaandboardxyvalue(currentImage); if(result == null){system.out.println( "メソッドgethalmaandboardxyvalueの結果はnull!");続く; } int halmax = result [0]; int halmay = result [1]; int boardx = result [2]; int boardy = result [3]; System.out.println( "Halmax:" + halmax + "、halmay:" + halmay + "、boardx:" + boardx + "、boardy:" + boardy); //ジャンプの距離を計算しますDouble JumpDistance = JumpJumphelper.comPuteJumpDistance(halmax、halmay、boardx、boardy); JumpJumphelper.Dojump(JumpDistance); // timeUnit.milliseConds.sleep(2500)ごとに2.5秒間滞在します。 }} catch(例外e){e.printstacktrace(); }} / ** *再起動する必要があるかどうかを確認しますImageLength [2] ImageLength [3] && ImageLength [3] == ImageLength [4]){//これは、5回連続で画像サイズが同じであることを意味します。現在の画面が別のゲーム配列にあることを知ることができます。 //ボタンをシミュレートしてクリックして、ゲームReplayGame()を起動します。 }} / ** *指定された座標のRGB値を取得 * * @param bufferedimage * @param x * @author leeho * @utdate 2017年12月31日12:12:43 * int pixel = bufferedimage.getrgb(x、y); // rgb番号this.rgbinfo.setrvalue((pixel&0xff0000)>> 16); this.rgbinfo.setgValue((pixel&0xff00)>> 8); this.rgbinfo.setBValue((pixel&0xff)); } class rgbinfo {private int rvalue; private int gValue; private int bvalue; public int getrvalue(){return rvalue; } public void setrvalue(int rvalue){rvalue = rvalue; } public int getGValue(){return gValue; } public void setGValue(int gValue){gValue = gValue; } public int getBValue(){return bvalue; } public void setBValue(int bvalue){bvalue = bvalue; } public void reset(){this.rvalue = 0; this.gvalue = 0; this.bvalue = 0; }}}その他のコンテンツについては、特別なトピック「Jump on Wechat」を参照して学習できます。
上記はこの記事のすべての内容です。みんなの学習に役立つことを願っています。誰もがwulin.comをもっとサポートすることを願っています。