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.
No description
No description
9 Replies
BricksAreTasty
BricksAreTastyOP11mo ago
the level if thats helpful
No description
phaseshift
phaseshift11mo ago
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?
BricksAreTasty
BricksAreTastyOP11mo ago
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?
phaseshift
phaseshift11mo ago
Both foreach shouldn't be inside the i j loops afaict I don't know what the deal is with Take(12) either
BricksAreTasty
BricksAreTastyOP11mo ago
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
phaseshift
phaseshift11mo ago
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
Thinker
Thinker11mo ago
Also please don't use Tuple<int, int>, use (int, int)
BricksAreTasty
BricksAreTastyOP11mo ago
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
No description
No description
BricksAreTasty
BricksAreTastyOP11mo ago
thank u for the help btw!! <3
Want results from more Discord servers?
Add your server