Snake game code in c#.net




















This doucment file contains project Synopsis, Reports, and various diagrams. Also abstract pdf file inside zip so that document link below the page. Complete ready made open source code free of cost download. You can find Top Downloaded C. You can't find any project with your requirement just tell us. We provide project as soon as possibles. Click to Share Here. This is snake game in C. At first download the project from Kashipara. Then Extract the downloaded ZIP file.

You have any error or you don't understand project follow or any other problem. You can ask question. Complete they project perfectly.

The main objective of the car service management System is to manage. The Purpose of the project is to build application manual work for managing the car and car services The objective of this project is to create a system where the customer can easily book their LPG gas cylinder through an online system and the agency can track the record of its customer and the delivery of the cylinder This is very useful project.

This project is used for any Fast Food Shop. The purpose of the project is to build an application program to reduce the manual work for managing the Veh The project is totally built at administrative end a It manages all the information about Books, Stock, Bills, Books. The project is totally built at administrative end and thus only the admin Dark Mode. IoT project components IoT Program. Python db connections.

NET with source code C. NET project snake game c- snake-game. Write Review. Share Projects. Share Ideas. My Project. Your way of making sure the body stays within the length, while growing with more food, is It took me a while to wrap my head around it. You're using the score variable for control. I felt it was clever enough so I left it as is. Please let me know if there is anything unclear in the comments. My version is far from perfect and I am sure I made some pitfalls myself.

Good job on this game. Your logic is good. Yes, there are some improvements in the code and so on, and all of the above comments are spot on, so I'm not going to hammer on the same points. When I ran the game I found it a bit laggy. The constant Console. Clear ; operations made the screen flicker quite a bit. Also, the drawing of the border was a bit long winded. For example, you are on a row at 0, You can write the entire horizontal bar in one go with one Console. The same applies for the bottom row of the border.

On that note: The border doesn't change. So we don't have to keep on drawing the border. We can draw it at the beginning and "pseudo-clear" the console. What I mean by that: the console is already black, so instead of saying Console. Clear ; we can just create a method named ClearConsole ; that writes black over the inside of the frame.

I've made those minor changes, and the game runs a lot smoother, without the flickering on the screen. Here is the modified code, with your variable names and all of that intact:. Naming is key, variables with the names like "hoofd" is kinda hard to read, generally you want your variables to be short but descriptive. I'd prefer pixelPlaceHolder or pixelCursor over something short but harder to read. I know that is a preference. But I've heard fewer people complain about a long var name, then a hard to read name.

Also using a bool instead of yes or no would make your program easier to read. You don't have to use a string equator.

So for buttonpressed, I would rename it to bool buttonPressed. So all you have to do is make buttonPressed, true or false. Also another thing to help you out, for literal like "UP" or 1 place them in const variables. Also 1 could mean anything. Instead, give it a name or a enum value. Started or while GameState! It cuts down on confusion for yourself and others.

Trust me! Leave your code for a couple of weeks and come back to it Let me know if you don't go, "what was I doing here? But generally you want to have a terminating condition in the loop.

Or one step further, have the program return to menu and wait for the user to either: start a new game, or quit. I know some people will argue over it, but IMHO it is bad practice to use a break outside of a switch statement. Reason being, it is harder to debug a loop that has a non-natural break, IE a break inside of a loop, because it takes longer to figure out when that break is triggered.

Especially in bigger programs it's hard to figure out when it will hit that statement. Another bigger issue, that is some times hard to debug, if you accidentally place a break outside a loop. The break statement will then "break" out of the function. This may cause the program to crash, or worse, the program will keep running like nothing happened. The program seems like it is operating normal, but in fact, it could be skipping a potentially important step that would cause the program to crash.

Crashing is not a bad thing, because it is the most obvious way to detect an issue with your code. In fact, when something is wrong and you don't get feed back, that is when you pull out your hair. Your code is not bad, especially for a beginner. I know, when I started out, I was hesitant in putting code into classes or functions, if I could get away putting it all in one function like main.

Once you get experience you will find, that functions make things easier to read and also program. Take for instance your while loops. If they were in their own functions, you could pass in the condition to stop at, and pass back the result, and it will be a lot easier to read and handle the program flow. Try, making main, the Head Quarters of your program and the functions the actual controls for your program. So all main does, is kick off the action and the functions control the actual movement of the snake.

Like have the first while loop, in a function called Draw. It takes in the changes from the switch statement, and redraws the snake based on the input. Then have another function for the other while loop. Call that function UserInput. If you want Co locate the switch statement with that loop, or have it in its own function. When you press a button while it's in the loop it can call the switch statement to make the adjustment, and then redraw the environment by calling the draw function.

You may find by doing this "refactoring" that you can rid yourself of a while loop or loops, which will reduce your Big O notation which can make your program faster. Obviously, since your program is so small this reduction in loops will not be that noticeable.

If you get in the practice now of doing it, when you move to something bigger, it will make a big difference. As one of the commentators above have mentioned, Clean Code is a really good book for learning how to refactor, and making code more efficient. The plus side of making clean code, is you can use it in more then one program. The more 'Object' you make your code the easier it is to use the code in other programs. I hope this helps you out, or at least, gives you ideas of how to improve your program.

Either way, keep up the good work. Just like anything, everyone starts somewhere and with practice you will be as good or better as many of the people you see giving examples on this site or Stack Overflow. In other words, keep coding my friend.

Your Main is tooo long and it is horrible to Read. Split your Code into multiple functions so other people can Read, and it becomes easier to unterstand with functions. A Thread. Sleep 5 is needed, otherwise loop will go horribly fast and it will eat lots of processorpower.

Sign up to join this community. The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group.

Create a free Team What is Teams? Learn more. First C program Snake game Ask Question. Asked 5 years, 8 months ago. Active 3 years, 4 months ago. Viewed k times. Generic; using System. Linq; using System. Text; using System. Tasks; using System. Clear ; if hoofd. SetCursorPosition i, 0 ; Console.

SetCursorPosition i, screenheight -1 ; Console. SetCursorPosition 0, i ; Console. SetCursorPosition screenwidth - 1, i ; Console. SetCursorPosition xposlijf[i], yposlijf[i] ; Console. SetCursorPosition hoofd. SetCursorPosition berryx, berryy ; Console. Cyan; Console. Now; if tijd2. Subtract tijd. WriteLine toets. ToString ; if toets. Equals ConsoleKey. Add hoofd. RemoveAt 0 ; yposlijf. Improve this question. Wagacca Wagacca 1 1 gold badge 1 1 silver badge 6 6 bronze badges.

Study the code and the answers there for some good tips: codereview. If there is not a good answer by tonight, I'll put some time into giving you a good example. Add a comment. Active Oldest Votes. Naming things Let's start with the obvious: naming. Your busy too busy, but I am coming to that list of declarations in the beginning becomes something like this: Console.

Using your classes properly Here is what I do not understand. Drawing the border As other answerers kindly said, your loop is too long. Direction You're using string values to indicate direction.

Right; C gives you type safety. Refactoring I noticed you use this exact pattern of code a lot : SetCursorPosition head. XPos, head.



0コメント

  • 1000 / 1000