c# - How can I have xy coordinates in a grid that can't be used? -


how can have xy coordinates can't used? don't want xy (5,5) , (7,9) ever used. how can this?

x = random.next(0, 20); y = random.next(0, 20);  // if xy coordinate (5,5) or (7,9), keep trying above obtain different xy value 

when xy coordinate created how can have coordinates not usable?

just loop on creation until condition satisfied:

var forbidden = new list<tuple<int, int>>(); forbidden.add(new tuple<int, int>(5, 5)); forbidden.add(new tuple<int, int>(7, 9)); while(true) {     x = random.next(0, 20);     y = random.next(0, 20);     if(forbidden.all(t => x != t.item1 || y != t.item2)) break; } 

this way, loop terminate if have coordinates "allowed", i.e. reach break statement.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -