Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <conio.h>
- #include <stdio.h>
- #include <windows.h>
- 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=10,dx=1,dy=1,px=36,py=25,i,j,st1=1,st2=1,t,wynik=0;
- int tab[85][27];
- long k;
- char c='x';
- for(i=1;i<80;i=i+1)
- {
- for(j=1;j<27;j=j+1)
- {
- tab[i][j]='o';
- if((i%6==0) && (j%4==0) && (j<15))
- {
- t=1+rand()%3;
- tab[i][j]=t;
- gotoxy(i,j);
- printf("%d", t);
- }
- }
- }
- for(i=1;i<26;i=i+1)
- {
- gotoxy(81,i);
- printf("|");
- }
- while(c!='k'){
- for(k=0;k<2;k++)
- {
- if (kbhit())
- c=getch();
- gotoxy(px,25);
- printf(" ====== ");
- if(c=='a'){
- if (px>1){
- px=px-1;
- gotoxy(px,25);
- printf(" ====== ");}
- }
- if(c=='d'){
- if (px<72){
- px=px+1;
- gotoxy(px,25);
- printf(" ====== ");}
- }
- }
- c='x';
- gotoxy(x,y);
- printf("%c",c);
- if ((y==24) && ((x>=px+1) && (x<=px+7)))dy=-dy;
- if ((x==80) || (x==1))dx=-dx;
- if ((y==25) || (y==1))dy=-dy;
- if (tab[x][y]==1)
- {
- dy=-dy;
- tab[x][y]=0;
- wynik=wynik+1;
- }
- if (tab[x][y]==2)
- {
- dy=-dy;
- tab[x][y]=0;
- wynik=wynik+2;
- }
- if (tab[x][y]==3)
- {
- dy=-dy;
- tab[x][y]=0;
- wynik=wynik+3;
- }
- for(k=0;k<50000000;k++);
- gotoxy(86,1);
- printf("Twoj wynik: %d ", wynik);
- gotoxy(x,y);
- printf(" ");
- x+=dx;
- y+=dy;
- if (y==25)
- {
- c='k';
- }
- }
- for(i=1;i<=80;i=i+1)
- {
- for(j=1;j<=25;j=j+1)
- {
- gotoxy(i,j);
- printf(" ");
- }
- }
- gotoxy(15,10);
- printf("Koniec");
- getchar();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement