Advertisement
robonx12

Untitled

Feb 12th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.38 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <conio.h>
  4. #include <windows.h>
  5.  
  6.  
  7. #define SIRKA 50
  8. #define VYSKA 50
  9. #define SPODEK 48
  10.  
  11.  
  12. //zmena souradnic kurzoru v cmd
  13. void gotoxy(int x, int y)
  14. {
  15.     COORD coord;
  16.     coord.X = x;
  17.     coord.Y = y;
  18.     SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
  19. }
  20.  
  21. //nacteni mapy - okraju
  22. void mapa(int x, int z, int (*map)[z])
  23. {
  24.     for (int i = 0; i < x; i++)
  25.         for (int y = 0; y < z; y++)
  26.         {
  27.             if ((i == 0) || (y == 0) || (i == x - 1) || (y == z - 1))
  28.                 map[i][y] = 219;
  29.             else
  30.                 map[i][y] = ' ';   
  31.         }  
  32. }
  33.  
  34. //tisk mapy na stdin   
  35. void printm(int x, int z, int (*map)[z])
  36. {
  37.     system("cls");
  38.     printf("Pocet bodu:\n");
  39.     for (int i = 0; i < x; i++)
  40.     {  
  41.         if (i != 0) printf("\n");
  42.         for (int y = 0; y < z; y++)
  43.         printf ("%c", map[i][y]);
  44.     }              
  45. }  
  46.  
  47. //akce pri stisku mezerniku - shoot + interakce s NPC
  48. int shoot(int x, int npc_xy)
  49. {
  50.     for (int i = 46; i > 1; i --)
  51.     {  
  52.         gotoxy(x, i);
  53.         printf("|");   
  54.     }
  55.     Sleep(50);
  56.     for (int i = 46; i > 1; i --)
  57.     {  
  58.         gotoxy(x, i);
  59.         printf(" ");   
  60.     }
  61.     if (x == npc_xy)
  62.         return 1;  
  63. }
  64.        
  65. //logika etc       
  66. int key_move_logic(int z, int (*map)[z])
  67. {
  68.     int b = z/2;
  69.     int key = 0;
  70.     int e;
  71.     int npc = 0;
  72.     int npc_xy = 0;
  73.     int body = 0;
  74.     int p = 0;     
  75.     printm(SIRKA, VYSKA, map);
  76.     gotoxy(b, SPODEK);
  77.     printf("A");
  78.     gotoxy(13, 0);
  79.     printf("%d", body);
  80.     srand(time(NULL));
  81.     for (;;)
  82.     {
  83.         if (npc == 0)
  84.         {
  85.             e = 2;
  86.             npc_xy = rand() % 40 + 5;
  87.             npc = 1;
  88.         }
  89.         do
  90.         {
  91.             p++;
  92.             if (p % 20000 == 0)
  93.             {
  94.                 if (e != 2)
  95.                 {
  96.                     gotoxy(npc_xy, e - 1);
  97.                     printf(" ");
  98.                 }
  99.                 gotoxy(npc_xy, e);
  100.                 printf("O");
  101.                 e++;
  102.             }
  103.         }while (!kbhit());     
  104.         key = getch(); 
  105.         if (key == 97) //doprava   
  106.         {
  107.             if (b != 1)
  108.                 b--;
  109.             gotoxy(b, SPODEK);
  110.             printf("A");
  111.             b++;
  112.             gotoxy(b, SPODEK);
  113.             printf(" ");
  114.             b--;
  115.         }
  116.         else if (key == 100) //doleva
  117.         {
  118.             if (b != 48)
  119.                 b++;
  120.             gotoxy(b, SPODEK);
  121.             printf("A");
  122.             b--;
  123.             gotoxy(b, SPODEK);
  124.             printf(" ");
  125.             b++;
  126.         }
  127.         else if (key == 32)
  128.         {
  129.             if (shoot(b, npc_xy) == 1)
  130.             {
  131.                 npc = 0;
  132.                 body += 10;
  133.                 gotoxy(13, 0);
  134.                 printf("%d", body);
  135.             }
  136.         }
  137.         else if (key == 27)
  138.         {
  139.             system("cls");
  140.             return 0;
  141.         }      
  142.     }      
  143. }      
  144.  
  145. int main(void)
  146. {
  147.     int map [SIRKA][VYSKA];
  148.     mapa(SIRKA, VYSKA, map);
  149.     key_move_logic(VYSKA, map);
  150.     return 0;
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement