Addded in / de crement methods to the Status

Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
2012-04-03 13:24:45 -04:00
parent 738ff31d1e
commit 2152cc8213
3 changed files with 141 additions and 45 deletions

View File

@@ -20,6 +20,7 @@
*/
package com.RickBarrette.asteroids;
import java.util.ArrayList;
import java.util.Vector;
/**
@@ -29,7 +30,7 @@ import java.util.Vector;
public class AsteroidGame extends Thread {
private static final int DELAY_IN_MSEC = 50;
private Vector<Object> mWorld;
private ArrayList<Object> mWorld;
private GameFrame mGameFrame;
public boolean isStarted = false;
@@ -50,12 +51,12 @@ public class AsteroidGame extends Thread {
*/
public void addElement(Object o) {
if(o instanceof Shot)
mGameFrame.getStatusBar().setShotCount(mGameFrame.getStatusBar().getShotCount()+1);
mGameFrame.getStatusBar().incrementShotCount();
if(o instanceof Asteroid)
mGameFrame.getStatusBar().setAsteroidCount(mGameFrame.getStatusBar().getAsteroidCount()+1);
mGameFrame.getStatusBar().incrementAsteroidCount();
mWorld.addElement(o);
mWorld.add(o);
}
/**
@@ -63,13 +64,21 @@ public class AsteroidGame extends Thread {
* @author ricky barrette
*/
public void createGame() {
mWorld = new Vector<Object>();
mWorld = new ArrayList<Object>();
mWorld.add(new Ship(100,100,0,.35,.98,.4,1));
addElement(new Asteroid(500, 500, 1, 10, 50, 3, 3, this));
mGameFrame.getStatusBar().setShipCount(3);
mGameFrame.getStatusBar().setScore(0);
mGameFrame.getStatusBar().setAsteroidCount(0);
mGameFrame.getStatusBar().setTime(0);
mGameFrame.getStatusBar().setShotCount(0);
}
public Vector<Object> getWorld() {
/**
* @return the world
* @author ricky barrette
*/
public ArrayList<Object> getWorld() {
return mWorld;
}
@@ -89,6 +98,7 @@ public class AsteroidGame extends Thread {
mWorld.clear();
mGameFrame.setDisplayText(null);
createGame();
startGame();
}
/**
@@ -108,11 +118,13 @@ public class AsteroidGame extends Thread {
*/
public void removeElement(Object o) {
if(o instanceof Shot)
mGameFrame.getStatusBar().setShotCount(mGameFrame.getStatusBar().getShotCount()-1);
mGameFrame.getStatusBar().decrementShotCount();
if(o instanceof Asteroid)
mGameFrame.getStatusBar().setAsteroidCount(mGameFrame.getStatusBar().getAsteroidCount()-1);
mWorld.removeElement(o);
if(o instanceof Asteroid) {
mGameFrame.getStatusBar().decrementAsteroidCount();
mGameFrame.getStatusBar().incrementScore(2);
}
mWorld.remove(o);
}
/**
@@ -177,7 +189,7 @@ public class AsteroidGame extends Thread {
mWorld.remove(i);
}
mGameFrame.getStatusBar().setShipCount(mGameFrame.getStatusBar().getShipCount() -1);
mGameFrame.getStatusBar().decrementShipCount();
if(mGameFrame.getStatusBar().getShipCount() > 0){
pauseGame();

View File

@@ -233,24 +233,24 @@ public class GameFrame extends JFrame implements KeyListener, ActionListener{
break;
/*
* [H] Hyoer jump
*/
case KeyEvent.VK_H:
if(isKeyPressed){
Random myRNG = new Random();
ship.setLocation(myRNG.nextInt(mDisplay.getHeight()), myRNG.nextInt(mDisplay.getWidth()));
}
break;
/*
* [Space] Pew Pew Pew!!!
*/
case KeyEvent.VK_SPACE:
if(isKeyPressed)
mGame.addElement(new Shot(ship.getX(), ship.getY(), ship.getAngle(), ship.getXVelocity(), ship.getYVelocity(), mGame));
break;
}
/*
* [H] Hyoer jump
*/
case KeyEvent.VK_H:
if(isKeyPressed){
Random myRNG = new Random();
ship.setLocation(myRNG.nextInt(mDisplay.getHeight()), myRNG.nextInt(mDisplay.getWidth()));
}
break;
/*
* [Space] Pew Pew Pew!!!
*/
case KeyEvent.VK_SPACE:
if(isKeyPressed)
mGame.addElement(new Shot(ship.getX(), ship.getY(), ship.getAngle(), ship.getXVelocity(), ship.getYVelocity(), mGame));
break;
}
}
@Override

