pozicija loptice
pozicijaLoptice.cpp@0:7aa751de1e82, 2021-02-22 (annotated)
- Committer:
- atopcic
- Date:
- Mon Feb 22 08:25:01 2021 +0000
- Revision:
- 0:7aa751de1e82
pozicija loptice;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
atopcic | 0:7aa751de1e82 | 1 | // funkcija pozicioniranja loptice: |
atopcic | 0:7aa751de1e82 | 2 | |
atopcic | 0:7aa751de1e82 | 3 | #include "pozicijaLoptice.h" |
atopcic | 0:7aa751de1e82 | 4 | extern int polje[8][8]; |
atopcic | 0:7aa751de1e82 | 5 | int loptaUljevo=1,loptaGore=1,loptaX=5,loptaY=4,Igrac1rez=0,Igrac2rez=0; |
atopcic | 0:7aa751de1e82 | 6 | Timer timer3; |
atopcic | 0:7aa751de1e82 | 7 | |
atopcic | 0:7aa751de1e82 | 8 | void PozicijaLoptice (void){ |
atopcic | 0:7aa751de1e82 | 9 | |
atopcic | 0:7aa751de1e82 | 10 | if(loptaUljevo==1) |
atopcic | 0:7aa751de1e82 | 11 | loptaX--; |
atopcic | 0:7aa751de1e82 | 12 | else |
atopcic | 0:7aa751de1e82 | 13 | loptaX++; |
atopcic | 0:7aa751de1e82 | 14 | if(loptaX == 0) |
atopcic | 0:7aa751de1e82 | 15 | loptaUljevo = 0; |
atopcic | 0:7aa751de1e82 | 16 | else if (loptaX == 7) |
atopcic | 0:7aa751de1e82 | 17 | loptaUljevo = 1; |
atopcic | 0:7aa751de1e82 | 18 | |
atopcic | 0:7aa751de1e82 | 19 | if(loptaGore==1) |
atopcic | 0:7aa751de1e82 | 20 | loptaY++; |
atopcic | 0:7aa751de1e82 | 21 | else |
atopcic | 0:7aa751de1e82 | 22 | loptaY--; |
atopcic | 0:7aa751de1e82 | 23 | |
atopcic | 0:7aa751de1e82 | 24 | |
atopcic | 0:7aa751de1e82 | 25 | if(loptaY == 6 && polje[7][loptaX] == 1) |
atopcic | 0:7aa751de1e82 | 26 | { |
atopcic | 0:7aa751de1e82 | 27 | loptaGore = 0; |
atopcic | 0:7aa751de1e82 | 28 | } |
atopcic | 0:7aa751de1e82 | 29 | |
atopcic | 0:7aa751de1e82 | 30 | else if(loptaY == 1 && polje[0][loptaX] == 1) |
atopcic | 0:7aa751de1e82 | 31 | |
atopcic | 0:7aa751de1e82 | 32 | { |
atopcic | 0:7aa751de1e82 | 33 | loptaGore = 1; |
atopcic | 0:7aa751de1e82 | 34 | } |
atopcic | 0:7aa751de1e82 | 35 | |
atopcic | 0:7aa751de1e82 | 36 | else if( loptaY==7 || loptaY==0) |
atopcic | 0:7aa751de1e82 | 37 | { |
atopcic | 0:7aa751de1e82 | 38 | if(loptaY==0){ Igrac2rez++; Igrac2rez%=8;} |
atopcic | 0:7aa751de1e82 | 39 | else if(loptaY==7){Igrac1rez++; Igrac1rez%=8;} |
atopcic | 0:7aa751de1e82 | 40 | //resetpolja: |
atopcic | 0:7aa751de1e82 | 41 | for(int i=0;i<8;i++) |
atopcic | 0:7aa751de1e82 | 42 | { |
atopcic | 0:7aa751de1e82 | 43 | for(int j=0;j<8;j++) |
atopcic | 0:7aa751de1e82 | 44 | { |
atopcic | 0:7aa751de1e82 | 45 | polje[i][j]=0; |
atopcic | 0:7aa751de1e82 | 46 | } |
atopcic | 0:7aa751de1e82 | 47 | } |
atopcic | 0:7aa751de1e82 | 48 | //prikaz rezultata: |
atopcic | 0:7aa751de1e82 | 49 | for( int i=0;i<8;i++) |
atopcic | 0:7aa751de1e82 | 50 | { |
atopcic | 0:7aa751de1e82 | 51 | if (i<Igrac2rez) polje[7][i]=1; |
atopcic | 0:7aa751de1e82 | 52 | if(i<Igrac1rez) polje[0][i]=1; |
atopcic | 0:7aa751de1e82 | 53 | } |
atopcic | 0:7aa751de1e82 | 54 | while(timer3.read_ms() < 1000) ispis(); |
atopcic | 0:7aa751de1e82 | 55 | loptaUljevo=!loptaUljevo; |
atopcic | 0:7aa751de1e82 | 56 | loptaGore=!loptaGore; |
atopcic | 0:7aa751de1e82 | 57 | loptaX=4,loptaY=4; |
atopcic | 0:7aa751de1e82 | 58 | } |
atopcic | 0:7aa751de1e82 | 59 | polje[loptaY][loptaX] = 1; |
atopcic | 0:7aa751de1e82 | 60 | } |