GO语言,半自动打怪

仅供学习参考,切勿用于商业用途

go 复制代码
package main

import (
    "fmt"
    "github.com/go-vgo/robotgo"
    "math/rand"
    "time"
)

const (
    taskNum = 7
)

type Task struct {
    Name       string
    SleepTime1 int
    SleepTime2 int
    Func       func()
}

func main() {
    for i := 1; i <= 32; i++ {
        tasks := []Task{
            {
                Name:       "第1图",
                SleepTime1: 3000,
                SleepTime2: 100,
                Func:       Task1,
            },
            {
                Name:       "第2图",
                SleepTime1: 1,
                SleepTime2: 1,
                Func:       Task2,
            },
            {
                Name:       "第3图",
                SleepTime1: 1,
                SleepTime2: 1,
                Func:       Task3,
            },
            {
                Name:       "第4图",
                SleepTime1: 1500,
                SleepTime2: 80,
                Func:       Task4,
            },
            {
                Name:       "第5图",
                SleepTime1: 1500,
                SleepTime2: 80,
                Func:       Task5,
            },
            {
                Name:       "第6图",
                SleepTime1: 1500,
                SleepTime2: 80,
                Func:       Task6,
            },
            {
                Name:       "第7图",
                SleepTime1: 1500,
                SleepTime2: 80,
                Func:       Task7,
            },
        }

        for i := 1; i <= taskNum; i++ {
            task := tasks[i-1]
            fmt.Printf("开始执行任务:%s\n", task.Name)
            time.Sleep(time.Duration(task.SleepTime1) * time.Millisecond)
            time.Sleep(time.Duration(rand.Intn(task.SleepTime2)) * time.Millisecond)
            task.Func()
            fmt.Printf("任务%s已完成\n", task.Name)
        }

    }
}

func Task1() {
    robotgo.MoveClick(367, 270, `left`, true)
    time.Sleep(2000)
    robotgo.KeyTap("right")
    robotgo.MilliSleep(10)
    robotgo.KeyToggle("right", "down")
    time.Sleep(6 * time.Second)
    robotgo.KeyToggle("right", "up")
    time.Sleep(100)
    fmt.Printf("第1图通关,")
}

func Task2() {
    robotgo.KeyTap("s")
    time.Sleep(2 * time.Second)
    robotgo.KeyTap("a")
    robotgo.MilliSleep(20)

    //向下移动3秒向上移动1秒
    robotgo.KeyToggle("up", "down")
    time.Sleep(2 * time.Second)
    robotgo.KeyToggle("up", "up")
    robotgo.MilliSleep(50)

    robotgo.KeyTap("g")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("w")

    time.Sleep(9 * time.Second)

    robotgo.KeyToggle("down", "down")
    time.Sleep(1 * time.Second)
    robotgo.KeyToggle("down", "up")
    robotgo.MilliSleep(50)
    fmt.Printf("第二图通关,")
}

func Task3() {
    robotgo.MilliSleep(50)
    robotgo.KeyTap("right")
    robotgo.MilliSleep(10)
    robotgo.KeyToggle("right", "down")
    time.Sleep(2 * time.Second)
    robotgo.KeyToggle("right", "up")
    fmt.Printf("进入第3图")

    robotgo.MilliSleep(50)
    robotgo.KeyTap("h")
    time.Sleep(3 * time.Second)
    time.Sleep(6 * time.Second)

    robotgo.KeyToggle("up", "down")
    time.Sleep(2 * time.Second)
    robotgo.KeyToggle("up", "up")
    robotgo.MilliSleep(50)

    robotgo.KeyToggle("down", "down")
    time.Sleep(1 * time.Second)
    robotgo.KeyToggle("down", "up")
    robotgo.MilliSleep(50)

    robotgo.KeyToggle("right", "down")
    time.Sleep(2 * time.Second)
    robotgo.KeyToggle("right", "up")
    robotgo.MilliSleep(50)

    fmt.Printf("第3通关")

}

func Task4() {
    robotgo.KeyTap("right")
    robotgo.MilliSleep(50)
    robotgo.KeyToggle("right", "down")
    time.Sleep(5 * time.Second)
    robotgo.KeyToggle("right", "up")
    robotgo.MilliSleep(50)

    time.Sleep(20 * time.Second)

    robotgo.KeyToggle("right", "down")
    time.Sleep(2 * time.Second)
    robotgo.KeyToggle("right", "up")
    robotgo.MilliSleep(50)

    robotgo.KeyToggle("up", "down")
    time.Sleep(2 * time.Second)
    robotgo.KeyToggle("up", "up")
    robotgo.MilliSleep(50)

    robotgo.KeyToggle("down", "down")
    time.Sleep(1 * time.Second)
    robotgo.KeyToggle("down", "up")
    robotgo.MilliSleep(50)

    fmt.Printf("第4图通关")
}

