Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <conio.h>
- #include <stdio.h>
- #include <windows.h>
- #include <time.h>
- #define NUMBERS_COUNT 10
- void gotoxy(int x, int y)
- {
- COORD c;
- c.X = x - 1;
- c.Y = y - 1;
- SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c);
- }
- void main() {
- int x = 10, y = 3, dx = 1, dy = 1;
- long k;
- char c = 'x';
- char b = 1;
- int px = 40, py = 23;
- int points = 0;
- COORD numbers[NUMBERS_COUNT];
- int i;
- srand(time(NULL));
- for(i = 0; i < NUMBERS_COUNT; i++) {
- numbers[i].X = rand() % 80;
- numbers[i].Y = rand() % 15;
- }
- while (c != 'k'){
- gotoxy(x, y);
- printf("%c", c);
- if (((x == px) || (x == px + 1) || (x == px + 2) || (x == px + 3) || (x == px + 4) || (x == px + 5 || (x== px+6))) && (y==23))
- {
- dy = -dy;
- }
- for(i = 0; i < NUMBERS_COUNT; i++) {
- if(x == numbers[i].X && y == numbers[i].Y) {
- numbers[i].X = rand() % 80;
- numbers[i].Y = rand() % 15;
- points += i + 1; // Punkty dodawane są na zasadzie indeksu z tablicy
- // Tablica indeksowana jest od 0, a my nie chcemy dodawac 0 pkt...
- dy= -dy;
- }
- gotoxy(numbers[i].X, numbers[i].Y);
- printf("%d", i + 1);
- }
- if ((x == 80) || (x == 1))dx = -dx;
- if ((y == 25) || (y == 1))dy = -dy;
- for (k = 0; k<66500000; k++);
- gotoxy(x, y);
- printf(" ");
- x += dx;
- y += dy;
- if (kbhit()) {
- b = getch();
- if ((b == 75) && (px>2)) px -= 2;
- if ((b == 77) && (px<70)) px += 2;
- // jeśli y pileczki == y paletki (powinnjo dojsc do odbicia) ale tylko wtedy gdy x pilczki x < px < x + 7)
- //// if(y == py) dy=-dy;
- gotoxy(px, 23);
- printf(" ............... ");
- }
- if (y==24)
- c='k';
- }
- gotoxy(30,1);
- printf("Niestety, nie udalo sie!");
- gotoxy(20,2);
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement