Skip to content

Commit

Permalink
Merge pull request #120 from R1ndT/critical-hits
Browse files Browse the repository at this point in the history
Implemented critical hits and weapon specific crit chance system
  • Loading branch information
hhaslam11 authored Jan 20, 2021
2 parents 5e0343d + e1165d2 commit fc3b67d
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/com/hotmail/kalebmarc/textfighter/main/Enemy.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private void die() {
com.hotmail.kalebmarc.textfighter.player.Xp.setBattleXp(0, false);

//Prompt enemy death
Ui.popup("You have defeated an enemy! You've found " + tempCoin + " coins, and " + xp + "Xp!", "You've defeated an enemy!", JOptionPane.PLAIN_MESSAGE);
Ui.popup("You have defeated an enemy, dealing " + Weapon.get().getDamageDealt() + " damage! You've found " + tempCoin + " coins, and " + xp + "Xp!", "You've defeated an enemy!", JOptionPane.PLAIN_MESSAGE);

//Rewards
testFoundPipe();
Expand Down
43 changes: 40 additions & 3 deletions src/com/hotmail/kalebmarc/textfighter/main/Weapon.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ public class Weapon {
public boolean owns;
private int damageMin;
private int damageMax;
private int damageDealt;
private double chanceOfMissing;
private double critChanceMultiplier;
private int critDamMultiplierMin;
private int critDamMultiplierMax;
private String name;
private boolean buyable;
//Ammo
Expand All @@ -33,7 +37,7 @@ public class Weapon {
private int ammoIncludedWithPurchase;

public Weapon(String name, int ammoUsed, int ammoIncludedWithPurchase, boolean buyable, int price, //For guns
int ammoPrice, int level, double chanceOfMissing, boolean firstInit, boolean changeDif) {
int ammoPrice, int level, double chanceOfMissing, double critChanceMultiplier, int critDamMultiplierMin, int critDamMultiplierMax, boolean firstInit, boolean changeDif) {

this.name = name;
this.ammoUsed = ammoUsed;
Expand All @@ -43,6 +47,9 @@ public Weapon(String name, int ammoUsed, int ammoIncludedWithPurchase, boolean b
this.ammoPrice = ammoPrice;
this.level = level;
this.chanceOfMissing = chanceOfMissing;
this.critChanceMultiplier = critChanceMultiplier;
this.critDamMultiplierMin = critDamMultiplierMin;
this.critDamMultiplierMax = critDamMultiplierMax;
this.melee = false;

if (!changeDif) {
Expand Down Expand Up @@ -181,8 +188,11 @@ public int getAmmo() {
return this.ammo;
}

public int getDamageDealt() {
return this.damageDealt;
}

public void dealDam() {
int damageDealt = 0;

if (this.melee) {
/*
Expand All @@ -200,12 +210,15 @@ public void dealDam() {
if (Random.RInt(100) > this.chanceOfMissing) {
damageDealt += BULLET_DAMAGE;
Stats.bulletsThatHit++;

}

//Results
setAmmo(-1, true);
Stats.bulletsFired += 1;
}
//Run the logic for critical hit
criticalHit();

} else {
noAmmo();
Expand All @@ -230,7 +243,29 @@ public void dealDam() {
if (Enemy.get().getHealth() <= Enemy.get().getHealthMax() / 3){
Enemy.get().useFirstAidKit();
}
}
}
damageDealt = 0;
}

private void criticalHit() {

if (wasCriticalHit()) {
int critMultiplier = Random.RInt(this.critDamMultiplierMin, this.critDamMultiplierMax);

damageDealt *= critMultiplier;

Ui.cls();
Ui.println("----------------------------------------------------");
Ui.println("Critical Hit!");
Ui.println("You dealt " + critMultiplier + "x normal damage.");
Ui.println("----------------------------------------------------");
Ui.pause();

}
}

private boolean wasCriticalHit() {
return Random.RInt((int) (100 / this.critChanceMultiplier)) == 1;
}

public void viewAbout() {
Expand All @@ -248,6 +283,8 @@ public void viewAbout() {
Ui.println("Chance of missing: " + this.chanceOfMissing + "%");
Ui.println("Ammo Used: " + this.ammoUsed);
Ui.println("Damage: " + this.getDamage());
Ui.println("Chance of critical hit: " + this.critChanceMultiplier + "%");
Ui.println("Critical hit damage multiplier: " + this.critDamMultiplierMin + "-" + this.critDamMultiplierMax + "x");
for (int i = 0; i < BORDER_LENGTH; i++) Ui.print("-");//Make line
Ui.pause();
Ui.cls();
Expand Down
42 changes: 26 additions & 16 deletions src/com/hotmail/kalebmarc/textfighter/player/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,18 +153,23 @@ private static void setConstants(String dif, boolean firstInit, boolean changeDi
Game.evilUnicorn = new Enemy("Evil Unicorn", 35, 30, 40, 5, 15, 20, firstInit, changeDif);
Game.ogre = new Enemy("Ogre", 90, 20, 50, 10, 30, 50, firstInit, changeDif);

//Weapons
//Gun: (name, ammoUsed, ammoIncludedWithPurchase, buyable, price, ammoPrice, level, chanceOfMissing, firstInit, changeDif)
//Melee: (name, startingWeapon, buyable, price, level, damageMin, damageMax, firstInit)
/*Weapons
* Gun: (name, ammoUsed, ammoIncludedWithPurchase, buyable, price, ammoPrice, level, chanceOfMissing, critChanceMultiplier,
* critDamMultiplierMin, critDamMultiplierMax firstInit, changeDif)
* Melee: (name, startingWeapon, buyable, price, level, damageMin, damageMax, firstInit, changeDif)
*/

//Melee:
Game.fists = new Weapon("Fists", true, false, 0, 0, 5, 10, firstInit, changeDif);
Game.baseballBat = new Weapon("Baseball Bat", false, true, 120, 1, 10, 15, firstInit, changeDif);
Game.knife = new Weapon("Knife", false, true, 125, 2, 10, 20, firstInit, changeDif);
Game.pipe = new Weapon("Pipe", false, false, 0, 0, 5, 20, firstInit, changeDif);
Game.pistol = new Weapon("Pistol", 1, 18, true, 250, 1, 4, 15, firstInit, changeDif);
Game.smg = new Weapon("Smg", 10, 75, true, 700, 1, 10, 75, firstInit, changeDif);
Game.shotgun = new Weapon("Shotgun", 1, 12, true, 375, 2, 9, 60, firstInit, changeDif);
Game.rifle = new Weapon("Rifle", 1, 18, true, 275, 1, 5, 10, firstInit, changeDif);
Game.sniper = new Weapon("Sniper", 1, 10, true, 700, 2, 7, 0, firstInit, changeDif);
//Guns:
Game.pistol = new Weapon("Pistol", 1, 18, true, 250, 1, 4, 15, 1.5, 3, 4, firstInit, changeDif);
Game.smg = new Weapon("Smg", 10, 75, true, 700, 1, 10, 75, 2.5, 4, 6, firstInit, changeDif);
Game.shotgun = new Weapon("Shotgun", 1, 12, true, 375, 2, 9, 60, 2, 5, 7, firstInit, changeDif);
Game.rifle = new Weapon("Rifle", 1, 18, true, 275, 1, 5, 10, 1.25, 6, 7, firstInit, changeDif);
Game.sniper = new Weapon("Sniper", 1, 10, true, 700, 2, 7, 0, 1, 7, 10, firstInit, changeDif);

//Price
Power.price = 25;
Expand Down Expand Up @@ -197,18 +202,23 @@ private static void setConstants(String dif, boolean firstInit, boolean changeDi
Game.evilUnicorn = new Enemy("Evil Unicorn", 35, 20, 40, 5, 15, 20, firstInit, changeDif);
Game.ogre = new Enemy("Ogre", 100, 20, 50, 10, 30, 50, firstInit, changeDif);

//Weapons
//Gun: (name, ammoUsed, ammoIncludedWithPurchase, buyable, price, ammoPrice, level, chanceOfMissing, firstInit, changeDif)
//Melee: (name, startingWeapon, buyable, price, level, damageMin, damageMax, firstInit, changeDif)
/*Weapons
* Gun: (name, ammoUsed, ammoIncludedWithPurchase, buyable, price, ammoPrice, level, chanceOfMissing, critChanceMultiplier,
* critDamMultiplierMin, critDamMultiplierMax firstInit, changeDif)
* Melee: (name, startingWeapon, buyable, price, level, damageMin, damageMax, firstInit, changeDif)
*/

//Melee:
Game.fists = new Weapon("Fists", true, false, 0, 0, 5, 10, firstInit, changeDif);
Game.baseballBat = new Weapon("Baseball Bat", false, true, 170, 1, 10, 15, firstInit, changeDif);
Game.knife = new Weapon("Knife", false, true, 175, 2, 10, 20, firstInit, changeDif);
Game.pipe = new Weapon("Pipe", false, false, 0, 0, 5, 20, firstInit, changeDif);
Game.pistol = new Weapon("Pistol", 1, 18, true, 275, 1, 4, 15, firstInit, changeDif);
Game.smg = new Weapon("Smg", 10, 75, true, 800, 1, 10, 75, firstInit, changeDif);
Game.shotgun = new Weapon("Shotgun", 1, 12, true, 415, 2, 9, 60, firstInit, changeDif);
Game.rifle = new Weapon("Rifle", 1, 18, true, 300, 1, 5, 10, firstInit, changeDif);
Game.sniper = new Weapon("Sniper", 1, 10, true, 750, 2, 7, 0, firstInit, changeDif);
//Guns:
Game.pistol = new Weapon("Pistol", 1, 18, true, 275, 1, 4, 15, 1.25, 2, 3, firstInit, changeDif);
Game.smg = new Weapon("Smg", 10, 75, true, 800, 1, 10, 75, 1.75, 3, 5, firstInit, changeDif);
Game.shotgun = new Weapon("Shotgun", 1, 12, true, 415, 2, 9, 60, 1.5, 4, 6, firstInit, changeDif);
Game.rifle = new Weapon("Rifle", 1, 18, true, 300, 1, 5, 10, 1, 5, 6, firstInit, changeDif);
Game.sniper = new Weapon("Sniper", 1, 10, true, 750, 2, 7, 0, .75, 7, 9, firstInit, changeDif);

//PRICE
Power.price = 75;
Expand Down

0 comments on commit fc3b67d

Please sign in to comment.