我試圖實現一個簡單的槳遊戲的作弊碼,作弊時只應按下按鍵的特定順序時激活:向上,向下,向下,向左,向左,向右,向右。我正在嘗試,但我無法得到它!Java - 是否有可能讓它監聽特定的按鍵順序?
if(up >= 2){
if(down >= 2){
if(left >= 2){
if(right >= 2){
cheat = true;
g.setColor(0x00FF0000);
g.fillRect(x, y, canvas.getWidth(), 5);
g.fillRect(x, y - 5, 5, 5);
g.fillRect(canvas.getWidth() - 5, y - 5, 5, 5);
x = 0;
width = canvas.getWidth();
height = canvas.getHeight();
}else{
g.setColor(0x00FF0000);
g.fillRect(x, y, width, height);
g.fillRect(x, y - height, height, height);
g.fillRect(x + width - height, y - height, height, height);
System.out.println(up + " " + down + " " + left + " " + right + "right");
}
}else{
g.setColor(0x00FF0000);
g.fillRect(x, y, width, height);
g.fillRect(x, y - height, height, height);
g.fillRect(x + width - height, y - height, height, height);
right = 0;System.out.println(up + " " + down + " " + left + " " + right + "left");
}
}else{
g.setColor(0x00FF0000);
g.fillRect(x, y, width, height);
g.fillRect(x, y - height, height, height);
g.fillRect(x + width - height, y - height, height, height);
left = 0; right = 0;System.out.println(up + " " + down + " " + left + " " + right + "down");
}
}else{
g.setColor(0x00FF0000);
g.fillRect(x, y, width, height);
g.fillRect(x, y - height, height, height);
g.fillRect(x + width - height, y - height, height, height);
down = 0; left = 0; right = 0;System.out.println(up + " " + down + " " + left + " " + right + "up");
}
程序每隔50ms更新一次。 向上,向左,向下,向右是按鍵,當按下這些按鍵時,它會像計數器一樣添加。忽略整個g.fillRect和g.setColor和System.out(試圖看看它是如何行事的以及如何自行解決問題)。當用戶沒有輸入正確的密鑰順序時,計數器應該重置,但由於每50ms更新一次,它會將計數器擰緊。
有沒有辦法來檢測按鍵的特定順序,或者它是不可能的?
每次按下某個鍵時都會得到一個鍵碼。現在,你爲什麼不親自檢查訂單並激活它? – TheLostMind