|
@ -23,7 +23,8 @@ public class Tanks |
|
|
//fields |
|
|
//fields |
|
|
private JFrame frame; |
|
|
private JFrame frame; |
|
|
private JPanel panel; |
|
|
private JPanel panel; |
|
|
|
|
|
|
|
|
|
|
|
private int fheight=500; |
|
|
|
|
|
private int fwidth=500; |
|
|
|
|
|
|
|
|
private Timer move; |
|
|
private Timer move; |
|
|
private KeyListener key; |
|
|
private KeyListener key; |
|
@ -167,14 +168,17 @@ public class Tanks |
|
|
height = 50; |
|
|
height = 50; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void move() |
|
|
|
|
|
|
|
|
void move() |
|
|
{ |
|
|
{ |
|
|
if(up==true) |
|
|
if(up==true) |
|
|
{ |
|
|
{ |
|
|
super.move(-1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
super.move(-1); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
if(down==true) |
|
|
if(down==true) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
super.move(1); |
|
|
super.move(1); |
|
|
} |
|
|
} |
|
|
if(left==true) |
|
|
if(left==true) |
|
@ -185,6 +189,23 @@ public class Tanks |
|
|
{ |
|
|
{ |
|
|
super.direction+=5; |
|
|
super.direction+=5; |
|
|
} |
|
|
} |
|
|
|
|
|
if(y<=0) |
|
|
|
|
|
{ |
|
|
|
|
|
y+=speed; |
|
|
|
|
|
} |
|
|
|
|
|
else if(x<=0) |
|
|
|
|
|
{ |
|
|
|
|
|
x+=speed; |
|
|
|
|
|
} |
|
|
|
|
|
else if(x>=fwidth-width) |
|
|
|
|
|
{ |
|
|
|
|
|
x-=speed; |
|
|
|
|
|
} |
|
|
|
|
|
else if(y>=fheight-height) |
|
|
|
|
|
{ |
|
|
|
|
|
y-=speed; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
void updateDir(KeyEvent e, boolean pressed) |
|
|
void updateDir(KeyEvent e, boolean pressed) |
|
|
{ |
|
|
{ |
|
|