Programming a Snake Game in C# - Full Guide

  Рет қаралды 164,164

OttoBotCode

OttoBotCode

Күн бұрын

Пікірлер: 356
@OttoBotCode
@OttoBotCode 10 ай бұрын
*Source code* If you don't want to write the code yourself, it's available here for 3$ (and free for Patreon supporters): www.patreon.com/OttoBotCode/shop/78661 Your support would be a massive help for me and my channel! 😊
@andjelaa23
@andjelaa23 9 ай бұрын
private readonly Image[,] in mainwindow.xaml is not working on my project. It says that the type or namespace Image could not be found
@hamnaic
@hamnaic 8 ай бұрын
I have a snake game project, but my language is C++. I am just a first-semester student, and I don't know much about C++. 😢 Can you create a video, similar to how you do in C#, or guide me on how to convert this code into C++? I have only 10 days left for project submission, and my project is still pending.
@jamesross3939
@jamesross3939 8 ай бұрын
@@hamnaic good luck ... people are not here to do your homework.
@josephedison6366
@josephedison6366 2 ай бұрын
​@@jamesross3939Real
@BigWill076
@BigWill076 7 ай бұрын
I've been staring at this without doing it for so long, but today's the day! Thanks for making it - teachers like you make starting the journey for people who want to do this sort of thing so much better.
@xucxichuc325
@xucxichuc325 Жыл бұрын
I'm not done watching the tutorial yet! But I'm really appreciated it, that you've invested so much time and effort into making these Tutorial. Thank you so much for that! You're a real hero
@OttoBotCode
@OttoBotCode Жыл бұрын
Thank you for the kind comment! ☺
@robertlysebo
@robertlysebo Жыл бұрын
I followed this guide as an intro to WPF during my studies. Tempo was great, explainations were great. Overall a pretty fun video!
@OttoBotCode
@OttoBotCode Жыл бұрын
Great to hear, thank you!
@RonRoostan
@RonRoostan Жыл бұрын
Hi Otto, I would like to say this tutorial is absolutely the best ever. Thanks and well done! I have modified my version to include a pause/resume feature and currently playing on a 32 x 32 grid. The longest snake I have to date is 176 cells. This took several minutes to construct but with the pause feature I was able to stop for a tea break halfway through. :)
@OttoBotCode
@OttoBotCode Жыл бұрын
You've made my day 🤩 Thanks for your comment and well done on the pause/resume feature!
@M-G112
@M-G112 Жыл бұрын
Would you be willing to share pause implementation?
@RonRoostan
@RonRoostan Жыл бұрын
Hi @@M-G112 Sorry I couldn't respond sooner. Maybe you have found a way to implement pause/resume in the meantime. But my approach was to introduce a new enum to track game mode (distinct from GameState): public enum GameMode { NotStarted, Started, Paused, Resuming, Over } The code looks for the space bar key press to enter 'Paused' mode if (gameState.Mode == GameMode.Started && e.Key == Key.Space) { mediaPlayer.Open(new Uri("Assets/intermission.wav", UriKind.Relative)); mediaPlayer.Play(); gameState.Mode = GameMode.Paused; return; } And another press of the space bar will enter 'Resuming' mode briefly before returning to 'Started' where the game play will continue from where it was interrupted. if (gameState.Mode == GameMode.Paused && e.Key == Key.Space) { gameState.Mode = GameMode.Resuming; return; } There are other code changes too but hopefully you get the idea. You can see them all in this github repo: github.com/rroostan/Snake/
@M-G112
@M-G112 Жыл бұрын
@@RonRoostan thank you for the reply, I allready implemented the pause but it is nice to see how you went about it.
@VitorBRYT
@VitorBRYT 5 ай бұрын
My first C# project! Thanks @OttoBotCode!
@lisalobo6389
@lisalobo6389 Жыл бұрын
Just finished the tutorial today. Thank you so much for explaining each step and for making this video. It helps immensely in seeing what I still need to revise in my own understanding of the language and building confidence in seeing the bits and pieces coming together. I am a huge fan!! Thanks a lot and I will be going through the other tuts on your channel as well.
@OttoBotCode
@OttoBotCode Жыл бұрын
I'm so glad to hear that! Thanks for your comment 😊
@vladoss4643
@vladoss4643 8 ай бұрын
Man!! Thank you a lot! My first fream was write a game using C# and today I made it!!) I spend 4,5 hours watching you, but I did it!! Thanks a lot. I have then looked your videolist. And have seen, that you made my second dream. Write the chess!!! AAAAAA!! I am so happy right now! I will thank a world for your existance!) Good luck in your life and etc.)) Thanks a lot again
@OttoBotCode
@OttoBotCode 8 ай бұрын
Thank you so much! Glad you enjoy the videos 😊
@darefishman
@darefishman Жыл бұрын
Thats a nice Tutorial! One Tip: you can double a row of text by using ctrl+D. This speeds up code like: public readonly static Direction Left = new Direction(0, -1); public readonly static Direction Right = new Direction(0, 1); public readonly static Direction Up = new Direction(1, 0); public readonly static Direction Down = new Direction(-1, 0);
@OttoBotCode
@OttoBotCode Жыл бұрын
Thanks for the comment and the tip! 😊
@jellycoding
@jellycoding 2 жыл бұрын
Now you code in a much better speed. I only had to pause a few times. The flow is much better when I code along. Great video...thanks.
@OttoBotCode
@OttoBotCode 2 жыл бұрын
Super! Thank you for that comment 🤩
@ifif6158
@ifif6158 Жыл бұрын
Dear OttoBotCode, Thank you so much for the video. You are explaining very well and the temp is good. I am still newbie in programming, but you are explaining in very understandable and helpful way. Before I started with the learning to code in c#, friend of mind recommended me to start to work under some projects following a step by step the professionalist. I am very glad that I found that your video. Thank you again for doing all this hard work. I followed all of your steps and I (thought I did the codes the same like you). Of course it is not the same because I have an issue for solving. Everything at the game goes at the way you did ( the colors, the snake, the food, the dead body snake, the counter from 3 to 1, the welcome text) except the important thing - the game it is not working prorerly(after the back counting the snake just dying and the game is restarting). It is not giving me any opportunity to move it. That was even when I wrote the codes with you. You showed that your game is working (I think may be from the 20min in the video) but mine did not moved at all. I reviewed and compared mine and your code tripple and everything seems the same as your. Of course I am sure I have missed someting😢. (By the way the 3 watching of the full video helped me to understand a lot of things). I decided to write you an comment, because I didn't find similar issue at the comments I read. The other think that I wanted to ask is - what I have to do to send the game to my friend to try it out? I tried, but on my computer is opening just on visual studio. Is it possible to set a instalation file, because I did not found it at the saved folder? I will be very glad if I receive your back comment. Thank you again for all your hard work under this project and thank you for sharing and helping people with it. Wish you many luck.
@OttoBotCode
@OttoBotCode Жыл бұрын
Thanks for the kind words! I cannot figure out what the problem is without seeing your code. If you are interested, you can send me your entire project to ottobotcodehelp@gmail.com (either as a github link or a zip). Then I'll take a look and see what I can find. When your game works, I can show you how to send it to a friend 😉
@TeamTornado168
@TeamTornado168 6 ай бұрын
لدي نفس المشكلة هل توصلتي الي حل؟
@deanRSA1
@deanRSA1 11 ай бұрын
Just finished the project. Thanks for the tutorial, this was also a cool introduction to WPF.
@OttoBotCode
@OttoBotCode 11 ай бұрын
Awesome! Thanks for your comment 😊
@katharxia7118
@katharxia7118 Жыл бұрын
really good tutorial! helped me with my college project!!
@justtohide
@justtohide 9 ай бұрын
thank youu for this a great application. i made a few changes like, different types of obstacles, foods, health bar, game duration, pause/stop menu and notification bar. + snake can move from outside Movement: Use keys A, W, S, D for movement. Also, consider arrow keys (arrays) and the number pad if available. Special Movements: X Movement: Q: Move above-left. E: Move above-right. Z: Move below-left. C: Move below-right. Scoring: Animals: Bird: 1 point per second. Rabbit: 3 points per 3 seconds. Frog: 5 points per 5 seconds. Total hearts: 3. Wood obstacles deduct 1 heart, metal obstacles deduct 2 hearts. Game duration: 60 seconds. Mystery Box and Chances: If total second is less than 30 seconds: Either +10 seconds or -5 seconds. Else total second is greater than 30: 1. Increase total obstacles. 2. Decrease total obstacles. 3. Additional Hearth Notification Bar: Located above the game arena. Displays important information. Pause/Resume: Open/close the resume menu by clicking the Space key.
@OttoBotCode
@OttoBotCode 9 ай бұрын
I'm glad you enjoyed the tutorial. Well done on all the extra features, it's sounds like a really fun Snake game! 😁
@justtohide
@justtohide 9 ай бұрын
@@OttoBotCode yeah it's. your role is undeniable
@GandohLakika-c7u
@GandohLakika-c7u Ай бұрын
great video otto!! i havent watched more than 2 min but i can tell you but alot of hard work into this, great work luv from india!!!
@OttoBotCode
@OttoBotCode Ай бұрын
Thank you! 😊
@deniscooper09
@deniscooper09 2 жыл бұрын
Thank you for listening to me!
@OttoBotCode
@OttoBotCode 2 жыл бұрын
And thank you for the suggestion 😀
@stealthragnarr2644
@stealthragnarr2644 8 ай бұрын
Thanks a Lot for this, I needed one project to complete personally in C# and that was my first one, thank you.
@OttoBotCode
@OttoBotCode 8 ай бұрын
I'm glad you like it. Thanks for your comment!
@anthonysteinerv
@anthonysteinerv 2 жыл бұрын
Finally this type of videos return
@gameaudioshaman
@gameaudioshaman 6 ай бұрын
appreciate the work you put into this
@mocanuemanuel7553
@mocanuemanuel7553 Жыл бұрын
You re the best bro , don t stop here. Tell us all you know, GOAT!
@OttoBotCode
@OttoBotCode Жыл бұрын
Thank you so much 🤩 I know it has been a little slow (lot's of things going on these past few months) BUT I am not stopping don't worry. I am working on the next video 😉
@Ayymoss
@Ayymoss 11 ай бұрын
I think the glossing over nullables is probably a little bad for newer developers. Why did you disable it? Nullables are super useful, those warnings should be handled correctly - even if you don't anticipate nullref.
@rzvn111
@rzvn111 3 күн бұрын
Thx, i learned the logic of how to make a game.
@simplonetudiant
@simplonetudiant Жыл бұрын
This video is really great Hope you will continue making games with c#
@OttoBotCode
@OttoBotCode Жыл бұрын
Thanks! There's a big project on the way 😉
@cariyaputta
@cariyaputta 3 ай бұрын
Thanks for this and the chess game tutorial. Added to my library.
@Emcprogamer
@Emcprogamer Жыл бұрын
HELP! At 19:48 it when you did the HeadPosition, TailPosition and also the SnakePositions I get the ERROR Code CS0050 (Inconsistent accessibility: return type 'type' is less accessible than method 'method'). And I did not know what do do so I put it to private for then but at 1:14:40 when you used the HeadPosition again I got the ERROR Code CS0122 ('member' is inaccessible due to its protection level) because it was private. I really need help because I am completely stuck. Thank you!
@OttoBotCode
@OttoBotCode Жыл бұрын
The properties have to public like you said. You are probably getting errors because your Position class is "internal" instead of "public" 😉
@Emcprogamer
@Emcprogamer Жыл бұрын
@@OttoBotCode Yep, That was the solution! Thank you very much, This deserves to subscribe
@cedricfr7047
@cedricfr7047 6 ай бұрын
Awesome, greetings from France ! Thank you !
@andrus1002
@andrus1002 2 ай бұрын
Great tutorial, thank you so much!
@cuke59
@cuke59 Жыл бұрын
Best video of making snake games
@Nate-nc4he
@Nate-nc4he Жыл бұрын
Hey, I really love your content so far very high quality and informative. I unfortunately have been running into a problem for quite sometime now and can't seem to figure it out. At 44:34 is where I first start to have problems. Everything works up until then but, unlike you, when I run the program the empty grid image that is in the assets folder does not show up. I decided to continue till about 53:00 and the same issue still persits, none of the ImageSource images that are shown when you run it, show up for me. The images are indeed marked as "resource" and i have checked over most of the code. Any Ideas? Thanks
@OttoBotCode
@OttoBotCode Жыл бұрын
Thanks for the kind words! Perhaps you are loading your assets from the wrong path (in Images.cs). I am of course just guessing here. If you want me to take a look, then send your project to me at ottobotcodehelp@gmail.com. I'll see if I can find the issue! ☺
@Nate-nc4he
@Nate-nc4he Жыл бұрын
@@OttoBotCode Nvm fixed the issue, turns out i spelt "assets" wrong lmao
@gooffball9758
@gooffball9758 Жыл бұрын
@OttoBotCode in 50 min mark how did you auto generate the Window_Loaded and Window_KeyDown methods? It gives me an error once I try to make them my self, and I cant see where in the code you wrote them. Thanks in advance :)
@OttoBotCode
@OttoBotCode Жыл бұрын
Let's say you want to create an event handler for the KeyDown event. Type in KeyDown="", then the text should show up. When it does, simple hit return and the method will be generated for you 😊
@gooffball9758
@gooffball9758 Жыл бұрын
@@OttoBotCode Sweet thanks for the fast help, that fixed it :)
@Izzy-fr1zu
@Izzy-fr1zu Жыл бұрын
@@OttoBotCode Thanks, I was looking for that!
@ocramkd
@ocramkd 4 ай бұрын
I know the basics of C++ and C#, I've programmed applications like to-do, the hanged man, a textual game using classes, objects, pointers etc... and still I'm having a lot of difficulties understanding this code. Even if I searched it yet I don't understand what is an hashcode for example
@francoislepron2301
@francoislepron2301 3 ай бұрын
Great job. This would have been awesome if you did it using Avalonia UI which is very close to WPF and is cross-platform. This is just an idea.
@captainufo4587
@captainufo4587 Жыл бұрын
Great tutorial! My first time monkeying with WPF, I learned a lot. I thought of using the same system to display an old console app game of mine, but it's slow as molasses (and before making my own, I tested your game with a field as large as 120x70 and it was pretty fast). Any suggestion? Can I write you in private?
@OttoBotCode
@OttoBotCode Жыл бұрын
This game is optimized more for simplicity than for speed, but it's good to hear that it works okay for larger grid sizes. How big is the grid in your game? You can contact me at ottobotcodehelp@gmail.com 😊
@user-gc8if5ts3l
@user-gc8if5ts3l Жыл бұрын
Hi OttoBotCode, thanks a lot. it is very good tutorial. i followed through with good understanding. 2 suggestions, 1) can you see some sound to it, when eat food, turn and die? as a next level tutorial. 2) consider teaching use how to make it an web app to put in online thanks anyway
@OttoBotCode
@OttoBotCode Жыл бұрын
Thanks for the suggestions 😊 Playing sounds is very easy. Just add an mp3 file to the assets folder. You have to set "Build Action" to "Content" and "Copy to Output Directory" to "Copy always". You can play the sound with the MediaPlayer class. MediaPlayer player = new MediaPlayer(); player.Open(new Uri("Assets/your_sound.mp3", UriKind.Relative)); player.Play();
@Izzy-fr1zu
@Izzy-fr1zu Жыл бұрын
@@OttoBotCode awesome thanks! I was looking for that! Can you please explain why we use "content" in that case and not "Resource"?
@SahanRajapaksha-pr2ms
@SahanRajapaksha-pr2ms Жыл бұрын
awesome stuff bro !!
@katharxia7118
@katharxia7118 Жыл бұрын
HI! I got an error in the switch (e.Key). There is an error on the word key saying 'RoutedEventArgs' does not contain a definition for 'Key' and no accessible extension method 'Key' accepting a first argument of type 'RoutedEventArgs' could be found. What might be the problem? I'm not sure what I'm doing wrong so a help would be much appreciated!
@coreyhunter25
@coreyhunter25 Жыл бұрын
At this part in the code under the gamestate class i am getting an error saying inconsistent accessibility for headposition, tailposition, and snakeposition. I have went over everything even rewatched your video up til this point to make sure everything was correct and it is and I can not figure out what is going on. Any ideas? public Position HeadPosition() { return snakePositions.First.Value; } public Position TailPosition() { return snakePositions.Last.Value; } public IEnumerable SnakePositions() { return snakePositions;
@TechRithikesh
@TechRithikesh Жыл бұрын
I will Like and Subscribe in my 10 devices Very good video and easy way of coding thanks a lot , i hope you will be doing such good coding videos
@OttoBotCode
@OttoBotCode Жыл бұрын
Thank you very much! 😊
@sujinlee2980
@sujinlee2980 Жыл бұрын
can somebody give me some advice? Mine works great but one error msg "System.NullReferenceException: Object reference not set to an instance of an object" on method named GetLastDirection
@benyapat.453
@benyapat.453 Жыл бұрын
Excuse me, i to write your code and everything runs except my snake. It doesn't move anywhere. Can you help me please? I've looked at it several times but can't find any mistakes.
@OttoBotCode
@OttoBotCode Жыл бұрын
Send your project to ottobotcodehelp@gmail.com. I'll take a look 😉
@esatzis4664
@esatzis4664 Жыл бұрын
Hello Otto, I would like to thank you from the bottom of my heart about this guide but i would like to ask you if you can help me with a problem i got. Right now i am at 49:51 of the video and when i run the program it says Exceptions Unhandled in a small box, and behind a new screen pops up with the title Symbol Loading Skipped. Can you please help ?
@OttoBotCode
@OttoBotCode Жыл бұрын
You're very welcome 😊 I can try to help, but I need to see your code to figure out what's going on. Can you send your entire project to ottobotcodehelp@gmail.com? It can be as a GitHub link or a zip.
@Whatisbrotalkingabout
@Whatisbrotalkingabout 5 ай бұрын
At 53:21 when you change the text for "ScoreText," my program says "The name 'ScoreText' does not exist in the current context," do you know why this could be?
@Whatisbrotalkingabout
@Whatisbrotalkingabout 5 ай бұрын
Okay, just to be clear, the code still does work, it's just that Visual Studio says there's an error and underlines the code in red.
@OttoBotCode
@OttoBotCode 5 ай бұрын
@@Whatisbrotalkingabout If the program runs and works without issues, then perhaps the IDE is buggy. Have you tried restarting Visual Studio?
@Whatisbrotalkingabout
@Whatisbrotalkingabout 5 ай бұрын
@OttoBotCode I restarted Visual Studio, but it still shows an error. I guess I'll just ignore it, because the code works fine. Thanks for the video!
@iskrenos_gaming3545
@iskrenos_gaming3545 Жыл бұрын
it is teling me Error CS1061 'KeyboardEventArgs' does not contain a definition for 'Key' and no accessible extension method 'Key' accepting a first argument of type 'KeyboardEventArgs' could be found (are you missing a using directive or an assembly reference?) Can you help thanks
@OttoBotCode
@OttoBotCode Жыл бұрын
Do you get this error in the event handler for the key down event? The argument should be"KeyEventArgs" not "KeyboardEventArgs".
@stephenkeesling4665
@stephenkeesling4665 6 ай бұрын
Idk why but I can’t get the snake to move but the code is the same
@PASHKULI
@PASHKULI Жыл бұрын
You need a special Tail .png or .svg for the End of the snake… maybe a triangle shape. A bit more work (especially changing direction of that Tail), but would be much more real.
@omegahaifoleet
@omegahaifoleet Жыл бұрын
Amazing tutorial!
@ukaszjanosik126
@ukaszjanosik126 8 ай бұрын
Excellent course although I think it would be more instructive if various game elements e.g. adding head, removing tail, were implemented a bit later, during debugging. It's a bit overwhelming to implement all logic at the beginning for a beginner audience. Still, great content.
@lexical450
@lexical450 Жыл бұрын
Hello, i'm at 52:55, when i run the application sometimes the key presses do not work. And when they do, after i change the direction 3 times it stops working completely. Then the game "pauses"/freezes, not sure where i went wrong though.
@OttoBotCode
@OttoBotCode Жыл бұрын
You can send your entire project to me at ottobotcodehelp@gmail.com. I'll take a look and see if I can spot the problem 😊
@rikajans
@rikajans 8 ай бұрын
Im having issues around 45:00 - 55:00 somewhere inbetween my code doesnt do the same as yours anymore since when i load the game nothing gets loaded anymore, i got the grid to work before but when i add the snake and the food and give the grid values it just opens the program with nothing, like no program opens at all
@rikajans
@rikajans 8 ай бұрын
Never mind I got it to work but ill keep this here incase anyone has a similar issue so you don't have to respond as often, i solved my issue going back to the gamestate code and finding an issue i wrote there. In my case i had put: for (int c = 0; c
@craig_austin
@craig_austin Жыл бұрын
Do you have the final project on Github? I have gone wrong somewhere and want to compare your code to mine. This will help to see where I have gone wrong
@Sync__s
@Sync__s Жыл бұрын
hey! great video, im having trouble since this is kind of an old version , can u help and create an updated version? thanks!
@OttoBotCode
@OttoBotCode Жыл бұрын
I believe everything should work even with the newest version of C#. What kind of issues are you having?
@nicholasflavin2961
@nicholasflavin2961 Жыл бұрын
Hi Otto, Thank you so much for the tutorial. This helped me learn a lot about creating things in C#. I was using this to try and learn how to create windows and games in C#, however, what I want to do will need a lot larger grid then the 15x15 for snake. I was wondering if this method of creating and drawing the grid is scalable to something like H:350xW:1000? When I try to use large numbers with the code of the snake game (i.e H:200xW:400) the game window doesn't open.
@OttoBotCode
@OttoBotCode Жыл бұрын
Although it is convenient to use a UniformGrid filled with Image Controls, it's not great for performance. For very large grids, it won't work (at least not well). You need to find a different way of drawing the GameState if you want to use a large grid. I don't know what options are available for fast 2D drawing in C#, but I'm sure something exists.
@schav9408
@schav9408 10 ай бұрын
Hello!!! you just gain a new subscriber here!!! I just wanted to ask a question on can you write a code so that every 10 food eaten the snake will get faster and faster? thank you!!!
@OttoBotCode
@OttoBotCode 10 ай бұрын
Awesome, thank you 👍 You can create a variable for the delay in the gameLoop, which you change depending on the current score. For a concrete example, check out my Tetris tutorial. I do something very similar in the game loop for that project! 😊
@safakhan6574
@safakhan6574 Жыл бұрын
Hi there, I’ve just emailed you again regarding my code. When I press any key to start the game the snake doesn’t move and dies on the spot. Do you know what I’ve done wrong?
@GravitraxMasters69
@GravitraxMasters69 Жыл бұрын
​ @OttoBotCode im having problem with this line "List empty = new List(Convert.ToInt32(EmptyPositions()));​" in the AddFood() method
@OttoBotCode
@OttoBotCode Жыл бұрын
The line is: List empty = new List(EmptyPositions()); Do you get an error when you use that?
@its02ninety29
@its02ninety29 Жыл бұрын
hey i was following our steps but i run into problem, it tells me error on (Icon="Assets/icon.ico"). when i deleted it. it launched game but there no grid lines on game it only sad SCORE 0 and game box. i recheck everything but still no difference, even it shows (no issues found). everything is correct but still no lines on game. then i added game states but still nothing. can you help me?
@OttoBotCode
@OttoBotCode Жыл бұрын
Your assets are not being found. Most people who had this issue either didn't mark their images as "Resource" or spelled "Assets" wrong (either the folder itself or the path in Images.cs). Can you check if that is the case for you?
@its02ninety29
@its02ninety29 Жыл бұрын
@@OttoBotCode thenks men I'll check
@its02ninety29
@its02ninety29 Жыл бұрын
@@OttoBotCode found it my Assets folder name was assits and thats why it didnt show
@Notwise66
@Notwise66 23 күн бұрын
At 43:22 I Wrote GameGrid and a error appears it says does not exist in the current context
@ram0973
@ram0973 Жыл бұрын
I am completely lost :) My Snake turns dead just after one step. Can you share the source code? P.S. Step 1 - I've found an error, I just missed the loop in the GameLoop :). Step 2 - now I don't have a snake's head texture - I've just missed DrawSnakeHead() in drawGrid. Step 3 - snake's head not turning rightfully when moving to the left - Direction Left = 2700 instead of 270. Step 4 - score not updates at all - changed DrawGrid to Draw in MainLoop. Now all working perfectly :) I know how to add sound, but how to add background music in the loop?
@OttoBotCode
@OttoBotCode Жыл бұрын
Sorry for the late reply. Glad you made it work! 😊 It looks like you can do add background music using a "MediaTimeline". Check out the answer here: stackoverflow.com/questions/3148965/how-to-do-background-music-for-my-wpf-application
@alext2886
@alext2886 8 күн бұрын
i have error i cant understand what is going wrong please help Severity Code Description Project File Line Suppression State Error (active) CS0050 Inconsistent accessibility: return type 'Position' is less accessible than method 'GameState.HeadPosition()' SnakeGame Error (active) CS0050 Inconsistent accessibility: return type 'Position' is less accessible than method 'GameState.TailPosition()' SnakeGame Error (active) CS0050 Inconsistent accessibility: return type 'IEnumerable' is less accessible than method 'GameState.SnakePositions()' SnakeGame
@OttoBotCode
@OttoBotCode 4 күн бұрын
It sounds like the problem is that your Position class is either internal or private. The methods (HeadPosition, TailPosition, SnakePositions) are public so they cannot return instances of a less visible class (internal, private). Your position class should be made public, as I've done in this video. Hope this helps! 😊
@paynemax3825
@paynemax3825 Жыл бұрын
Thank you very much! This is awesome! May I ask you how can I save the score with a nickname?
@SarcasticCupcake223
@SarcasticCupcake223 Жыл бұрын
So far I am really enjoying this tutorial! However I have run into a problem that probably has a super easy fix but I just can't figure it out. At roughly 43:00 you input the code "GameGrid.Row = rows" and the same for column. My problem is it keeps saying that "GameGrid" doesn't exist. it is possible I missed where you created that, but I can't find where you did that.
@OttoBotCode
@OttoBotCode Жыл бұрын
GameGrid is the name we give the Uniform Grid in MainWindow.xaml. Make sure that your UniformGrid has the attribute x:Name="GameGrid" (I write it around 39:45). Hope this helps and good luck with the rest of the tutorial 😊
@SarcasticCupcake223
@SarcasticCupcake223 Жыл бұрын
@@OttoBotCode Thank you for replying! It turns out I actually did name the Uniform Grid that, but after closing it and opening it, it seems visual studio has registered it properly now, so its all working now. Thanks again!
@OttoBotCode
@OttoBotCode Жыл бұрын
@@SarcasticCupcake223 You're welcome. "Bugs" like that seem to be a little too common in Visual Studio 😅
@SarcasticCupcake223
@SarcasticCupcake223 Жыл бұрын
@@OttoBotCode Hey again, so I've run into another problem. for some reason, when you write the switch statement at 50:27 my one has a problem with the (e.Key) it keeps saying: " 'RoutedEventArgs' does not contain a definition for 'Key' and no accessible extension method 'Key' accepting a first argument of type 'RoutedEventArgs' could be found (are you missing a using directive or an assembly reference?)"
@OttoBotCode
@OttoBotCode Жыл бұрын
@@SarcasticCupcake223 I probably need a bit more information to find the problem. If you send your code to ottobotcodehelp@gmail.com I'll take a look!
@sir_shezen9908
@sir_shezen9908 9 ай бұрын
I Wrote all the codes right but when i want to run or debug the game the bar at bottom turns red and seems like freeze or stop the process and i cant play the game whats the solution?
@OttoBotCode
@OttoBotCode 9 ай бұрын
Do you get some kind of error message in the output window?
@邓翔-v7j
@邓翔-v7j 10 ай бұрын
hey!could i ask about if i met a problem that in the 40 minutes part of the video i try to start my game to check the grid but the grid didn't appear,what's wrong with that ?i am really confused
@OttoBotCode
@OttoBotCode 10 ай бұрын
It's most likely because your assets did not load correctly. Make sure they are marked as "Resource" and that the asset names are spelled correctly in Images.cs.
@邓翔-v7j
@邓翔-v7j 9 ай бұрын
@@OttoBotCode thank u for ur help
@邓翔-v7j
@邓翔-v7j 9 ай бұрын
@@OttoBotCode Can you show me a way to learn c# development games? I don't know where to start.
@solvedplus858
@solvedplus858 Жыл бұрын
this is very good many thanks for your great effort
@OttoBotCode
@OttoBotCode Жыл бұрын
I'm glad you like it!
@optic8268
@optic8268 Жыл бұрын
Hi there, haven't finished the tutorial yet but it seems really good. One problem I have is that App.xaml is not appearing on the solution explorer sidebar, what is the specific fix for that?
@OttoBotCode
@OttoBotCode Жыл бұрын
Hmmm, did you create a WPF project when you started? Do you have MainWindow.xaml and MainWindow.xaml.cs?
@optic8268
@optic8268 Жыл бұрын
@@OttoBotCode oh right, thanks. i started with a WPF class library, instead of WPF application. thanks for the help!
@optic8268
@optic8268 Жыл бұрын
@@OttoBotCode lol need a bit of help again, at 44:42, when i try to start the program, nothing pops up. It says there is no build errors so im just a bit confused
@OttoBotCode
@OttoBotCode Жыл бұрын
@@optic8268 No problem. It's because your assets are not loading correctly. Double check that they are marked as "Resource" (I do it in the "Importing Assets" section). And make sure you have spelled "Assets" correctly (both the folder itself and the path in Images.cs) 😊
@aidenstocking8910
@aidenstocking8910 11 ай бұрын
@@optic8268 Did you manage to fix it? I'm having the same issue and the other suggested fixes aren't working, can't find anything online, very confused.
@TrollHeroActual
@TrollHeroActual 5 ай бұрын
Visual Studio 2022 has deadlined WPF. It's not available in Visual Studio anymore. Is there an alternative way to set up the project in VS 2022?
@OttoBotCode
@OttoBotCode 5 ай бұрын
I've just updated my installation of VS 2022 and WPF is available! Open the "Visual Studio Installer" and "Modify" your installation. Under "Desktop and Mobile" make sure you have ".NET desktop development" installed.
@TrollHeroActual
@TrollHeroActual 5 ай бұрын
@@OttoBotCode Thank you!!! :)
@agataa6067
@agataa6067 Жыл бұрын
hey how could one make an 'easy gamemode' and once the snake hits the edge of the board it reapears on the other side?
@abhinavprabhakar455
@abhinavprabhakar455 2 жыл бұрын
Do you have any plans for videos MAUI? Looking forward for that
@OttoBotCode
@OttoBotCode 2 жыл бұрын
Potentially, yes! But first I have to learn about it myself 😉
@abhinavprabhakar455
@abhinavprabhakar455 2 жыл бұрын
@@OttoBotCode ♥
@MCAltar68
@MCAltar68 Жыл бұрын
hello OttoBotCode ! I would like to say that your tutorial is amazing to understand C# syntaxt and principles. Although, I have a question : In the Direction Class, won't the lines where you initialize LEFT, RIGHT, DOWN, UP create a spiral and themselves create a Direction class that will repeat these lines etc? because you used "new Direction(0, -1)" won't this create a new Direction class? Thanks. PS : I'm french so my question could be badly formulated
@OttoBotCode
@OttoBotCode Жыл бұрын
The new keyword creates an instance of the given class and calls it's constructor. "Normal" class variables are instance variables, which means they belong to an instance (or object) of a class. Left, Right, Down and Up are static variables. Static variables belong to the class itself, so they will only be initialized once. There are simply 4 predefined instances of the Direction class. It is not the case that each Direction instance contains 4 other Direction instances. That would indeed be really bad! Thanks for the kind words ☺
@andriikozyriev3714
@andriikozyriev3714 2 жыл бұрын
Hello. Thank you for lesson. I started to learn c# 3moth ago. I did what you did until 1:00:00, but wheh I start project i see only square and inscription SCORE 0 from above. Maybe I don't tied up grid with main document or what can it be. In class Direction and Position i see ??? like :operator ==(Position? left, Position? ...) public override bool Equals(object? obj), maybe problem tied up with this?
@OttoBotCode
@OttoBotCode 2 жыл бұрын
The ? after the types indicates that they are "nullable". You can turn off the "nullable" feature (I show how to do it in the beginning of this video). Try turning it off and then generate Equals, GetHashCode, etc. again. That will get rid of those strange question marks. I'm not sure if this will fix your problem, if it doesn't just let me know 😁
@andriikozyriev3714
@andriikozyriev3714 2 жыл бұрын
@@OttoBotCode I just did't do assets like resourse. I think, programing is not mine, I even can't repeat that have already been done(
@its_eyjay6080
@its_eyjay6080 Жыл бұрын
Hello can i get the whole copy of this game?
@zelowatch30
@zelowatch30 9 ай бұрын
I like this. Finally a real person. I'm so tired of the stupid AI voices and videos.
@OttoBotCode
@OttoBotCode 9 ай бұрын
Glad you like it! Thanks for your comment 😊
@iceblocksoda8214
@iceblocksoda8214 Жыл бұрын
thank you sir, it's very helpful
@OttoBotCode
@OttoBotCode Жыл бұрын
I'm glad you like it! Thanks for the comment 😉
@zellezxelece9016
@zellezxelece9016 2 жыл бұрын
Would one be able to add one or two more snakes to the game, and also add different type of foods to make the game more dynamic?
@OttoBotCode
@OttoBotCode 2 жыл бұрын
Anything is possible! Both ideas sound like a fun additions to the game. I think different types of food would be easy to implement. How would multiple snakes work? Will all snakes be controlled by the user? 😉
@johnsoto7112
@johnsoto7112 2 жыл бұрын
@@OttoBotCode possibly multiplayer
@alejopgonzz
@alejopgonzz 11 ай бұрын
Thanks a lot! you are awesome!
@emanbhatti585
@emanbhatti585 4 ай бұрын
what did you say in the first 10 min video about the key, the key is cntrl + ...... please tell me
@romerosierrac
@romerosierrac 29 күн бұрын
dot/period "."
@alexanderivanov1672
@alexanderivanov1672 Жыл бұрын
Hi I really like your tutorial, but I ran into a problem. I am on the 49:00 minute and if gives me error " No overload for "Window_Loaded" matches delegate "RoutedEventHandler" ". I rewrote the 46:00 to 49:00 minute code several times, but the same thing happened. I tried with debug but nothing happened. Can you help?
@OttoBotCode
@OttoBotCode Жыл бұрын
If you send your entire project (as a zip or github link) to ottobotcodehelp@gmail.com, I'll try to find the problem for you 😉
@alexanderivanov1672
@alexanderivanov1672 Жыл бұрын
@@OttoBotCode I sent it
@OttoBotCode
@OttoBotCode Жыл бұрын
​@@alexanderivanov1672 I've found the problem. It's explained in my email reply ☺
@alexanderivanov1672
@alexanderivanov1672 Жыл бұрын
@@OttoBotCode Thank you very much! Appreciate it❤
@TestTest-zx4mk
@TestTest-zx4mk Жыл бұрын
@@alexanderivanov1672 You probably just forgot to remove the Window_Loaded Event in xaml
@mohamdrezamohamadiraftar343
@mohamdrezamohamadiraftar343 Жыл бұрын
thanks my brother 💙
@hampus3699
@hampus3699 2 жыл бұрын
really nice video! thank you
@OttoBotCode
@OttoBotCode 2 жыл бұрын
Thanks 😁 I appreciate it!
@Vunk
@Vunk Ай бұрын
Everything was good until 44:00 minutes, the grids won't show. I still followed thru until the snake and food being draw, and nothing was there. I did it exactly like you, maybe something broke in these 2 years.
@OttoBotCode
@OttoBotCode Ай бұрын
No it's working just fine for other people. The most common mistake is not marking your assets as resources - then they won't show up. In the assets folder, select all the images, right click and choose properties, then set "Build Action" to "Resource" (I show this around 2:40 in the video). Let me know if that solves the issue! 😉
@alessandroesofago1837
@alessandroesofago1837 Ай бұрын
​​@@OttoBotCodei'm having the same problem, all the assets are marked as resources.
@OttoBotCode
@OttoBotCode Ай бұрын
@@alessandroesofago1837 The other problem is see quite often is people spell "Assets" wrong. Make sure that the folder is indeed called "Assets" and that the path in Images.cs is also correct. If that doesn't work, you can send your project to ottobotcodehelp@gmail.com and I'll find the problem for you 😊
@Gusseman69
@Gusseman69 Жыл бұрын
Hello OttobotCode i have a problem with the snake and the grid. The problem is that the snake and the grid are not showing on the screen but they exist so i can score points and the snake dies but i can not see anything that is happening
@OttoBotCode
@OttoBotCode Жыл бұрын
It sounds like your assets are not found. Can you double check that they are marked as "Resources"?
@Gusseman69
@Gusseman69 Жыл бұрын
Found the problem it was in the images class. It is when you write public readonly static but it does not work for me so i change them around like public static readonly and it worked
@Gusseman69
@Gusseman69 Жыл бұрын
@@OttoBotCode thank you for your help it was still usefull for findning the problem
@sujinlee2980
@sujinlee2980 Жыл бұрын
where is the right place to call SnackPositions() ?
@ceejaycordero
@ceejaycordero Жыл бұрын
hi i love the tutorial, but i have a problem with the code the food of the snake is not showing can you help me fix it?
@OttoBotCode
@OttoBotCode Жыл бұрын
Yes if you send your project to me at ottobotcodehelp@gmail.com 😊
@ceejaycordero
@ceejaycordero Жыл бұрын
@@OttoBotCode sent
@DiimaPopov
@DiimaPopov 2 жыл бұрын
Great Job! Thank you
@OttoBotCode
@OttoBotCode 2 жыл бұрын
Thanks for your comment 😀
@gloriamasengo
@gloriamasengo Жыл бұрын
hi, I want to ask how to fix the error on position class line 15(translate is giving me an error what can i use instead).?
@OttoBotCode
@OttoBotCode Жыл бұрын
What does the error say?
@gloriamasengo
@gloriamasengo Жыл бұрын
I fixed that error, but now my grid isn’t appearing in fact all my assets aren’t showing
@OttoBotCode
@OttoBotCode Жыл бұрын
@@gloriamasengo Double check that your assets are marked as "Resource" and that you have spelled "Assets" correctly (both the folder and the path in Images.cs)
@jsatstudio5742
@jsatstudio5742 4 ай бұрын
Can i write this game in code blox? I use normal c language.
@zainuddin5591
@zainuddin5591 8 ай бұрын
for some reason the grid is not showing up when i run the code what exactly makes the grid and how do i fix it.
@OttoBotCode
@OttoBotCode 8 ай бұрын
The grid is made by displaying the empty squares next to each other. If it doesn't show up, it's most likely because your assets are not loading correctly. Double check that they are marked as resources and that you've typed their paths correctly in Images.cs 😊
@zainuddin5591
@zainuddin5591 8 ай бұрын
yes i forgot to set the build action to resource @@OttoBotCode
@azekeilaze9908
@azekeilaze9908 Жыл бұрын
Could you please make tutorial about how to add a high score on the snake thank you.
@Махлун
@Махлун Жыл бұрын
Hey. May you tell which patterns of OOP do you use here, please?
@lorenzodiambra5210
@lorenzodiambra5210 5 ай бұрын
Ocaml
@esmeilinantoniorivascabrer6949
@esmeilinantoniorivascabrer6949 Жыл бұрын
The code link no longer works, could you provide it?
@sebastianmantelli533
@sebastianmantelli533 2 жыл бұрын
gj you are great thx ;) Is it possible to do the same things you did with xaml just using the editor tools and properties?
@OttoBotCode
@OttoBotCode 2 жыл бұрын
Thank you 😀 I'm not sure - I prefer to type in the code myself 😉
@alexyoutuberhd3052
@alexyoutuberhd3052 Жыл бұрын
Hello, can you give an example of components that we need to run this program. I mean processor, video card, RAM. I will very much appreciate it.
@OttoBotCode
@OttoBotCode Жыл бұрын
This little game should run on the cheapest hardware you can get your hands on. You need very little RAM and no dedicated video card is necessary 😊
@zohavajdi1744
@zohavajdi1744 Жыл бұрын
hello i write this code in visual 2019 and i have an error for new() keyword, because you said you omitted the type keyword after new, but i cant do it can you help us ?
@OttoBotCode
@OttoBotCode Жыл бұрын
In older versions of C# you must add the type after the new keyword like this: private readonly Dictionary gridValToImage = new Dictionary { // Add key value pairs here just like in the video };
@zohavajdi1744
@zohavajdi1744 Жыл бұрын
@@OttoBotCode thanks alotttttttt
@ChatGpt-vp5ke
@ChatGpt-vp5ke 5 ай бұрын
If I buy full code via patreon for 3$ can I open it with SharpDevelop 4.4?
@catssmacks_
@catssmacks_ Жыл бұрын
Hello, Thank You for the great tutorial but i ran into a problem with the DrawSnakeHead method that you did at 1:14:43 and it looks like this: private void DrawSnakeHead() { Position headPos = gameState.HeadPositon(); Image image = gridImages[headPos.Row, headPos.Col]; image.Source = Images.Head; int rotation = dirToRotation[gameState.Dir]; image.RenderTransform = new RotateTransform(rotation); } but it gives an error on dirToRotation
@OttoBotCode
@OttoBotCode Жыл бұрын
Hello! What does the error say?
@catssmacks_
@catssmacks_ Жыл бұрын
@@OttoBotCode i cant tell you the exact error rn but i remember it said that it doesn't exist in that context
@catssmacks_
@catssmacks_ Жыл бұрын
@@OttoBotCode the exact error is : The name 'dirToRotation' does not exist in the current context
@catssmacks_
@catssmacks_ Жыл бұрын
@@OttoBotCode Nevermind I managed to find the problem myself in the head direction method I have typed it completely wrong. Sorry for the bother!
@natsumeinnit1758
@natsumeinnit1758 Жыл бұрын
@@catssmacks_ im getting same problem help me out
@El_kammex
@El_kammex 2 жыл бұрын
Tutorial is fine, the animations are so helpful. However imo many things are maked so complicated. For exaple in part "Changing Direction Properly" you maked a few method and it could have been done like this: public void ChangeDirection(Direction direction) { if (direction != Dir.Oposite()) { Dir = direction; } }
@OttoBotCode
@OttoBotCode 2 жыл бұрын
That actually doesn't work. I try to explain why in the video. Let's say the snake is moving DOWN and I quickly press LEFT and UP. With your code both changes are accepted (neither one is an opposite). The snake will change direction to LEFT and then to UP before it moves. The result is that the game just ends 😉 I hope that makes sense. Try to use your code and replicate the scenario I just described.
@El_kammex
@El_kammex 2 жыл бұрын
@@OttoBotCode I didnt think about this i that way. Ok so we can wait for move and then Switch dir again. I Missed this info in video, sorry for confusion
@El_kammex
@El_kammex 2 жыл бұрын
@@OttoBotCode I found other solution for this. How can I contack with you to show code?
@OttoBotCode
@OttoBotCode 2 жыл бұрын
@@El_kammex You can send it to me at OttoBotCodeHelp@gmail.com. I'll take a look when I have the time 😉
@Acky0078
@Acky0078 2 жыл бұрын
Still looking forward to see the upcoming C++ videos...
@OttoBotCode
@OttoBotCode 2 жыл бұрын
It will come! 😉
@Acky0078
@Acky0078 2 жыл бұрын
@@OttoBotCode It would be nice if you could cover some more comples sizers (like gridbag sizer and flexgrid sizer) and the wxGLCanvas widget. That would be awesome.
@hassan.shakeel1
@hassan.shakeel1 Жыл бұрын
i dont have a new version of c# so i an having an error on that new() so what should i type for images please suggest
@OttoBotCode
@OttoBotCode Жыл бұрын
In older versions of c# you have to add the type after the new keyword like this: private readonly Dictionary gridValToImage = new Dictionary { // Add key value pairs here just like in the video };
@PASHKULI
@PASHKULI Жыл бұрын
Where is the part where the Food does not get placed on the Snake?
@thesovietmuffin8139
@thesovietmuffin8139 2 жыл бұрын
Hey I’m trying to do this but when I download the assets it won’t let me drag them into the c# program any help?
@OttoBotCode
@OttoBotCode 2 жыл бұрын
When you drag them into the project, do you get an error or it just won't let you?
@OttoBotCode
@OttoBotCode 2 жыл бұрын
I just checked what I could find online. Some people report that they cannot drag and drop when running Visual Studio as administrator. Try running it as a normal user. If that doesn't work you can add the assets like this: right click on your assets folder, choose "Add", then "Existing item" instead. Hope this works! 😀
@thesovietmuffin8139
@thesovietmuffin8139 2 жыл бұрын
@@OttoBotCode hey I figured it out I just had to extract them which I should have done at the beginning but I was being dumb but thank you for the help anyway!
Programming a Tetris Game in C# - Full Guide
39:34
OttoBotCode
Рет қаралды 204 М.
Blueprints vs. C++: How They Fit Together and Why You Should Use Both
47:14
Friends make memories together part 2  | Trà Đặng #short #bestfriend #bff #tiktok
00:18
Сюрприз для Златы на день рождения
00:10
Victoria Portfolio
Рет қаралды 2,6 МЛН
"كان عليّ أكل بقايا الطعام قبل هذا اليوم 🥹"
00:40
Holly Wolly Bow Arabic
Рет қаралды 15 МЛН
Миллионер | 2 - серия
16:04
Million Show
Рет қаралды 1,7 МЛН
How programmers flex on each other
6:20
Fireship
Рет қаралды 2,5 МЛН
Coding Adventure: Rendering Text
1:10:54
Sebastian Lague
Рет қаралды 726 М.
how Google writes gorgeous C++
7:40
Low Level
Рет қаралды 919 М.
Why Isn't Functional Programming the Norm? - Richard Feldman
46:09
JavaScript Fighting Game Tutorial with HTML Canvas
3:56:20
Chris Courses
Рет қаралды 8 МЛН
C# Tutorial Deutsch (Komplettkurs) - C# Lernen in unter 4 Stunden
3:21:40
Programmieren Starten
Рет қаралды 544 М.
Learning C# In A Week... Otherwise I Fail University
9:04
These coding projects give you an unfair advantage
8:13
Jason Goodison
Рет қаралды 1,1 МЛН
Programming a Chess Game in C# | Part 6 - Generating Moves II
18:52
Coding Challenge 180: Falling Sand
23:00
The Coding Train
Рет қаралды 999 М.
Friends make memories together part 2  | Trà Đặng #short #bestfriend #bff #tiktok
00:18