예제 #1
0
func main() {
	fmt.Println("Starting..")
	ship, err := dtl.New()
	if err != nil {
		fmt.Println("Failed to create ship")
		panic(err)
	}

	for {
		fmt.Println("Scanning...")
		ships, sectors, err := scan(ship)
		if err != nil {
			fmt.Printf("Unable to scan: %s\n", err.Error())
		} else {
			index := 0
			if len(sectors) > 1 {
				index = rand.Intn(len(sectors) - 1)
			}
			if len(sectors) > 0 {
				escapeSector := sectors[index]
				fmt.Printf("Selected escape sector %s\n", escapeSector.Name)
				if len(ships) > 0 {
					fmt.Println("ALERT! Detected Ship, evac!!!")
					evac(ship, escapeSector)
				}
			}
		}
		time.Sleep(10 * time.Second)
	}
}
예제 #2
0
func main() {
	fmt.Println("Starting..")
	ship, err := dtl.New()
	if err != nil {
		fmt.Println("Failed to create ship")
		panic(err)
	}

	for {
		time.Sleep(5 * time.Second)
		fmt.Println("Scanning...")
		ships, sectors, err := scan(ship)
		if err != nil {
			fmt.Printf("Unable to scan: %s\n", err.Error())
		} else {
			index := 0
			if len(ships) > 1 {
				index = rand.Intn(len(ships) - 1)
			}
			if len(ships) > 0 {
				target := ships[index]
				fmt.Printf("Selected target ship %s\n", target.Name)
				err := fireLoop(ship, target)
				if err != nil {
					fmt.Printf("Failed to attack %s, %s\n", target.Name, err.Error())
				}
			} else {
				index := 0
				if len(sectors) > 1 {
					index = rand.Intn(len(sectors) - 1)
				}
				if len(sectors) > 0 {
					nextSector := sectors[index]
					if err := travel(ship, nextSector); err != nil {
						fmt.Printf("Failed to travel: %s\n", err.Error())
					}
				}

			}
		}
	}
}