如何通过单击R来回答

Cho*_*ung 0 r

我会尽量让小游戏,因为这个.我会尝试替换点击触摸屏.外观很容易,但我找不到解决这个问题的方法.

我想知道你是否可以帮助我.

先感谢您.

Jul*_*ora 6

试试这个:

set.seed(123)
y <- runif(9)
x <- runif(9)

# 1. Numbers 1-9 appear on the screen for some time
plot(x, y, pch = as.character(1:9), 
     xlab = "", ylab = "",  
     xaxt = "n", yaxt = "n",
     xlim = c(-0.05, 1.05), ylim = c(-0.05, 1.05))
Sys.sleep(3)

# 2. Black boxes replace numbers and now one is allowed to click on them
for(i in 1:9) {
  plot(x[i:9], y[i:9], pch = 15, cex = 3,
       xlab = "", ylab = "",  
       xaxt = "n", yaxt = "n",
       xlim = c(-0.05, 1.05), ylim = c(-0.05, 1.05))
  ans <- identify(x, y, n = 1, plot = FALSE)
  if(ans != i){
    cat("Game over")
    break
  }
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述