❔ 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
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Buddy
Buddy2y ago
$paste please
MODiX
MODiX2y ago
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!
Buddy
Buddy2y ago
🙂
someoneelse6077
BlazeBin - obtyihfrvrmk
A tool for sharing your source code with the world!
hiyosilver
hiyosilver2y ago
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 😄
Buddy
Buddy2y ago
yes The game should not be tied to the controls, but in a separate class. acting on it's own.
someoneelse6077
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.! 🥲
Accord
Accord2y ago
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.
Want results from more Discord servers?
Add your server
More Posts
✅ ConsoleApp - run the .exe by cmd and catch given parametersWell, as a little task I'm trying to code a ConsoleApp that should base64 encrypt an input string ~~❔ Bad IL Format Exception when porting .NET Framework 4.8 Project to .NET Core 6.0Hi, I've currently got the glorious task to port a .NET Framework 4.8 project to .NET Core 6.0. So f❔ "Cannot assign requested address [::1]:27017" when connecting to MongoDB on Docker.I have a Docker Compose file with containers - `backend`: ASP.NET Core web API - `mongo`: MongoDB wh❔ External Login Callback (Facebook works, Google doesn't)This is copied from a youtube tutorial and I've been trying to step through and figure out the probl❔ Need someone who is an expert at rating resumes, would really appreciate itMy resume https://cdn.discordapp.com/attachments/684475244664193242/1065827594806763580/Yehor-Belenk❔ Handling different version changes for external standard.Hey! I'm developing tools for a community to support OpenDRIVE standard. The name of the standard do❔ IMAP vs POP3 for getting attachments from an emailI'm building a console app in C# using MailKit to find and save all of the attachments in my outlook❔ WPF MVVM ModelViews and ViewsI have recently learned that ModelView can't have UI elements in it (bad practice). Hence, couple of❔ RatelimitHello, i am currently trying to program a discord bot. Ive created a method to track how many player❔ WPF export binding into resourcesHi! How can I define a binding with the ability to use intellisense ```xml <UserControl.Resource