Jump to content

The Hero of Time

Members
  • Posts

    11066
  • Joined

  • Last visited

  • Days Won

    9
  • Feedback

    100%

Everything posted by The Hero of Time

  1. So, to give you a quick run through, i have created a class Fighter, which represents a fighter with a combat style ENUM: COMBAT CLASS: FIGHTER Now we have a class barracks, the barracks is full of fighters. The ArrayList inside barracks that represents the barracks is: private ArrayList<Fighter> fighters = new ArrayList<>(); now the class Barracks has a few methods. CLASS: BARRACKS now if you have a basic understanding of the classes, the problem i have is with this method. The problem is that the fighters will not be removed from the barracks. They will all be called by a phrase, and the list with calledfighters will be correctly filled, but they just wont be removed from the barracks if there are 2 fighters with the same initial /** * Calls all fighters that have initials that are in the name. Example: name = war. All fighters with initials 'w','a', or 'r' will be called and removed from the barracks. * @param phrase The phrase with initials * @param combatStyle The combat style the fighter is specialized in */ public ArrayList<Fighter> callFighters(String phrase, Combat combatStyle) { //make the phrase fully uppercase phrase = phrase.toUpperCase(); //Used to check if we have enough fighters in our army ArrayList<Fighter> tempBarracks = new ArrayList<>(); //fighters to remove from the barracks after they have been called ArrayList<Fighter> toRemoveFightersFromBarracks = new ArrayList<>(); //list of fighters that are called from the barracks ArrayList<Fighter> calledFighters = new ArrayList<>(); //fill the temporary barracks with the contents real barracks, so that we dont have to modify the real barracks if we call fighters and dont have enough fighters tempBarracks.addAll(fighters); //Fill the arraylist with chars of the parameter name //war will be 'W','A','R' ArrayList<Character> nameInChars = new ArrayList<>(); for(char chr: phrase.toCharArray()) nameInChars.add(chr); //Call all fighters int i = 0; int removedFighters = 0; for(Fighter fgt: tempBarracks) { if (nameInChars.contains(fgt.getInitial()) && fgt.getCombatStyle().equals(combatStyle) && i < nameInChars.size()) { Fighter r = new Fighter(nameInChars.get(i), combatStyle); calledFighters.add(r); for (Fighter fghtr : tempBarracks) { if (fghtr.getInitial() == nameInChars.get(i) && fghtr.getCombatStyle().equals(combatStyle) && removedFighters == 0) { toRemoveFightersFromBarracks.add(fghtr); removedFighters++; } } removedFighters = 0; i++; } } //toRemoveFightersFromBarracks will now be Correctly filled with all the fighters from the given phrase for(Fighter fgt: toRemoveFightersFromBarracks) //HERE LIES THE PROBLEM I'M HAVING. { if(tempBarracks.contains(fgt)) { //Will also be FALSE if indexOfRm = -1 as described below. } int indexOfRm = tempBarracks.indexOf(fgt); //Will be -1 if we call 2 fighters with the same initials and combat style tempBarracks.remove(fgt); //Wont remove object fgt from tempBarracks, probably has something to do with the fact that the index of fgt in tempBarracks is -1 } So basically if there is a second fighter with the same initial, the object fgt from toRemoveFightersFromBarracks will not be removable from tempBarracks, the index of that fighter in tempbarracks is -1, and contains returns false, but it does contain a fighter with that exact initial and that exact combat style I've made a .gif to show it if(calledFighters.size() == phrase.length()) { //Finally: remove the fighters from the barracks! this.fighters.clear(); this.fighters.addAll(tempBarracks); return calledFighters; } else { System.out.println("We dont have enough fighters for this phrase"); return null; } } gif: EDIT: Images instead since this editor is annoying callFighters
  2. you're better off alching or botting mage in the fastest way to like 85+, itll make your kills so, so much faster, and youll make more profit
  3. im not sure if itll be in our lifetimes. it is interesting and cool, but very scary at the same time
  4. i kind of always liked the spacy stuff, but i can see how rs related things can look cool too
  5. PLEASE tell me this is real LOL
  6. doesn't hurt to have it though, i mean you never interact with it anyway
  7. rip, corrupted hdd. format it and youll be fine
  8. good thing my local pizza place is the best pizza place i've ever tasted, and i can walk there much , much, much better than dominos or new york or any others here in the area
×
×
  • Create New...