2013-06-05 156 views
0

回答我会尽力使小游戏成为this。我会尝试替代点击触摸屏。外观很简单,但是我找不到解决这个问题的办法。如何通过点击R

我想知道你能否帮助我。

预先感谢您。

+2

不知道你问什么在这里,但'identify'会让你读取用户的鼠标点击? –

+1

或者查看'tcltk'包中的画布小部件。 – Thomas

+2

这是一个很好的问题,有一个很好的答案。我不明白为什么它关闭。 –

回答

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 
    } 
} 

enter image description here

+0

谢谢。答案是“识别”。 – Choijaeyoung