Advertisement
rowers

Untitled

Mar 10th, 2014
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.16 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() % 80;
  34.         numbers[i].Y = rand() % 15;
  35.     }
  36.  
  37.     while (c != 'k'){
  38.  
  39.         gotoxy(x, y);
  40.         printf("%c", c);
  41.        
  42.             if (((x == px) || (x == px + 1) || (x == px + 2) || (x == px + 3) || (x == px + 4) || (x == px + 5 || (x== px+6))) && (y==23))
  43.             {
  44.                 dy = -dy;
  45.             }
  46.  
  47.  
  48.         for(i = 0; i < NUMBERS_COUNT; i++) {
  49.             if(x == numbers[i].X && y == numbers[i].Y) {
  50.                 numbers[i].X = rand() % 80;
  51.                 numbers[i].Y = rand() % 15;
  52.  
  53.                 points += i + 1; // Punkty dodawane są na zasadzie indeksu z tablicy
  54.                                  // Tablica indeksowana jest od 0, a my nie chcemy dodawac 0 pkt...
  55.                dy= -dy;
  56.                
  57.             }
  58.  
  59.             gotoxy(numbers[i].X, numbers[i].Y);
  60.             printf("%d", i + 1);
  61.         }
  62.  
  63.         if ((x == 80) || (x == 1))dx = -dx;
  64.         if ((y == 25) || (y == 1))dy = -dy;
  65.  
  66.         for (k = 0; k<66500000; k++);
  67.         gotoxy(x, y);
  68.         printf(" ");
  69.         x += dx;
  70.         y += dy;
  71.  
  72.         if (kbhit()) {
  73.             b = getch();
  74.  
  75.             if ((b == 75) && (px>2)) px -= 2;
  76.             if ((b == 77) && (px<70)) px += 2;
  77.  
  78.             // jeśli y pileczki == y paletki (powinnjo dojsc do odbicia) ale tylko wtedy gdy x pilczki   x  < px < x + 7)
  79.  
  80.             ////    if(y == py) dy=-dy;
  81.  
  82.             gotoxy(px, 23);
  83.             printf("  ...............  ");  
  84.         }
  85.          if (y==24)
  86.           c='k';
  87.     }
  88.  
  89. gotoxy(30,1);
  90. printf("Niestety, nie udalo sie!");
  91. gotoxy(20,2);
  92. system("pause");
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement