2013-06-05 158 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