So, I'm working on creating a sort of role playing game. First off, throughout this post I will put little marks to correspond to the code I'm talking about. Down below will be the code organized by the order I reference it in here. To hold all of the enemies I have programmed into the game, I created an array titled enemyList. This holds 100 enemies^1. The first thing that I have my program set to do is call a method titled createAllEnemies()^1 that will first create enemies and then assign them to different places in the array^1. If you're wondering about the creation thing on the enemies, that is the method in the enemy class I created to take variables passed to it and assign it to different variables in the enemy class^2. In any event, when I try to call an enemy for battle^3 it does not in fact give me the enemy I desired but instead gives me the enemy that was last put into the array. I am not getting any errors at all, just the wrong results.
1: Main class(edited for relevance)
public class Main { static Enemy[] enemyList = new Enemy[100]; public static void main(String[] args) { createAllEnemies(); } private void createAllEnemies() { Enemy friend = new Enemy(); friend.creation("your friend", "Slash", "Stab", "", 100, 10, 20, 0, 100, 1, 2, 100, 10); enemyList[1] = friend; } }
2: Enemy class(edited for relevance. Left out an unnecessary method)
public class Enemy { static String name; static String attackOneName; static String attackTwoName; static String attackThreeName; static int health; static int attackOneDamage; static int attackTwoDamage; static int attackThreeDamage; static int experienceGiven; static int level; static int numberOfAttacks; static int maxHealth; static int speed; public static void creation(String a, String b, String c, String d, int e, int f, int g, int h, int i, int j, int k, int l, int m) { name = a; attackOneName = b; attackTwoName = c; attackThreeName = d; health = e; attackOneDamage = f; attackTwoDamage = g; attackThreeDamage = h; experienceGiven = i; level = j; numberOfAttacks = k; maxHealth = l; speed = m; } }
3:Example of creating a new battle and passing it an enemy
Battle battle = new Battle(); battle.main(Main.enemyList[3]);
Does anyone have any idea about what could be going wrong here? Any and all help is appreciated.