lundi 24 avril 2017

Constructor argument not pulling values from List?

So I'm having issues with an instance of my Class not pulling the values from a list.

When I call my Battle constructor, the starter's stats are displayed properly. However, when the wild Pokemon's stats are displayed, they all show a value of 0. I recently revitalized this code to rid it of conflicting static variables. Since I'm new and IntelliJ doesn't seem to display any issues, I can't figure out where I went wrong.

As I'm not sure where the problem lies, I'll post more than necessary. I apologize for the walls of text.

To construct the Pokemon:

public class Pokemon {

public static int starterHealth;
String name;
public int health;
public int attack;
public int speed;
public boolean status;


public Pokemon(String name, int health, int attack, int speed, boolean status) {

    this.name = name;
    this.health = health;
    this.attack = attack;
    this.speed = speed;
    this.status = status;
}}

To construct the starter:

class Starter {

static String newStarter;
static int maxStarterHealth;
static int starterAttack;
static int starterSpeed;
static int starterLevel = 1;


Starter(String newStarter, int starterHealth, int starterAttack, int starterSpeed) {
    Starter.newStarter = newStarter;
    Starter.maxStarterHealth = starterHealth;
    Starter.starterAttack = starterAttack;
    Starter.starterSpeed = starterSpeed;
}

Creating the wild Pokemon in a List with random stats given a min and max value:

class WildPokemon {


private int randomHealth(int min, int max) {
    int range = (max - min) + 1;
    return (int)(Math.random() * range) + min;
}
private int randomAttack(int min, int max) {
    int range = (max - min) + 1;
    return (int)(Math.random() * range) + min;
}
private int randomSpeed(int min, int max) {
    int range = (max - min) + 1;
    return (int)(Math.random() * range) + min;
}


public Random rand = new Random();
public List<Pokemon> pokemonList;

WildPokemon(){
    pokemonList = new ArrayList();

    Pokemon rattata = new Pokemon("Rattata",randomHealth(15,20),randomAttack(2,5),randomSpeed(3,6), true);
    pokemonList.add(rattata);
    Pokemon pidgey = new Pokemon("Pidgey",randomHealth(12,17),randomAttack(3,4),randomSpeed(2,5), true);
    pokemonList.add(pidgey);
    Pokemon caterpie = new Pokemon("Caterpie",randomHealth(20,23),randomAttack(3,4),randomSpeed(2,5), true);
    pokemonList.add(caterpie);}

Pokemon getRandomPokemon() {
    int n = rand.nextInt(pokemonList.size());
    return pokemonList.get(n);
}

The battle constructor to have the starter battle a random wild Pokemon from the list:

public class Battle {

public int health;
public int speed;
public int attack;
public boolean status;
private static int randomDamage;
private static int getExp;
private static int totalExp;
public int starterHealth = Starter.maxStarterHealth;


Battle(Starter starter, Pokemon wildPokemon) {
    do {
        //Show stats of both Pokemon before the battle
        JOptionPane.showMessageDialog(null, "Your " + Starter.newStarter + "'s (Lvl. " + Starter.starterLevel + ") stats are: \n Health: "
                + Starter.maxStarterHealth + "\n Strength: " + Starter.starterAttack + "\n Speed: " + Starter.starterSpeed);

        showMessageDialog(null, wildPokemon.name + "'s stats are: \n Health: "
                + health + "\n Attack: " + attack + "\n Speed: " + speed);
        exp(health, attack, speed);

        if (Starter.starterSpeed > speed) {
            showMessageDialog(null, Starter.newStarter + " begins the fight against " + wildPokemon.name);
        } else if (speed > Starter.starterSpeed) {
            showMessageDialog(null, wildPokemon.name + " begins the fight against " + Starter.newStarter);
        }

And to call it all:

public class PokemonTester {


public static void main(String[] args) {
    Starter.selectStarter();
    Starter.createNewStarter(newStarter);
    Starter starter = new Starter(newStarter, maxStarterHealth, starterAttack, starterSpeed);

    WildPokemon wildPokemon = new WildPokemon();
    new Battle(starter, wildPokemon.getRandomPokemon());




Aucun commentaire:

Enregistrer un commentaire