Android Open Source - Apocalypse-Defense Gun






From Project

Back to project page Apocalypse-Defense.

License

The source code is released under:

MIT License

If you think the Android project Apocalypse-Defense listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.apocalypsedefense.core;
/**/*from   ww w  . jav a  2 s  .co  m*/
*/
public class Gun extends Weapon {
  /**
  */
  public int clipSize;
  /**
  */
  public int reloadRate;
  /**
  */
  public int currentAmmo;
  
  /**
   * @param reloadRate 
   * @param rate 
   * @param wType 
   * @param attackRange 
   * @param name 
   * @param damage 
   * @param clipSize 
  */
  public Gun(String wType, String name, int damage, int rate, int attackRange, int clipSize, int reloadRate) {
    super(wType,name,damage,rate,attackRange);
    this.clipSize = clipSize;
    this.reloadRate = reloadRate;
    this.currentAmmo = clipSize;
  }
  
  /**
   * @return int
  */
  @Override
  public int attack() {
    int ammoExpelled = 1/this.rate;
    this.currentAmmo -= ammoExpelled;
    if (this.currentAmmo < 0){ //Can't go below 0 bullets
      this.currentAmmo = 0;
      this.reloadGun(); //Reload gun
    }
    return this.damage*ammoExpelled;
  }
  /**
  */
  public void reloadGun() {
    //TODO Need to add reload rate:
    System.out.print("RELOADING!");
    this.currentAmmo += this.clipSize;
  }

}


/*
Python code:

class Gun(Weapon):
    def __init__(self, wType='Default Gun Type', name='Default Gun', damage=10, 
                 rate=1, attackRange=300, clipSize=50, reloadRate=1):
        Weapon.__init__(self, wType, name, damage, rate, attackRange)
        self.clipSize = clipSize
        self.reloadRate = reloadRate
        self.currentAmmo = clipSize

    def shoot(self):
        ammoExpelled = 1/self.rate
        self.currentAmmo -= ammoExpelled
        if self.currentAmmo < 0: #Can't go below 0 bullets
            self.currentAmmo = 0
            self.reloadGun() #Reload the gun
        return self.damage*ammoExpelled #Every shot hits

    def reloadGun(self):
        #NEED TO ADD RELOAD RATE
        print 'RELOADING!'
        self.currentAmmo = self.clipSize
*/




Java Source Code List

com.apocalypsedefense.app.AchievementsActivity.java
com.apocalypsedefense.app.ApocalypseDefenseActivity.java
com.apocalypsedefense.app.EndOfGameDialog.java
com.apocalypsedefense.app.ExitConfirmationDialog.java
com.apocalypsedefense.app.InGameActivity.java
com.apocalypsedefense.app.InstructionsDialog.java
com.apocalypsedefense.app.NewGameSettingsActivity.java
com.apocalypsedefense.app.OverwriteExistingGameDialog.java
com.apocalypsedefense.app.gameplay_visuals.AndroidLogAdapter.java
com.apocalypsedefense.app.gameplay_visuals.GameFacade.java
com.apocalypsedefense.app.gameplay_visuals.GameObject.java
com.apocalypsedefense.app.gameplay_visuals.GameSurfaceView.java
com.apocalypsedefense.app.gameplay_visuals.GameThread.java
com.apocalypsedefense.app.gameplay_visuals.OnGameEndListener.java
com.apocalypsedefense.app.gameplay_visuals.OnStatsChangedListener.java
com.apocalypsedefense.app.gameplay_visuals.Sprite.java
com.apocalypsedefense.core.ActorType.java
com.apocalypsedefense.core.Armor.java
com.apocalypsedefense.core.GameData.java
com.apocalypsedefense.core.GameState.java
com.apocalypsedefense.core.Game.java
com.apocalypsedefense.core.Gun.java
com.apocalypsedefense.core.LogAdapter.java
com.apocalypsedefense.core.MapElement.java
com.apocalypsedefense.core.Map.java
com.apocalypsedefense.core.Movement.java
com.apocalypsedefense.core.Person.java
com.apocalypsedefense.core.Point.java
com.apocalypsedefense.core.PrintLogAdapter.java
com.apocalypsedefense.core.Shared.java
com.apocalypsedefense.core.SurvivorManager.java
com.apocalypsedefense.core.Survivor.java
com.apocalypsedefense.core.Weapon.java
com.apocalypsedefense.core.ZombieManager.java
com.apocalypsedefense.core.Zombie.java
com.apocalypsedefense.core.testDriver.java