Snake game code in c sharp




















Threading ;. Start ;. Setup ;. Draw ;. Input ;. Logic ;. Sleep ;. End ;. Stop ;. Clear ;. Height - 1. Width - 2. Write 1 , i , ConsoleColor. Blue , ConsoleColor. Black ;. Write " 0 " , ConsoleColor.

Yellow , ConsoleColor. Cyan , ConsoleColor. ReadKey false. Key ;. Copy ;. Red , ConsoleColor. White ;. 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. Console snake game in C Ask Question. Asked 3 years ago. Active 3 years ago. Viewed 17k times. Generic; using System. Diagnostics; using System. Text; using System. Threading; using System. SetCursorPosition 0, 0 ; printGrid ; Console. Write "Where to move? ReadKey ; doInput input. Sleep ; Process. Start System. Location ; Environment. Next grid. GetLength 0 , r. GetLength 1 ]; if cell. Improve this question.

Terradice Terradice 1 1 gold badge 1 1 silver badge 6 6 bronze badges. Add a comment. Active Oldest Votes. Improve this answer. Xam Xam 1 1 gold badge 5 5 silver badges 16 16 bronze badges. I like to invest time and energy to think of names that make sense. On that note, I typically rely on the domain for many names.

While you managed to wrangle your solution into just two classes, to me, such an approach does little to describe and document the domain. I use the relatively new C feature of Expression-Bodied members pretty much wherever possible — e. I even keep Main as short as possible, immediately passing control to a normal non-static class. I use it in a few different places and wanted to avoid passing a board object all over.

When first building the object model, I had cells being able to find their own neighbors. David West says something to the effect that at its core, object-oriented programming OOP is an approach to message passing.

It lets the board know that it needs to put out more food. Pausing between each turn to slow the game to human speed is great. In your code as the speed increases so does the pause, making 1 the fastest speed. I found it more intuitive to make the pause go down as the speed goes up.

And, I set a max speed of 5 which is now the fastest speed. Perhaps because I am a bit neurotic about the appearance and readability of my code, I typically conceal monstrous predicates and other calculations, even small ones, in their own property or method. This gives the benefit of naming the predicate or calculation, which in my opinion boosts readability and makes the code largely self-documenting.

For example: to determine if a cell is part of the border you had: if cell. IsHead and Cell. IsTail properties Prompt user for speed when starting and show speed A game timer Declare instructions on the Game class and possibly even add separate Instructions class Come up with a better name than "DoTurn" Avoid having DirectionMap as static Here is the code. I am interested in your feedback on this approach.

Linq; using System. Run ; if System. Quit; if game. O jogador controla um ponto, quadrado ou objeto em um plano com borda. Recreation of the popular game "Snake" for Game Boy Advance. A snake game using C language and SDL2. Works on Ubuntu Platform. SnakeTerm is a terminal snake game that uses NCurses library. Shitty ROM and disk image sources for a shitty fantasy computer.

Emulator is in Asspull3X repo. Second-year project. Add a description, image, and links to the snake-game topic page so that developers can more easily learn about it. Curate this topic. To associate your repository with the snake-game topic, visit your repo's landing page and select "manage topics. Learn more.

Skip to content. Here are public repositories matching this topic Language: C Filter by language. Sort options. Star Updated Nov 10, C. Star 9. A custom 8-bit computer and software suite. Updated Oct 10, C.

Star 8. Updated Aug 2, C. Star 7. A Snake game made in multiple programming languages.



0コメント

  • 1000 / 1000