Advertisement
rowers

Untitled

Mar 10th, 2014
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.15 KB | None | 0 0
  1. #include <conio.h>
  2. #include <stdio.h>
  3. #include <windows.h>
  4. #include <time.h>
  5.  
  6. #define NUMBERS_COUNT 10
  7.  
  8.  
  9. void gotoxy(int x, int y)
  10. {
  11.     COORD c;
  12.     c.X = x - 1;
  13.     c.Y = y - 1;
  14.     SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c);
  15. }
  16.  
  17.  
  18. void main() {
  19.     int x = 10, y = 3, dx = 1, dy = 1;
  20.     long k;
  21.     char c = 'x';
  22.     char b = 1;
  23.     int px = 40, py = 23;
  24.     int points = 0;
  25.  
  26.     COORD numbers[NUMBERS_COUNT];
  27.  
  28.     int i;
  29.  
  30.     srand(time(NULL));
  31.  
  32.     for(i = 0; i < NUMBERS_COUNT; i++) {
  33.         numbers[i].X = rand() % 79;
  34.         numbers[i].Y = rand() % 14;
  35.     }
  36.  
  37.     while (c != 'k'){
  38.  
  39.         gotoxy(x, y);
  40.         printf("%c", c);
  41.        
  42.             if ((x >= px && x <= px + 30) && (y==22))
  43.             {
  44.                 dy = -dy;
  45.                
  46.             }
  47.  
  48.  
  49.         for(i = 0; i < NUMBERS_COUNT; i++) {
  50.             if(x == numbers[i].X && y == numbers[i].Y) {
  51.                 numbers[i].X = rand() % 79;
  52.                 numbers[i].Y = rand() % 14;
  53.  
  54.                 points += i%9 + 1; // Punkty dodawane są na zasadzie indeksu z tablicy
  55.                                  // Tablica indeksowana jest od 0, a my nie chcemy dodawac 0 pkt...
  56.                dy= -dy;
  57.                
  58.             }
  59.  
  60.             gotoxy(numbers[i].X, numbers[i].Y);
  61.             printf("%d", i%9 + 1);
  62.         }
  63.  
  64.         if ((x >= 80) || (x <= 1))dx = -dx;
  65.         if ((y >= 25) || (y <= 1))dy = -dy;
  66.  
  67.         for (k = 0; k<100000000; k++);
  68.         gotoxy(x, y);
  69.         printf(" ");
  70.         x += dx;
  71.         y += dy;
  72.    
  73.  
  74.         if (kbhit()) {
  75.             b = getch();
  76.  
  77.             if ((b == 75) && (px>2)) px -= 2;
  78.             if ((b == 77) && (px<50)) px += 2;
  79.  
  80.             // jeśli y pileczki == y paletki (powinnjo dojsc do odbicia) ale tylko wtedy gdy x pilczki   x  < px < x + 7)
  81.  
  82.             ////    if(y == py) dy=-dy;
  83.  
  84.             gotoxy(px, 23);
  85.             printf("  ==============================  ");  
  86.         }
  87.          if (y==24)
  88.           c='k';
  89.     }
  90.  
  91. gotoxy(30,1);
  92. printf("Niestety, nie udalo sie!");
  93. gotoxy(20,2);
  94. printf("Punkty: %d",points);
  95. system("pause");
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement