本文主要是介绍GO语言,半自动打怪,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
仅供学习参考,切勿用于商业用途
package mainimport ("fmt""github.com/go-vgo/robotgo""math/rand""time"
)const (taskNum = 7
)type Task struct {Name stringSleepTime1 intSleepTime2 intFunc 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
}
这篇关于GO语言,半自动打怪的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!