
This is done so that the user’s input can be processed at anytime while the snake thread is looping continuously (if we use only 1 thread, the snake will pause for the user input before moving). The _beginthread(userInput, 0, (void*)0) function starts the function userInput(void* id) in a separate thread. Int oppositeDirection(int input1, int input2) SetConsoleCursorPosition(hStdOut, homeCoords) * Fill the entire buffer with the current colors and attributes */Ĭsbi.wAttributes, //Character attributes to useĬellCount, //Number of cells to set attribute &count //receives the number of characters written (TCHAR) ' ', //character to write to the buffer HStdOut, //handle to console screen buffer If (!GetConsoleScreenBufferInfo(hStdOut, &csbi)) return ĬellCount = * * Get the number of cells and cell attributes in the current buffer */ SetConsoleCursorPosition(hStdOut, coord) If (hStdOut = INVALID_HANDLE_VALUE) return HStdOut = GetStdHandle(STD_OUTPUT_HANDLE) Int input = RIGHT //global variable to take in the user's input (0, -1) is UP (because the row number increase from top to bottom) direction array, for use with RIGHT, UP, LEFT, DOWN constants negative values represent areas that cannot be touched or else game over Thereafter, we will create the display by changing those numbers into something that we can visualize and understand.
#Loading screen snake game code
The code for the Snake program shown in the video above is shown below here! I will explain it in detail below too! The main idea is to create a mathematical layer where each number represent the wall, snake, food, etc. So, Enjoy the game! Oh, please press in case something acts up. It will probably prompt a warning for virus but don’t worry about that because ThePoorEngineer has no interest in infecting your computer or anything.
#Loading screen snake game windows
* The attached file only works in the windows operating system. If you are learning C++ programming, I would say that this exercise would be very beneficial to you, and it is fun as well! Below is a video on the Program, and here is the EXECUTABLE FILE. It might seem complicated at first but it is actually quite simple.

In order to do this, I decided to recreate the old Snake game from the Nokia phone using C++. Both the Arduino IDE and Qt programming (my work in the ARC Lab in NUS requires me to use Qt) uses C++ so I thought it might be good to revise the lecture notes, and also pick up C++ programming along the way. It does not store any personal data.I had a class on Programming methodology during my 1st semester in NUS which uses the C language. The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. The cookie is used to store the user consent for the cookies in the category "Performance". This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.


The cookies is used to store the user consent for the cookies in the category "Necessary".

The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional". The cookie is used to store the user consent for the cookies in the category "Analytics". These cookies ensure basic functionalities and security features of the website, anonymously. Necessary cookies are absolutely essential for the website to function properly.
