this question has answer here:
i making game in java. want able check whether level has been visited. came this:
public class leveltracker { boolean depth1visited = false; boolean depth2visited = false; // .. boolean depth100visited = false; private boolean leveltracking() { if (dungeon.depth == 1) { depth1visited = true; } if (dungeon.depth == 2) { depth2visited = true; } // .. if (dungeon.depth == 100) { depth100visited = true; } } }
in situation, each depth must checked independently since level might accessed other level. this:
if (depth > deepestdepth) { deepestdepth = depth; }
won't work in situation. unless i'm wrong, possible. am, can tell, novice @ this.
what better way this? loop used in situation?
use arrays, can addressed index. can replace if
s , 100 separate variables.
boolean[] depthvisited = new boolean[100]; // default values: false
then can access array calculating index.
depthvisited[dungeon.depth - 1] = true; // 0-based index
no for
loop necessary.
Comments
Post a Comment