java - Trying to write a loop that goes through my array and increments health of each player by 100 -
print screen:
player13 character name: fourz, class name: ninja strength: 17, agility: 21, stamina: 17, intellect: 25, spirit: 20, health: 52, mana: 50
i need loop go through 16 different sets of player stats , give health bonus of 100. struggling writing correct loop.
public static void sortplayersbyhealth() { (int outer = 0; outer < playerobjectarray.length -1; outer ++) { (int inner = 0; inner < playerobjectarray.length - 1; inner ++ ) { int num1 = playerobjectarray[inner].gethealth(); //must + 1 know go next number , find > number. int num2 = playerobjectarray[inner+1].gethealth(); if(num1 > num2) { player player = playerobjectarray[inner]; playerobjectarray[inner] = playerobjectarray[inner+1]; playerobjectarray[inner+1] = player; }
this loop wrote loop through 16 player stats, sorting them lowest highest health score. changing syntax increment health 100 appreciated.
sorry if not making sense, new programming, , new stackoverflow.
public void bumphealth() { (player player : playerobjectarray) { player.health += 100; } }
assuming, of course, player object's health variable called 'health'.
Comments
Post a Comment