func Task5() {

    //向上移动1秒
    fmt.Print("****准备进入5图")

    //向上移动1秒
    robotgo.KeyTap("right")
    robotgo.MilliSleep(50)
    robotgo.KeyToggle("right", "down")
    time.Sleep(5 * time.Second)
    robotgo.KeyToggle("right", "up")
    robotgo.MilliSleep(50)
    time.Sleep(20 * time.Second)

    robotgo.KeyToggle("right", "down")
    time.Sleep(2 * time.Second)
    robotgo.KeyToggle("right", "up")
    robotgo.MilliSleep(50)

    robotgo.KeyToggle("up", "down")
    time.Sleep(2 * time.Second)
    robotgo.KeyToggle("up", "up")
    robotgo.MilliSleep(50)

    robotgo.KeyToggle("down", "down")
    time.Sleep(1 * time.Second)
    robotgo.KeyToggle("down", "up")
    robotgo.MilliSleep(50)

    fmt.Printf("第5图通关")
}

func Task6() {
    fmt.Print("****准备进入6图")
    robotgo.KeyTap("right")
    robotgo.MilliSleep(50)
    robotgo.KeyToggle("right", "down")
    robotgo.KeyToggle("down", "down")
    time.Sleep(5 * time.Second)
    robotgo.KeyToggle("right", "up")
    robotgo.KeyToggle("down", "up")
    robotgo.MilliSleep(50)

    robotgo.KeyTap("w")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("a")
    fmt.Print("****进入6图")

    robotgo.KeyTap("w")
    time.Sleep(20 * time.Second)
    fmt.Printf("最后通关1")
    robotgo.KeyTap("w")
    time.Sleep(30 * time.Second)
    fmt.Printf("最后通关2")
    robotgo.KeyTap("w")
    time.Sleep(20 * time.Second)


    fmt.Printf("全图通关")
}

func Task7() {
    fmt.Printf("开始捡完物品")

    robotgo.KeyTap("v")
    time.Sleep(3 * time.Second)

    //修装备
    //time.Sleep(time.Duration(sleepTime2) * time.Millisecond)
    //robotgo.KeyTap("s")
    //time.Sleep(time.Duration(sleepTime2) * time.Millisecond)
    //robotgo.KeyTap("s")
    //time.Sleep(time.Duration(sleepTime2) * time.Millisecond)
    //robotgo.KeyTap("enter")
    //time.Sleep(1 * time.Second)

    //捡东西
    time.Sleep(3 * time.Second)
    fmt.Printf("第一个图捡完物品")

    robotgo.MilliSleep(2000)
    robotgo.MoveClick(10, 10, `left`, true)
    robotgo.MilliSleep(50)
    robotgo.MoveClick(10, 10, `left`, true)

    time.Sleep(2 * time.Second)
	robotgo.KeyTap("enter")
	time.Sleep(2 * time.Second)
	robotgo.KeyTap("shift")
    
    robotgo.MilliSleep(50)
    robotgo.KeyTap("/")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("/")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("shift")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("y")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("i")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("d")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("o")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("n")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("g")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("w")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("u")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("p")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("i")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("n")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("space")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("enter")
    robotgo.MilliSleep(50)
    time.Sleep(3 * time.Second)
    fmt.Printf("第一个图捡完物品")

    robotgo.MilliSleep(2000)
    robotgo.MoveClick(1377, 71, `left`, true)
    robotgo.MilliSleep(50)
    robotgo.MoveClick(1377, 71, `left`, true)
    robotgo.MilliSleep(50)
    robotgo.KeyTap("enter")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("shift")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("/")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("/")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("shift")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("y")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("i")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("d")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("o")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("n")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("g")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("w")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("u")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("p")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("i")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("n")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("space")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("enter")
    robotgo.MilliSleep(50)
    time.Sleep(3 * time.Second)

    robotgo.MilliSleep(50)
    robotgo.MoveClick(10, 10, `left`, true)
    robotgo.MilliSleep(100)

    robotgo.KeyTap("esc")
    time.Sleep(1 * time.Second)
    robotgo.KeyTap("f10")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("f10")
    time.Sleep(3 * time.Second)
}

func randInt(min, max int) int {
    rand.Seed(time.Now().UnixNano())
    return rand.Intn(max-min+1) + min
}
相关推荐
Ajiang28247353041 小时前
对于C++中stack和queue的认识以及priority_queue的模拟实现
开发语言·c++
幽兰的天空1 小时前
Python 中的模式匹配:深入了解 match 语句
开发语言·python
Theodore_10224 小时前
4 设计模式原则之接口隔离原则
java·开发语言·设计模式·java-ee·接口隔离原则·javaee
----云烟----6 小时前
QT中QString类的各种使用
开发语言·qt
lsx2024066 小时前
SQL SELECT 语句:基础与进阶应用
开发语言
开心工作室_kaic7 小时前
ssm161基于web的资源共享平台的共享与开发+jsp(论文+源码)_kaic
java·开发语言·前端
向宇it7 小时前
【unity小技巧】unity 什么是反射?反射的作用?反射的使用场景?反射的缺点?常用的反射操作?反射常见示例
开发语言·游戏·unity·c#·游戏引擎
武子康7 小时前
Java-06 深入浅出 MyBatis - 一对一模型 SqlMapConfig 与 Mapper 详细讲解测试
java·开发语言·数据仓库·sql·mybatis·springboot·springcloud
qq_17448285757 小时前
springboot基于微信小程序的旧衣回收系统的设计与实现
spring boot·后端·微信小程序
转世成为计算机大神7 小时前
易考八股文之Java中的设计模式?
java·开发语言·设计模式