❔ Can someone help me with my snake game?
Hi everyone reading this.
I’m pretty new to C#, so please go easy on me.
I have a snake-game (wpf), and the next level should have some kind of obstacle. So I made this for the next level. See picture please.
My problem now is that the apples that spawn with the Random Class might land on top of my obstacles. Is there anyway to make sure that they do not?
The other picture is the code for apples being spawned.
Would really appreciate help!
9 Replies
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
$paste please
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
🙂
I hope i did it right. https://paste.mod.gg/obtyihfrvrmk/0
BlazeBin - obtyihfrvrmk
A tool for sharing your source code with the world!
This is pretty wild, ngl.
Is it meant to be free-form? Because Snake seems like a pretty solidly grid-based game. If you did that you wouldn't have to do this funky collision check you do with
VisualTreeHelper
which is presumably what you'd have to do to check the apple against the Snake
and Border
shapes before placing it.
If you had the entire board as a grid, like a 2D-Array of tiles or some such thing, you could make everything so much easier for yourself.
Unless it is meant to be free flowing in which case... well its WPF I guess, it's bound to be painful making games in it 😄yes
The game should not be tied to the controls, but in a separate class.
acting on it's own.
OK. Thanks for your comments!
This is supposed to be like this. This is an exercise I have to do. Do you see a way to do what i asked, with this code? You don't need to give me a direct answer how its done. But maybe you can give me a hint. Its driving me mad.! 🥲
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.