Advertisement
robonx12

Untitled

Feb 10th, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.08 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <conio.h>
  5. #include <windows.h>
  6.  
  7. void gotoxy(int x, int y)
  8.     {
  9.         COORD coord;
  10.         coord.X = x;
  11.         coord.Y = y;
  12.         SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
  13.     }
  14.  
  15. void mapa(int x, int z, int (*map)[z])
  16.     {
  17.         for (int i = 0; i < x; i++)
  18.             for (int y = 0; y < z; y++)
  19.                 {
  20.                     if ((i == 0) || (y == 0) || (i == x - 1) || (y == z - 1))
  21.                         map[i][y] = 219;
  22.                     else
  23.                         map[i][y] = ' ';   
  24.                 }  
  25.     }
  26.    
  27. void printm(int x, int z, int (*map)[z])
  28.     {
  29.         system("cls");
  30.         for (int i = 0; i < x; i++)
  31.             {
  32.                
  33.                 if (i != 0) printf("\n");
  34.                 for (int y = 0; y < z; y++)
  35.                     printf ("%c", map[i][y]);
  36.             }
  37.                    
  38.     }  
  39.        
  40. int key_move_logic(int x, int z, int (*map)[z])
  41.     {
  42.         int a = x/2;
  43.         int b = z/2;
  44.         int _42 = 0;
  45.         int key = 0;
  46.         gotoxy(b,a);
  47.         for(;;)
  48.         {
  49.             loop:
  50.             key = getch();
  51.             if (key == 119)     //nahoru
  52.                 {
  53.                     a--;
  54.                     _42 = 1;   
  55.                 }
  56.             else if (key == 115) //dolu
  57.                 {
  58.                     a++;
  59.                     _42 = 2;
  60.                 }
  61.             else if (key == 100) //doprava
  62.                 {
  63.                     b++;
  64.                     _42 = 3;
  65.                 }
  66.             else if (key == 97) //doleva
  67.                 {
  68.                     b--;
  69.                     _42 = 4;
  70.                 }
  71.             else if (key == 27) //konec filmu
  72.                 {
  73.                     return 0;
  74.                 }
  75.             while (!kbhit())
  76.             {
  77.                 gotoxy(b,a);
  78.                 if (_42 == 1)
  79.                     {
  80.                         gotoxy(b,a + 1);
  81.                         printf(" ");
  82.                         gotoxy(b,a - 1);
  83.                         a--;
  84.                         Sleep(150);
  85.                     }
  86.                 else if (_42 == 2)
  87.                     {
  88.                         gotoxy(b,a - 1);
  89.                         printf(" ");
  90.                         gotoxy(b,a + 1);
  91.                         a++;
  92.                         Sleep(150);
  93.                     }
  94.                 else if (_42 == 3)
  95.                     {
  96.                         gotoxy(b - 1,a);
  97.                         printf(" ");
  98.                         gotoxy(b + 1,a);
  99.                         b++;
  100.                         Sleep(200);
  101.                     }
  102.                 else if (_42 == 4)
  103.                     {
  104.                         gotoxy(b + 1,a);
  105.                         printf(" ");
  106.                         gotoxy(b - 1,a);
  107.                         b--;
  108.                         Sleep(200);
  109.                     }  
  110.             }
  111.             goto loop;    
  112.         }
  113.            
  114.     }      
  115.  
  116. int main(void)
  117.     {
  118.         int map [25][50];
  119.         mapa(25, 50, map);
  120.         printm(25, 50, map);
  121.         key_move_logic(25, 50, map);
  122.         return 0;
  123.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement