help with random class and tuples.
i am making a game for my class project and i have a problem. My goal is to randomly generate 12 coins in my level each time you play and so i made this code, only problem is that in only places the coins in the top corner of the screen instead of the actual game level.
This is not my first attempt at this and i've used other sources and different code to try and do this but they all, at best, leave me in the same situation with the coins in the corner.
9 Replies
the level if thats helpful
Use Random.Shared
(Random.Shared.Next(...))
You're loops look sus tho. Why are you drawing every coin for each i and for each j?
i dont know tbh, i just figured putting everything closer to each other like that would make it easier
would moving the last 'foreach' outside make it easier?
Both foreach shouldn't be inside the i j loops afaict
I don't know what the deal is with Take(12) either
i put everything in a function but when i run the function, it keeps running over and over, so to stop generating an infinite amount of whatever, i put a limit. i used this way in another oart of my code and it seemed to work fine
the 12 is just cuz i only want 12 coins/ locations
Sounds like you've got some bugs then
It looks weird that position list is a function arg
The crux of what you're asking is just to get a list of 12 random indexes, though? Just concentrate on that. It can be it's own function
Also please don't use
Tuple<int, int>
, use (int, int)
haha yeah i decided to not use tuple and instead just work with the rectangles already there. it may not be optimal but this current system does what i need
thank u for the help btw!! <3