Browse Source

Merge pull request #6 from 17mgeffert/master

fixed some silly stuff
TryingToMakeThisALittleBetter
17mgeffert 6 years ago
committed by GitHub
parent
commit
538ec64849
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 62 deletions
  1. +8
    -0
      README.md
  2. +0
    -1
      src/tanks/Enemy.java
  3. +1
    -14
      src/tanks/Living.java
  4. +20
    -47
      src/tanks/Tanks.java

+ 8
- 0
README.md View File

@ -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.

+ 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