【Pythonが学べる】ゲーム自動化(2)～クアンタムマキ ストーリー編～【スマホゲーム】

## はじめに

smartphOtoというシステムを使ってクアンタムマキのストーリーを自動化していきます．


## smartphOto (β版)の概要

smartphOtoとはスマホゲームをPCから操作して自動化するシステムです．

![](https://hamaruki.com/wp-content/uploads/2022/08/structure2.png)

環境構築などはこちら

https://hamaruki.com/2022/08/28/smartphone_game_automation_system01/

## クアンタムマキ

2022年8月22日にリリースされた3D弾幕シューティングRPGです．
グラフィックスがめちゃ綺麗＋キャラがかわいいので最近ではおすすめのゲームです．

![](https://hamaruki.com/wp-content/uploads/2022/08/screenshot_demo.png)

## 自動化コード

gameフォルダ直下に下記のファイルを作成して頂き，実行すれば動作します．

```python
import os
import sys
import cv2
import time

sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
sys.path.append(os.path.join(os.path.dirname(__file__), '.'))

import modules.SmartphOto as SmartphOto

class QuantumMaki(SmartphOto.SmartphOto):
    def __init__(self, device_id, adb_exe_path, temp_dir, capture_dir, search_th):
        super().__init__(device_id=device_id, adb_exe_path=adb_exe_path, temp_dir=temp_dir, capture_dir=capture_dir, search_th=search_th)

    def main_Sequential(self):

        while 1:

            # --------------------------------------------
            # sample tap
            #
            
            self.tap_temp_image5_Sequential(r"image\QuantumMaki\ok.png", th=0.8)
            self.tap_temp_image5_Sequential(r"image\QuantumMaki\ok2.jpg", th=0.8)
            
            self.tap_temp_image5_Sequential(r"image\QuantumMaki\choice_stage.png", th=0.8)
            self.tap_temp_image5_Sequential(r"image\QuantumMaki\battle_start.png", th=0.8)
            self.tap_temp_image5_Sequential(r"image\QuantumMaki\skip.png", th=0.8)
            self.tap_temp_image5_Sequential(r"image\QuantumMaki\skip2.png", th=0.8)
            self.tap_temp_image5_Sequential(r"image\QuantumMaki\back.png", th=0.8)
            self.tap_temp_image5_Sequential(r"image\QuantumMaki\back.png", th=0.8)
            
            self.tap_temp_image5_Sequential(r"image\QuantumMaki\scenario.jpg", th=0.8)
            
            self.tap_temp_image5_Sequential(r"image\QuantumMaki\new_stage.png", th=0.8)
            self.tap_temp_image5_Sequential(r"image\QuantumMaki\new_stage2.jpg", th=0.8)
            
            time.sleep(2)


if __name__ == "__main__":

    # ---------------------------------------------------
    # init
    #
    adb_exe_path    = r"D:\Local_Project\5000_HaMaruki\5000.003_smartphOto\smartphOto\sdk\platform-tools_r33.0.2-windows\platform-tools\adb.exe"
    device_id       = "d7b42150"
    temp_dir        = r"image\QuantumMaki"
    capture_dir     = r"image\_capture"

    # ---------------------------------------------------
    # connect smartphone 2 pc
    #
    S2P = QuantumMaki(device_id=device_id, adb_exe_path=adb_exe_path, temp_dir=temp_dir, capture_dir=capture_dir, search_th=0.7)

    # =================================================
    # capture image
    #
    S2P_flag, S2P_image = S2P._capture_screen()
    print("S2P_flag :{}".format(S2P_flag))
    print("S2P_image:{}".format(S2P_image.shape))

    if(S2P_flag==1):
        cv2.imwrite('image/_capture/S2P_image_sample.jpg', S2P_image)

    # ---------------------------------------------------
    # main
    #
    S2P.main_Sequential()



```

## 稼働動画

[![](https://img.youtube.com/vi/_3_Pzbcc8PE/0.jpg)](https://www.youtube.com/watch?v=_3_Pzbcc8PE)