Browse Source

Everytime i open this up i find more formatting issues with the code alone, i feel like 12th grade us's had no idea how to code.

pull/6/head
Michael 6 years ago
parent
commit
44622d1d35
3 changed files with 21 additions and 62 deletions
  1. +0
    -1
      src/tanks/Enemy.java
  2. +1
    -14
      src/tanks/Living.java
  3. +20
    -47
      src/tanks/Tanks.java

+ 0
- 1
src/tanks/Enemy.java View File

@ -6,7 +6,6 @@
*/
package tanks;
import javax.swing.JFrame;
public abstract class Enemy extends Living

+ 1
- 14
src/tanks/Living.java View File

@ -17,18 +17,6 @@ public class Living extends RotationalElement
health=0;
isAlive=true;
}
public void setHealth(int holdH)
{
health=holdH;
}
public void setAlive(boolean holdA)
{
isAlive=holdA;
}
public int getHealth()
{
return health;
}
public boolean getAlive()
{
return isAlive;
@ -41,8 +29,7 @@ public class Living extends RotationalElement
public void takeDamage()
{
health-=10;
if(health<=0)
{
if(health<=0) {
isAlive=false;
}
}

+ 20
- 47
src/tanks/Tanks.java View File

@ -29,7 +29,6 @@ public class Tanks
private Timer move;
private KeyListener key;
//game elements
private ArrayList<Bullet> bullets;
private Player p;
@ -39,13 +38,10 @@ public class Tanks
//constructor
public Tanks()
{
frame=new JFrame("Tanks project");
frame.setSize(fwidth,fheight + 150);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
newGame();
key=new KeyListener() {
@ -93,7 +89,6 @@ public class Tanks
for(Bullet b: bullets) {
b.draw(g);
}
for(Enemy en: enemy) {
en.draw(g);
}
@ -105,8 +100,9 @@ public class Tanks
//Wave
g.setColor(Color.WHITE);
g.setFont(new Font("Arial" , 1, 25));
g.drawString("Wave: " + wave.waveNum + " Ammo: "+ p.ammo + " Kills: " + wave.kills +" Health: " + p.health + " Time: " + wave.timeCount, 50, fheight + 50);
g.drawString("Wave: " + wave.waveNum + " Ammo: "+ p.ammo +
" Kills: " + wave.kills +" Health: " + p.health +
" Time: " + wave.timeCount, 50, fheight + 50);
//Pausing the game
if(wave.gameMode == 3) {
g.setColor(Color.WHITE);
@ -161,11 +157,7 @@ public class Tanks
p = new Player();
wave = new Wave();
}
/*
Sub-classes that require the fields in tanks
*/
/**
* the player class which extends the living class
@ -179,17 +171,14 @@ public class Tanks
private boolean up,down,left,right, rleft, rRight;
private int ammo=10;
private boolean shoot;
ActionListener coolDown = new ActionListener()
{
ActionListener coolDown = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(shoot==false)
{
if(shoot==false) {
shoot=true;
}
}
};
Timer time=new Timer(300,coolDown);
@ -202,8 +191,7 @@ public class Tanks
t=new Turret(this);
speed = 5;
health = 100;
this.imageLocation = "player.png";
super.loadImage();
@ -211,51 +199,39 @@ public class Tanks
height = 50;
}
void move()
{
if(rleft)
{
void move() {
if(rleft) {
t.rotate(-1);
}
if(rRight)
{
if(rRight) {
t.rotate(1);
}
if(up==true)
{
if(up==true) {
super.move(-1);
t.move(-1);
}
if(down==true)
{
if(down==true) {
t.move(1);
super.move(1);
}
if(left==true)
{
if(left==true) {
super.direction -=5;
t.rotate(-1);
}
if(right==true)
{
if(right==true) {
super.direction+=5;
t.rotate(1);
}
if(y<=0)
{
if(y<=0) {
y+=speed;
}
else if(x<=0)
{
else if(x<=0) {
x+=speed;
}
else if(x>=fwidth-width)
{
else if(x>=fwidth-width) {
x-=speed;
}
else if(y>=fheight-height)
{
else if(y>=fheight-height) {
y-=speed;
}
t.x = x;
@ -294,8 +270,7 @@ public class Tanks
}
}
}
void shoot()
{
void shoot() {
if(ammo>0) {
bullets.add(new Bullet (t));
ammo--;
@ -314,11 +289,9 @@ public class Tanks
* the move method checks to see if it collides with the player
* if so it removes itself from the arraylist in tanks and deducts damage
*/
private class Zombie extends Enemy
{
private class Zombie extends Enemy {
//constructor instanciated fields
public Zombie()
{
public Zombie() {
super();
spawn(fwidth, fheight);
width = 30;

Loading…
Cancel
Save