Skip to content

Commit

Permalink
Add a class to handle score information
Browse files Browse the repository at this point in the history
  • Loading branch information
vbarthel-fr committed Aug 15, 2013
1 parent 857ae21 commit 63eb650
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,19 @@
import java.util.List;

public class GameInformation implements Parcelable {
protected int mScore;
protected long mRemainingTime;
protected long mSpawningTime;
protected Weapon mWeapon;
protected int mMaxTargetOnTheField;
protected TargetableItem mCurrentTarget;
protected List<TargetableItem> mTargetableItems;
protected List<DisplayableItem> mDisplayableItems;
protected int mTargetKilled;
protected int mBulletFired;
protected int mCurrentCombo;
protected int mMaxCombo;
protected int mSceneWidth;
protected int mSceneHeight;
protected float mCurrentX;
protected float mCurrentY;
protected GameMode mGameMode;
protected ScoreInformation mScoreInformation;

/**
* Create a new GameInformation
Expand All @@ -33,11 +29,7 @@ public class GameInformation implements Parcelable {
* @param weapon weapon used for this game
*/
public GameInformation(long remainingTime, long spawningTime, Weapon weapon) {
mScore = 0;
mTargetKilled = 0;
mBulletFired = 0;
mCurrentCombo = 0;
mMaxCombo = 0;
mScoreInformation = new ScoreInformation();
mRemainingTime = remainingTime;
mSpawningTime = spawningTime;
mWeapon = weapon;
Expand All @@ -57,11 +49,7 @@ public int describeContents() {
}

public void readFromParcel(Parcel in) {
mScore = in.readInt();
mTargetKilled = in.readInt();
mBulletFired = in.readInt();
mCurrentCombo = in.readInt();
mMaxCombo = in.readInt();
mScoreInformation = in.readParcelable(ScoreInformation.class.getClassLoader());
mRemainingTime = in.readLong();
mSpawningTime = in.readLong();
mWeapon = in.readParcelable(Weapon.class.getClassLoader());
Expand All @@ -76,11 +64,7 @@ public void readFromParcel(Parcel in) {

@Override
public void writeToParcel(Parcel out, int i) {
out.writeInt(mScore);
out.writeInt(mTargetKilled);
out.writeInt(mBulletFired);
out.writeInt(mCurrentCombo);
out.writeInt(mMaxCombo);
out.writeParcelable(mScoreInformation, i);
out.writeLong(mRemainingTime);
out.writeLong(mSpawningTime);
out.writeParcelable(mWeapon, i);
Expand Down Expand Up @@ -195,7 +179,7 @@ public void removeTarget() {
public void targetKilled() {
mTargetableItems.remove(mCurrentTarget);
mCurrentTarget = null;
mTargetKilled++;
mScoreInformation.increaseNumberOfTargetsKilled();
}

/**
Expand All @@ -204,14 +188,14 @@ public void targetKilled() {
* @return number of frag
*/
public int getFragNumber() {
return mTargetKilled;
return mScoreInformation.getNumberOfTargetsKilled();
}

/**
* increase bullets fired number
*/
public void bulletFired() {
mBulletFired++;
mScoreInformation.increaseNumberOfBulletsFired();
}

/**
Expand All @@ -220,7 +204,7 @@ public void bulletFired() {
* @return current combo
*/
public int getCurrentCombo() {
return mCurrentCombo;
return mScoreInformation.getCurrentCombo();
}

/**
Expand All @@ -229,36 +213,30 @@ public int getCurrentCombo() {
* @return max combo number
*/
public int getMaxCombo() {
if (mCurrentCombo > mMaxCombo) mMaxCombo = mCurrentCombo;
return mMaxCombo;
return mScoreInformation.getMaxCombo();
}

/**
* increase combo if conditions are filled
*/
public void stackCombo() {
if (mTargetKilled > mCurrentCombo * mCurrentCombo) {
mCurrentCombo++;
}
mScoreInformation.increaseCurrentCombo();
}

/**
* reset current combo counter
*/
public void resetCombo() {
if (mCurrentCombo > mMaxCombo) mMaxCombo = mCurrentCombo;
mCurrentCombo = 0;
mScoreInformation.resetCurrentCombo();
}

/**
* increase score
*
* @param ammount score you want to add to the current one
* @param amount score you want to add to the current one
*/
public void increaseScore(int ammount) {
if (ammount > 0) {
mScore += ammount;
}
public void increaseScore(int amount) {
mScoreInformation.increaseScore(amount);
}

/**
Expand All @@ -267,15 +245,12 @@ public void increaseScore(int ammount) {
* @return current score
*/
public int getCurrentScore() {
return mScore;
return mScoreInformation.getScore();
}

public void setCurrentScore(int score) {
mScore = score;
}

public int getBulletFired() {
return mBulletFired;
return mScoreInformation.getmNumberOfBulletsFired();
}

public int getMaxTargetOnTheField() {
Expand All @@ -290,6 +265,10 @@ public int getCurrentTargetsNumber() {
return mTargetableItems.size();
}

public ScoreInformation getScoreInformation() {
return mScoreInformation;
}

public GameMode getGameMode() {
return mGameMode;
}
Expand Down Expand Up @@ -317,4 +296,4 @@ public void setGameMode(GameMode gameMode) {
mGameMode = gameMode;
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package fr.tvbarthel.games.chasewhisply.model;


import android.os.Parcel;
import android.os.Parcelable;

/**
* ScoreInformation stores :
* the player score
* the number of targets killed
* the number of bullets fired
* the current combo
* the max combo reached by the player
*/
public class ScoreInformation implements Parcelable {
private int mScore;
private int mNumberOfTargetsKilled;
private int mNumberOfBulletsFired;
private int mCurrentCombo;
private int mMaxCombo;

public ScoreInformation() {
mScore = 0;
mNumberOfBulletsFired = 0;
mNumberOfTargetsKilled = 0;
mCurrentCombo = 0;
mMaxCombo = 0;
}

public ScoreInformation(Parcel in) {
readFromParcel(in);
}

/**
* Increase the score by one.
*/
public void increaseScore() {
increaseScore(1);
}

/**
* Increase the score by {@code amount}.
*
* @param amount
*/
public void increaseScore(int amount) {
mScore += amount;
}

/**
* Increase the number of targets killed by one.
*/
public void increaseNumberOfTargetsKilled() {
mNumberOfTargetsKilled += 1;
}

/**
* Increase the number of bullets fired by one.
*/
public void increaseNumberOfBulletsFired() {
mNumberOfBulletsFired += 1;
}

/**
* If the number of targets killed is greater than
* the current Combo squared, increase the current combo by one.
*
* If the new current combo is higher than the max combo
* the max combo is set to the current combo.
*/
public void increaseCurrentCombo() {
if(mNumberOfTargetsKilled > mCurrentCombo * mCurrentCombo) {
mCurrentCombo += 1;
mMaxCombo = Math.max(mMaxCombo, mCurrentCombo);
}
}

/**
* Set the current combo to 0.
*/
public void resetCurrentCombo() {
mCurrentCombo = 0;
}

/*
Parcelable stuff
*/

@Override
public int describeContents() {
return 0;
}

@Override
public void writeToParcel(Parcel out, int flags) {
out.writeInt(mScore);
out.writeInt(mNumberOfBulletsFired);
out.writeInt(mNumberOfTargetsKilled);
out.writeInt(mCurrentCombo);
out.writeInt(mMaxCombo);
}

private void readFromParcel(Parcel in) {
mScore = in.readInt();
mNumberOfBulletsFired = in.readInt();
mNumberOfTargetsKilled = in.readInt();
mCurrentCombo = in.readInt();
mMaxCombo = in.readInt();
}

public static final Parcelable.Creator<ScoreInformation> CREATOR = new Parcelable.Creator<ScoreInformation>() {
public ScoreInformation createFromParcel(Parcel in) {
return new ScoreInformation(in);
}

public ScoreInformation[] newArray(int size) {
return new ScoreInformation[size];
}
};

/*
Getters & Setters
*/

public int getScore() {
return mScore;
}

public int getNumberOfTargetsKilled() {
return mNumberOfTargetsKilled;
}

public int getmNumberOfBulletsFired() {
return mNumberOfBulletsFired;
}

public int getCurrentCombo() {
return mCurrentCombo;
}

public int getMaxCombo() {
return mMaxCombo;
}

}

0 comments on commit 63eb650

Please sign in to comment.