Eddie_1337

snake

May 29th, 2017
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #ifdef _WIN32
  2.     #include <windows.h>
  3.  
  4.     void sleep(unsigned milliseconds)
  5.     {
  6.         Sleep(milliseconds);
  7.     }
  8. #else
  9.     #include <unistd.h>
  10.  
  11.     void sleep(unsigned milliseconds)
  12.     {
  13.         usleep(milliseconds * 1000); // takes microseconds
  14.     }
  15. #endif
  16.  
  17. #include <iostream.h>
  18.  
  19. char teren[19][19];
  20.  
  21. void generare_careu(){
  22.     for (int i = 1; i <= 18; i++){
  23.         teren[1][i] = '#';
  24.         teren[i][1] = '#';
  25.         teren[18][i] = '#';
  26.         teren[i][18] = '#';
  27.     }
  28. }
  29.  
  30. void afisare_careu(){
  31.     for (int i = 1; i <= 18; i++){
  32.         for (int j = 1; j <= 18; j++)
  33.             cout << teren[i][j];
  34.         cout << endl;
  35.     }
  36. }
  37.  
  38. void animatie(){
  39.     int k = 3; char aux;
  40.     while (teren[2][k] != '#'){
  41.         afisare_careu();
  42.         aux = teren[2][k - 1];
  43.         teren[2][k - 1] = teren[2][k];
  44.         teren[2][k] = aux;
  45.         k++;
  46.         sleep(100);
  47.         system("cls");
  48.     }
  49.     afisare_careu();
  50.     system("cls");
  51. }
  52.  
  53.  
  54. int main(){
  55.     generare_careu();
  56.     teren[2][2] = 'O';
  57.     animatie();
  58. }
Advertisement
Add Comment
Please, Sign In to add comment