Skip to content

Commit

Permalink
Added Activity#indexOf
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRealEmissions committed Mar 20, 2024
1 parent fee67ee commit 6ad7681
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions core/src/uk/ac/york/student/game/activities/Activity.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,22 @@ public enum Activity {
}
return null;
}

/**
* Returns the index of the first occurrence of the specified {@link PlayerMetrics.MetricType} in {@link Activity#effects}.
* This method iterates over {@link Activity#effects}.
* If an effect with the specified {@link PlayerMetrics.MetricType} is found, the index of the effect in {@link Activity#effects} is returned.
* If no effect with the specified {@link PlayerMetrics.MetricType} is found, -1 is returned.
*
* @param metricType the {@link PlayerMetrics.MetricType} to find in {@link Activity#effects}
* @return the index of the first occurrence of the specified {@link PlayerMetrics.MetricType} in {@link Activity#effects}, or -1 if the {@link PlayerMetrics.MetricType} is not found
*/
public int indexOf(PlayerMetrics.MetricType metricType) {
for (int i = 0; i < effects.size(); i++) {
if (effects.get(i).getLeft() == metricType) {
return i;
}
}
return -1;
}
}

0 comments on commit 6ad7681

Please sign in to comment.