https://github.com/lpg2709/verysimplesnakegameinc
A very simple SnakeGame in C
https://github.com/lpg2709/verysimplesnakegameinc
beginner-project beginners-guide c exemple game snake-game windows
Last synced: about 2 months ago
JSON representation
A very simple SnakeGame in C
- Host: GitHub
- URL: https://github.com/lpg2709/verysimplesnakegameinc
- Owner: lpg2709
- Created: 2019-07-18T21:36:49.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-06-18T14:09:12.000Z (almost 5 years ago)
- Last Synced: 2025-04-02T04:55:38.687Z (2 months ago)
- Topics: beginner-project, beginners-guide, c, exemple, game, snake-game, windows
- Language: C
- Homepage:
- Size: 27.3 KB
- Stars: 7
- Watchers: 0
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Very simple snake game in C [Only for windows]
![]()
## Whats is this code:
This is a version of the snake game made with C running in prompt. The code is not the best version or logic for this game. The focus is a simple code for beginners understand arrays and simple concepts of a game logic.
## Whats is need to run this code:
You only need a compiler for C/C++ whogameOver can compile for Windows. All header used in this project is standard headers on compilers for Windows.
## Explaining the code:
- The headres:
- ```stdio.h```
```c
// Funcrtion used of stdio.h
int printf ( const char * format, ... );
FILE * fopen ( const char * filename, const char * mode );
size_t fread ( void * ptr, size_t size, size_t count, FILE * stream );
int fclose ( FILE * stream );
size_t fwrite ( const void * ptr, size_t size, size_t count, FILE * stream );
```
- ```stdlib.h```
```c
// Funcrtion used of stdlib.h
int rand (void);
void srand (unsigned int seed);
void exit (int status);
int system (const char* command);
```
- ```conio.h```
>Header only for windows
```c
// Funcrtion used of conio.h
int kbhit(void);
int getch(void);
```
- ```windows.h```
>Header only for windows
```c
// Funcrtion used of windows.h
void Sleep(DWORD);
```
- ```time.h```
```c
// Funcrtion used of time.h
time_t time (time_t* timer);
```
- Functions:
```c
void setUp(); // read the record file and startup the variables
void mapa(); // the output function, draw the map
void entrada(); // the input function, read the keyboard without interruptions
void logica(); // all the checks and logic of the game
```
- Explain:The only part of the code that may have difficulty understanding is the snake's tail.
The tail is divided into two matrices, with the maximum length being 399, a bit exaggerated. And we have a variable who tell the actual size of the tail.
To have the tail effect follow our movement, we use a 'bubblesort' to rearrange it every cycle of the game.
The logic is, the current position we're checking the tail, gets the position of your neighbor. The first position of the vector receives the position of the head, the second receives that of the first, the third that of the second, and so on.
![]()
- In code:
```C
int posCalX,posCalY;
int posSeguiCalX, posSeguiCalY;
```
These variables are auxiliary to a tail reorganization.
```C
calX[0]=x;
calY[0]=y;
for(i=1;i
## New Record Screen:
![]()
## References:
[stdio.h](http://www.cplusplus.com/reference/cstdio/)
[stdlib.h](http://www.cplusplus.com/reference/cstdlib/)
[time.h](http://www.cplusplus.com/reference/ctime/)