From 3abe3a3db04793e1a0f28f7cba7418e8fa434bcb Mon Sep 17 00:00:00 2001 From: 17mgeffert Date: Tue, 31 May 2016 10:23:03 -0400 Subject: [PATCH] added fields and methods to player class --- src/tanks/Tanks.java | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/tanks/Tanks.java b/src/tanks/Tanks.java index 6e30a80..9801809 100644 --- a/src/tanks/Tanks.java +++ b/src/tanks/Tanks.java @@ -23,7 +23,8 @@ public class Tanks //fields private JFrame frame; private JPanel panel; - + private int fheight=500; + private int fwidth=500; private Timer move; private KeyListener key; @@ -167,14 +168,17 @@ public class Tanks height = 50; } - void move() + void move() { if(up==true) { - super.move(-1); + + super.move(-1); + } if(down==true) { + super.move(1); } if(left==true) @@ -185,6 +189,23 @@ public class Tanks { 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) {