From 471067bb589ed82da54c936003e8ce5b03a95dfe Mon Sep 17 00:00:00 2001 From: 17mgeffert Date: Fri, 12 Oct 2018 14:04:47 -0400 Subject: [PATCH 1/2] Create README.md --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..46b8c0f --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# Tanks +Set 3 AP computer science programming project +This was a project created for the prupose of illistrating several features in Java. It can be run through any compiler through standard +practices. + +To contribute: +The main class, Tanks, is outdated cold use some effiency increases. The code and logic is long and could easily be improved. +In addition, the program has limited funciontality. after a certain level, the game just ends. this level could be increased to add difficulty. From 44622d1d35f86a98b93c33e45083a7112dbf59b1 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 13 Oct 2018 22:37:18 -0400 Subject: [PATCH 2/2] 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. --- src/tanks/Enemy.java | 1 - src/tanks/Living.java | 15 +--------- src/tanks/Tanks.java | 67 +++++++++++++------------------------------ 3 files changed, 21 insertions(+), 62 deletions(-) diff --git a/src/tanks/Enemy.java b/src/tanks/Enemy.java index 037bf48..f6cf6fd 100644 --- a/src/tanks/Enemy.java +++ b/src/tanks/Enemy.java @@ -6,7 +6,6 @@ */ package tanks; -import javax.swing.JFrame; public abstract class Enemy extends Living diff --git a/src/tanks/Living.java b/src/tanks/Living.java index 1e8359d..7c8fd33 100644 --- a/src/tanks/Living.java +++ b/src/tanks/Living.java @@ -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; } } diff --git a/src/tanks/Tanks.java b/src/tanks/Tanks.java index a83a556..39a7e8d 100644 --- a/src/tanks/Tanks.java +++ b/src/tanks/Tanks.java @@ -29,7 +29,6 @@ public class Tanks private Timer move; private KeyListener key; - //game elements private ArrayList 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;