I'm new to java and trying my hand at making a game. Here is what I have so far in my "combat class." Right now, if this was displayed with:
Combat fight1 = new Combat("Homeless Man", "Rusty Fork", 100, 110, 30);
I would get the output:
Homeless Man hits you with a Rusty Fork, Dealing 0 damage!
You now have 0 HP left!
You hit Homeless Man With an attack using your null dealing 0 damage!
Homeless Man now has 100 HP left!
Is there any way that I can fix this to make it display the right values (random damage, health values, damage values, etc.)
I know that this is a lot of code (and work) to look through, so all help is greatly appreciated!
The code for the "Combat" class is below:
package Walking;
import java.util.Random;
import java.util.Scanner;
public class Combat {
//enemy
String enemyName;
String enemyItem;
int enemyHP;
int enemyMaxDam;
int enemyMinDam;
public int damageDelt;
//player
public int playerHP;
public int playerMaxDam;
public int playerMinDam;
public int damageTaken;
//player armor
int clothes = 1;
int tux = 0;
//player weapon
String playerWeapon;
int fists = 1;
int bloodySpoon = 0;
public Combat() {
if(clothes == 1) {
playerHP = 1000;
}else {
if(tux == 1) {
playerHP = 1100;
}
}
if(fists == 1) {
playerMaxDam = 75;
playerMinDam = 30;
}else {
if(bloodySpoon == 1) {
playerMaxDam = 100;
playerMinDam = 75;
}
}
}
public Combat(String _enemyName, String _enemyItem, int _enemyHP, int _enemyMaxDam, int _enemyMinDam) {
enemyName = _enemyName;
enemyItem = _enemyItem;
enemyHP = _enemyHP;
enemyMaxDam = _enemyMaxDam;
enemyMinDam = _enemyMinDam;
}
public int getDamageDelt() {
Random rand = new Random();
damageDelt = rand.nextInt(playerMaxDam = playerMinDam + 1) + playerMinDam;
return damageDelt;
}
public int getDamageTaken() {
Random rand = new Random();
damageTaken = rand.nextInt(enemyMaxDam - enemyMinDam + 1) + enemyMinDam;
return damageTaken;
}
public void displayCombat() {
Scanner in = new Scanner(System.in);
System.out.println("Will you:\n -Attack (1)\n -Consume Item (2) \n -Run (3)");
String userInput = in.nextLine();
if(userInput.equals("1")) {
System.out.println(enemyName + " hits you with a " + enemyItem + ", Dealing " + damageTaken + " damage!");
System.out.println("You now have " + (playerHP - damageDelt) + " HP left!");
System.out.println("You hit " + enemyName + " With an attack using your " + playerWeapon + " dealing " + damageDelt + " damage!");
System.out.println(enemyName + " now has " + (enemyHP - damageDelt) + " HP left!");
}else {
if(userInput.equals("3")) {
System.out.println("You managed to escape the fight with " + playerHP + " left!");
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire