func getUserCmd() bool { cmd := C.getKey() if cmd == KEY_EXIT { return false } if cmd == KEY_CTRL { cmd = C.getKey() switch cmd { case KEY_UP: Up() case KEY_DOWN: Down() case KEY_LEFT: Left() case KEY_RIGHT: Right() } } return true }
func getCmd() bool { cmd := C.getKey() if cmd == KEY_EXIT { return false } if cmd == KEY_CTRL { cmd = C.getKey() switch cmd { case KEY_UP: moveDirection(1) case KEY_DOWN: moveDirection(3) case KEY_LEFT: moveDirection(0) case KEY_RIGHT: moveDirection(2) } } return true }
func main() { isRunning := true for isRunning { if maxValue == WIN { fmt.Println("You win!") break } if !canMove() && maxValue != WIN { fmt.Println("You lose.") break } isRunning = getUserCmd() } fmt.Println("Press any key to exit.") C.getKey() }