{"id":18290597,"url":"https://github.com/lpg2709/verysimplesnakegameinc","last_synced_at":"2025-04-05T10:30:50.122Z","repository":{"id":162610305,"uuid":"197660239","full_name":"lpg2709/VerySimpleSnakeGameInC","owner":"lpg2709","description":"A very simple SnakeGame in C","archived":false,"fork":false,"pushed_at":"2020-06-18T14:09:12.000Z","size":28,"stargazers_count":7,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-02T04:55:38.687Z","etag":null,"topics":["beginner-project","beginners-guide","c","exemple","game","snake-game","windows"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lpg2709.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-07-18T21:36:49.000Z","updated_at":"2025-03-10T06:48:31.000Z","dependencies_parsed_at":"2024-05-31T20:35:09.963Z","dependency_job_id":null,"html_url":"https://github.com/lpg2709/VerySimpleSnakeGameInC","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lpg2709%2FVerySimpleSnakeGameInC","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lpg2709%2FVerySimpleSnakeGameInC/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lpg2709%2FVerySimpleSnakeGameInC/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lpg2709%2FVerySimpleSnakeGameInC/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lpg2709","download_url":"https://codeload.github.com/lpg2709/VerySimpleSnakeGameInC/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247324395,"owners_count":20920636,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["beginner-project","beginners-guide","c","exemple","game","snake-game","windows"],"created_at":"2024-11-05T14:11:35.144Z","updated_at":"2025-04-05T10:30:50.112Z","avatar_url":"https://github.com/lpg2709.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Very simple snake game in C [Only for windows]\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\".img/jogoMap.png\"\u003e\n\u003c/p\u003e\n\n## Whats is this code:\n\nThis 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.\n\n## Whats is need to run this code:\n\nYou 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.\n\n## Explaining the code:\n\n- The headres:\n    - ```stdio.h```\n    \n    ```c\n    // Funcrtion used of stdio.h\n    int printf ( const char * format, ... );\n    FILE * fopen ( const char * filename, const char * mode );\n    size_t fread ( void * ptr, size_t size, size_t count, FILE * stream );\n    int fclose ( FILE * stream );\n    size_t fwrite ( const void * ptr, size_t size, size_t count, FILE * stream );\n    ```\n    - ```stdlib.h```\n    ```c\n    // Funcrtion used of stdlib.h\n    int rand (void);\n    void srand (unsigned int seed);\n    void exit (int status);\n    int system (const char* command);\n    ```\n    - ```conio.h```\n    \n    \u003eHeader only for windows\n    ```c\n    // Funcrtion used of conio.h\n    int kbhit(void);\n    int getch(void);\n    \n    ```\n    - ```windows.h```\n    \n    \u003eHeader only for windows\n    ```c\n    // Funcrtion used of windows.h\n    void Sleep(DWORD);\n    \n    ```\n    - ```time.h```\n    ```c\n    // Funcrtion used of time.h\n    time_t time (time_t* timer);\n    \n    ```\n- Functions:\n    ```c\n    void setUp(); // read the record file and startup the variables\n    void mapa(); // the output function, draw the map\n    void entrada(); // the input function, read the keyboard without interruptions\n    void logica(); // all the checks and logic of the game    \n    ```\n- Explain:\n\nThe only part of the code that may have difficulty understanding is the snake's tail.\n\nThe 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.\n\nTo have the tail effect follow our movement, we use a 'bubblesort' to rearrange it every cycle of the game.\n\nThe 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.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\".img/tailLogic.png\"\u003e\n\u003c/p\u003e\n\n- In code:\n```C\nint posCalX,posCalY; \nint posSeguiCalX, posSeguiCalY;\n```\nThese variables are auxiliary to a tail reorganization. \n```C\ncalX[0]=x;\ncalY[0]=y;\nfor(i=1;i\u003cMAXCALDA;i++){ \n  posSeguiCalX = posCalX;\n  posSeguiCalY = posCalY;\n  posCalX=calX[i];\n  posCalY=calY[i];\n  calX[i]=posSeguiCalX;\n  calY[i]=posSeguiCalY;\n}\n``` \n\nBefore entering the loop, we take the x and y positions of the head. And we do the 'bubblesort'.\n\nIn order to draw the syrup on the screen, we need to validate each position of the screen in relation to the vector. If the string corresponds with the current location of the screen we start the character, we change the value of the variable that allows the space to be placed on the screen. 1, so we do not print the space in the position check.\n\n\n## Game Over Screen: \n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\".img/gameOver.PNG\"\u003e\n\u003c/p\u003e\n\n## New Record Screen: \n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\".img/record.PNG\"\u003e\n\u003c/p\u003e\n\n## References:\n\n[stdio.h](http://www.cplusplus.com/reference/cstdio/)\n\n[stdlib.h](http://www.cplusplus.com/reference/cstdlib/)\n\n[time.h](http://www.cplusplus.com/reference/ctime/)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flpg2709%2Fverysimplesnakegameinc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flpg2709%2Fverysimplesnakegameinc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flpg2709%2Fverysimplesnakegameinc/lists"}