Stein nach links und rechts bewegen.

This commit is contained in:
zhe 2021-11-22 12:35:26 +01:00
parent 4d0f9a10ba
commit 11eef601e0
3 changed files with 11 additions and 1 deletions

View File

@ -30,6 +30,8 @@ public class Board extends JPanel implements KeyListener
private int fast = 50;
private long beginTime;
private int delayTime = normal;
private int deltax = 0;
public Board() {
@ -39,6 +41,8 @@ public class Board extends JPanel implements KeyListener
@Override
public void actionPerformed(ActionEvent e) {
if(System.currentTimeMillis() -beginTime > delayTime){
x +=deltax;
deltax= 0;
y++;
beginTime=System.currentTimeMillis();
}
@ -56,6 +60,7 @@ public class Board extends JPanel implements KeyListener
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(Color.lightGray);
//shape mit 2-Forschleife
for(int row=0;row< shape.length;row++){
for(int col = 0;col< shape[0].length;col++){
@ -85,8 +90,13 @@ public class Board extends JPanel implements KeyListener
public void keyPressed(KeyEvent e) {
if(e.getKeyChar() == KeyEvent.VK_SPACE){
delayTime=fast;
}else if(e.getKeyChar() == KeyEvent.VK_ENTER){
deltax = 2;
}
else if(e.getKeyChar() == KeyEvent.VK_ESCAPE){
deltax = -2;
}
}
}
@Override
public void keyReleased(KeyEvent e) {