Advertisement
Guest User

main.cpp

a guest
Jan 8th, 2014
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include "config.hpp"
  2. #include "snake.hpp"
  3.  
  4. int main() {
  5.     COORD cursor = { 0, 0 };
  6.     char plane[SCREEN_WIDTH][SCREEN_HEIGHT] = { 0 };
  7.     Snake snake(0, (int)(SCREEN_HEIGHT / 2));
  8.     unsigned char key_pressed = ControlKeyCodes::right;
  9.  
  10.     while (true) {
  11.         Sleep(200);
  12.         if (_kbhit()) {
  13.             key_pressed = _getch();
  14.         }
  15.         snake.MoveByKeyPressed((ControlKeyCodes)key_pressed);
  16.         SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), cursor);
  17.         plane[snake.GetTailPrePosX()][snake.GetTailPrePosY()] = CellSymbols::empty;
  18.         plane[snake.GetTailPosX()][snake.GetTailPosY()] = CellSymbols::snakeTail;
  19.         plane[snake.GetHeadPosX()][snake.GetHeadPosY()] = CellSymbols::snakeHead;
  20.         for (int i = 0; i < SCREEN_HEIGHT; ++i) {
  21.             for (int j = 0; j < SCREEN_WIDTH; ++j) {
  22.                 std::cout << plane[j][i];
  23.             }
  24.             std::cout << std::endl;
  25.         }
  26.     }
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement