comments
This commit is contained in:
@@ -7,7 +7,10 @@ import com.bayviewglen.zork.Entities.Player;
|
||||
import com.bayviewglen.zork.Entities.Enemies.Enemy;
|
||||
import com.bayviewglen.zork.Items.Item;
|
||||
import com.bayviewglen.zork.Items.Shavingcream;
|
||||
|
||||
/*
|
||||
* This combat class stores information, and handles turns for both the player and enemy that are in combat.
|
||||
* Whenever combat takes place, this class is instantiated and stored in the Game class.
|
||||
*/
|
||||
public class Combat {
|
||||
private Player player;
|
||||
private Enemy enemy;
|
||||
@@ -17,7 +20,12 @@ public class Combat {
|
||||
this.player = player;
|
||||
this.enemy = enemy;
|
||||
}
|
||||
// return new health of enemy
|
||||
/*
|
||||
* Handles the attack made by a player. Called whenever a player uses the command word "attack"
|
||||
* This method takes the item from the command as a string, and turns it into an object so that it can find info about the item.
|
||||
* When the player attacks, there is a 10% chance of missing, 10% chance of a critical hit, and an 80% chance of a normal hit.
|
||||
* Returns the new health of the enemy.
|
||||
*/
|
||||
public double playerAttack(String item) {
|
||||
Class<?> clazz;
|
||||
Item object;
|
||||
@@ -27,6 +35,7 @@ public class Combat {
|
||||
object = (Item) ctor.newInstance();
|
||||
|
||||
double rand = Math.random();
|
||||
// Special case when weapon is shaving cream, blind enemy
|
||||
if(object.equals(new Shavingcream())) {
|
||||
System.out.println("You blinded " + enemy.getName());
|
||||
player.removeFromInventory(new Shavingcream());
|
||||
@@ -44,6 +53,7 @@ public class Combat {
|
||||
}
|
||||
else {
|
||||
enemy.setHealth(enemy.getHealth()-object.getDamage());
|
||||
// Ensure health is not negative
|
||||
if(enemy.getHealth() < 0)
|
||||
enemy.setHealth(0);
|
||||
System.out.println("You did " + object.getDamage() + " damage! " + enemy.getName() + " is now at " + enemy.getHealth() + "% health.");
|
||||
@@ -55,9 +65,14 @@ public class Combat {
|
||||
turn = 1;
|
||||
return enemy.getHealth();
|
||||
}
|
||||
|
||||
/*
|
||||
* Much like the playerAttack() method, this method handles attacks for the enemy.
|
||||
* Same attack probabilities as player.
|
||||
* Returns new health of the player.
|
||||
*/
|
||||
public double enemyAttack() {
|
||||
double rand = Math.random();
|
||||
// If the enemy is blind, there is a 40% chance of the enemy beocoming unblinded.
|
||||
if(enemy.getBlinded()) {
|
||||
if(rand <0.4) {
|
||||
System.out.println(enemy.getName() + " is no longer blinded!");
|
||||
@@ -70,14 +85,17 @@ public class Combat {
|
||||
System.out.println(enemy.getName() + " missed!");
|
||||
}else if(rand < 0.20) {
|
||||
player.setHealth(player.getHealth()-enemy.getDamage()*1.5);
|
||||
// ensure health does not drop below 0
|
||||
if(player.getHealth() < 0)
|
||||
player.setHealth(0);
|
||||
System.out.println(enemy.getName() + " hit you with a critical hit, doing " + enemy.getDamage()*1.5 + " damage! Your health is now " + player.getHealth() + "%");
|
||||
// Set the player's bleeding status to true, when the enemy makes a critical hit
|
||||
System.out.println("You are now bleeding.");
|
||||
player.setBleeding(true);
|
||||
}
|
||||
else {
|
||||
player.setHealth(player.getHealth()-enemy.getDamage());
|
||||
// ensure health does not drop below 0
|
||||
if(player.getHealth() < 0)
|
||||
player.setHealth(0);
|
||||
System.out.println(enemy.getName() + " did " + enemy.getDamage() + " damage to you! Your health is now " + player.getHealth() + "%");
|
||||
@@ -86,6 +104,9 @@ public class Combat {
|
||||
return player.getHealth();
|
||||
}
|
||||
|
||||
/*
|
||||
* Getters and setters for this class.
|
||||
*/
|
||||
public int getTurn() {
|
||||
return this.turn;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user