Example #1
0
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
}
Example #2
0
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
}
Example #3
0
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()
}