View File

@@ -57,72 +57,156 @@ public class Status extends JPanel {
}
/**
* @return the mAsteroidCount
* decreases total asteroid count by 1
* @author ricky barrette
*/
public int getAsteroidCount() {
return mAsteroidCount;
public synchronized void decrementAsteroidCount() {
this.mAsteroidCount -= 1;
}
/**
* reduces total score by x amount
* @param score
* @author ricky barrette
*/
public synchronized void decrementScore(int score) {
this.mScore -= mScore;
}
/**
* reduces total ships by 1
* @author ricky barrette
*/
public synchronized void decrementShipCount() {
this.mShipCount -= 1;
}
/**
* reduces total shots by 1
* @author ricky barrette
*/
public synchronized void decrementShotCount() {
this.mShotCount -= 1;
}
/**
* Reduces time be x amount
* @param mTime
* @author ricky barrette
*/
public synchronized void decrementTime(long mTime) {
this.mTime -= mTime;
}
/**
* @return the mAsteroidCount
*/
public synchronized int getAsteroidCount() {
return mAsteroidCount;
}
/**
* @return the mScore
*/
public long getScore() {
public synchronized long getScore() {
return mScore;
}
/**
* @return the mShipCount
*/
public int getShipCount() {
public synchronized int getShipCount() {
return mShipCount;
}
/**
* @return the mShotCount
*/
public int getShotCount() {
public synchronized int getShotCount() {
return mShotCount;
}
/**
* @return the mTime
*/
public long getTime() {
public synchronized long getTime() {
return mTime;
}
/**
* increases total asteroid count by 1
* @author ricky barrette
*/
public synchronized void incrementAsteroidCount() {
this.mAsteroidCount += 1;
}
/**
* increases total score by x amount
* @param score
* @author ricky barrette
*/
public synchronized void incrementScore(int score) {
this.mScore += score;
}
/**
* increases total ships by one
* @author ricky barrette
*/
public synchronized void incrementShipCount() {
this.mShipCount += 1;
}
/**
* increases total shots by one
* @author ricky barrette
*/
public synchronized void incrementShotCount() {
this.mShotCount += 1;
}
/**
* increates time by x amount
* @param mTime
* @author ricky barrette
*/
public synchronized void incrementTime(long mTime) {
this.mTime += mTime;
}
/**
* @param mAsteroidCount the mAsteroidCount to set
*/
public void setAsteroidCount(int mAsteroidCount) {
public synchronized void setAsteroidCount(int mAsteroidCount) {
this.mAsteroidCount = mAsteroidCount;
}
/**
* @param mScore the mScore to set
*/
public void setScore(long mScore) {
public synchronized void setScore(long mScore) {
this.mScore = mScore;
}
/**
* @param mShipCount the mShipCount to set
*/
public void setShipCount(int mShipCount) {
public synchronized void setShipCount(int mShipCount) {
this.mShipCount = mShipCount;
}
/**
* @param mShotCount the mShotCount to set
*/
public void setShotCount(int mShotCount) {
public synchronized void setShotCount(int mShotCount) {
this.mShotCount = mShotCount;
}
/**
* @param mTime the mTime to set
*/
public void setTime(long mTime) {
public synchronized void setTime(long mTime) {
this.mTime = mTime;
}