Posts

My Snake Game Progarm in C++

# include<iostream> # include<conio.h> void run(); void printMap(); void initMap(); void move(int dx, int dy); void update(); void changeDirection(char key); void clearScreen(); void generateFood(); char getMapValue(int value); const int mapwidth = 20; const int mapheight = 20; const int size = mapwidth + mapheight; int map[size]; int headxpos; int headypos; int direction; int food = 3; bool running; int main() { run(); return 0; } void run() { initMap(); running = true; while(running) { if (_kbhit()) { changeDirection(_getch()); } update(); clearScreen(); printMap(); }     std::cout << "\t\t!!!Game over!" << std::endl << "\t\tYour score is:" << food; std::cin.ignore(); } void changeDirection(char key) { switch (key) { case'w': if (direction != 2) direction = 0; break; case'd': if (direction != 3) direction = 1; break; case's...