![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Emina Muharemovic Hamdija Sinanovic
main.cpp@0:72dfee80b000, 2014-06-09 (annotated)
- Committer:
- tim004
- Date:
- Mon Jun 09 07:59:44 2014 +0000
- Revision:
- 0:72dfee80b000
Hamdija Sinanovic; Emina Muharemovic
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tim004 | 0:72dfee80b000 | 1 | #include "mbed.h" |
tim004 | 0:72dfee80b000 | 2 | #include "N5110.h" |
tim004 | 0:72dfee80b000 | 3 | |
tim004 | 0:72dfee80b000 | 4 | #define POLUPRECNIK 5 |
tim004 | 0:72dfee80b000 | 5 | |
tim004 | 0:72dfee80b000 | 6 | N5110 display (dp4, dp24, dp23, dp25, dp2, dp6, dp18); |
tim004 | 0:72dfee80b000 | 7 | AnalogIn VRx(dp11); |
tim004 | 0:72dfee80b000 | 8 | AnalogIn VRy(dp10); |
tim004 | 0:72dfee80b000 | 9 | InterruptIn SW(dp9); |
tim004 | 0:72dfee80b000 | 10 | DigitalOut enable(dp14); |
tim004 | 0:72dfee80b000 | 11 | Timer deb; |
tim004 | 0:72dfee80b000 | 12 | |
tim004 | 0:72dfee80b000 | 13 | bool tabela = false; |
tim004 | 0:72dfee80b000 | 14 | bool player1 = true; |
tim004 | 0:72dfee80b000 | 15 | bool nerjeseno = false; |
tim004 | 0:72dfee80b000 | 16 | |
tim004 | 0:72dfee80b000 | 17 | int pobjedeX; |
tim004 | 0:72dfee80b000 | 18 | int pobjedeO; |
tim004 | 0:72dfee80b000 | 19 | int brojac; |
tim004 | 0:72dfee80b000 | 20 | |
tim004 | 0:72dfee80b000 | 21 | struct kursor { |
tim004 | 0:72dfee80b000 | 22 | int x; |
tim004 | 0:72dfee80b000 | 23 | int y; |
tim004 | 0:72dfee80b000 | 24 | } _c; |
tim004 | 0:72dfee80b000 | 25 | |
tim004 | 0:72dfee80b000 | 26 | struct polje { |
tim004 | 0:72dfee80b000 | 27 | kursor gore_lijevo; |
tim004 | 0:72dfee80b000 | 28 | kursor dolje_desno; |
tim004 | 0:72dfee80b000 | 29 | char vrijednost; |
tim004 | 0:72dfee80b000 | 30 | }; |
tim004 | 0:72dfee80b000 | 31 | |
tim004 | 0:72dfee80b000 | 32 | polje ekran[3][3]; |
tim004 | 0:72dfee80b000 | 33 | |
tim004 | 0:72dfee80b000 | 34 | |
tim004 | 0:72dfee80b000 | 35 | void postaviPolja(){ |
tim004 | 0:72dfee80b000 | 36 | |
tim004 | 0:72dfee80b000 | 37 | ekran[0][0].gore_lijevo.x = 0; |
tim004 | 0:72dfee80b000 | 38 | ekran[0][0].gore_lijevo.y = 0; |
tim004 | 0:72dfee80b000 | 39 | ekran[0][0].dolje_desno.x = 26; |
tim004 | 0:72dfee80b000 | 40 | ekran[0][0].dolje_desno.y = 14; |
tim004 | 0:72dfee80b000 | 41 | ekran[0][0].vrijednost = 'a'; |
tim004 | 0:72dfee80b000 | 42 | |
tim004 | 0:72dfee80b000 | 43 | ekran[0][1].gore_lijevo.x = 0; |
tim004 | 0:72dfee80b000 | 44 | ekran[0][1].gore_lijevo.y = 16; |
tim004 | 0:72dfee80b000 | 45 | ekran[0][1].dolje_desno.x = 26; |
tim004 | 0:72dfee80b000 | 46 | ekran[0][1].dolje_desno.y = 30; |
tim004 | 0:72dfee80b000 | 47 | ekran[0][1].vrijednost = 'a'; |
tim004 | 0:72dfee80b000 | 48 | |
tim004 | 0:72dfee80b000 | 49 | ekran[0][2].gore_lijevo.x = 0; |
tim004 | 0:72dfee80b000 | 50 | ekran[0][2].gore_lijevo.y = 32; |
tim004 | 0:72dfee80b000 | 51 | ekran[0][2].dolje_desno.x = 26; |
tim004 | 0:72dfee80b000 | 52 | ekran[0][2].dolje_desno.y = 47; |
tim004 | 0:72dfee80b000 | 53 | ekran[0][2].vrijednost = 'a'; |
tim004 | 0:72dfee80b000 | 54 | |
tim004 | 0:72dfee80b000 | 55 | ekran[1][0].gore_lijevo.x = 28; |
tim004 | 0:72dfee80b000 | 56 | ekran[1][0].gore_lijevo.y = 0; |
tim004 | 0:72dfee80b000 | 57 | ekran[1][0].dolje_desno.x = 54; |
tim004 | 0:72dfee80b000 | 58 | ekran[1][0].dolje_desno.y = 14; |
tim004 | 0:72dfee80b000 | 59 | ekran[1][0].vrijednost = 'a'; |
tim004 | 0:72dfee80b000 | 60 | |
tim004 | 0:72dfee80b000 | 61 | ekran[1][1].gore_lijevo.x = 28; |
tim004 | 0:72dfee80b000 | 62 | ekran[1][1].gore_lijevo.y = 16; |
tim004 | 0:72dfee80b000 | 63 | ekran[1][1].dolje_desno.x = 54; |
tim004 | 0:72dfee80b000 | 64 | ekran[1][1].dolje_desno.y = 30; |
tim004 | 0:72dfee80b000 | 65 | ekran[1][1].vrijednost = 'a'; |
tim004 | 0:72dfee80b000 | 66 | |
tim004 | 0:72dfee80b000 | 67 | ekran[1][2].gore_lijevo.x = 28; |
tim004 | 0:72dfee80b000 | 68 | ekran[1][2].gore_lijevo.y = 32; |
tim004 | 0:72dfee80b000 | 69 | ekran[1][2].dolje_desno.x = 54; |
tim004 | 0:72dfee80b000 | 70 | ekran[1][2].dolje_desno.y = 47; |
tim004 | 0:72dfee80b000 | 71 | ekran[1][2].vrijednost = 'a'; |
tim004 | 0:72dfee80b000 | 72 | |
tim004 | 0:72dfee80b000 | 73 | ekran[2][0].gore_lijevo.x = 56; |
tim004 | 0:72dfee80b000 | 74 | ekran[2][0].gore_lijevo.y = 0; |
tim004 | 0:72dfee80b000 | 75 | ekran[2][0].dolje_desno.x = 83; |
tim004 | 0:72dfee80b000 | 76 | ekran[2][0].dolje_desno.y = 14; |
tim004 | 0:72dfee80b000 | 77 | ekran[2][0].vrijednost = 'a'; |
tim004 | 0:72dfee80b000 | 78 | |
tim004 | 0:72dfee80b000 | 79 | ekran[2][1].gore_lijevo.x = 56; |
tim004 | 0:72dfee80b000 | 80 | ekran[2][1].gore_lijevo.y = 16; |
tim004 | 0:72dfee80b000 | 81 | ekran[2][1].dolje_desno.x = 83; |
tim004 | 0:72dfee80b000 | 82 | ekran[2][1].dolje_desno.y = 30; |
tim004 | 0:72dfee80b000 | 83 | ekran[2][1].vrijednost = 'a'; |
tim004 | 0:72dfee80b000 | 84 | |
tim004 | 0:72dfee80b000 | 85 | ekran[2][2].gore_lijevo.x = 56; |
tim004 | 0:72dfee80b000 | 86 | ekran[2][2].gore_lijevo.y = 32; |
tim004 | 0:72dfee80b000 | 87 | ekran[2][2].dolje_desno.x = 83; |
tim004 | 0:72dfee80b000 | 88 | ekran[2][2].dolje_desno.y = 47; |
tim004 | 0:72dfee80b000 | 89 | ekran[2][2].vrijednost = 'a'; |
tim004 | 0:72dfee80b000 | 90 | } |
tim004 | 0:72dfee80b000 | 91 | |
tim004 | 0:72dfee80b000 | 92 | int mod; //0 - pocetni; 1 - singleplayer; 2 - multiplayer |
tim004 | 0:72dfee80b000 | 93 | int player; |
tim004 | 0:72dfee80b000 | 94 | int polja[3][3]; |
tim004 | 0:72dfee80b000 | 95 | |
tim004 | 0:72dfee80b000 | 96 | void cursor(int x, int y) |
tim004 | 0:72dfee80b000 | 97 | { |
tim004 | 0:72dfee80b000 | 98 | display.setPixel(x, y+1); |
tim004 | 0:72dfee80b000 | 99 | display.setPixel(x-1, y); |
tim004 | 0:72dfee80b000 | 100 | display.setPixel(x, y); |
tim004 | 0:72dfee80b000 | 101 | display.setPixel(x+1, y); |
tim004 | 0:72dfee80b000 | 102 | display.setPixel(x, y-1); |
tim004 | 0:72dfee80b000 | 103 | display.refresh(); |
tim004 | 0:72dfee80b000 | 104 | } |
tim004 | 0:72dfee80b000 | 105 | |
tim004 | 0:72dfee80b000 | 106 | void drawTable(); |
tim004 | 0:72dfee80b000 | 107 | void osvjezi(); |
tim004 | 0:72dfee80b000 | 108 | |
tim004 | 0:72dfee80b000 | 109 | void brisi(int x, int y) |
tim004 | 0:72dfee80b000 | 110 | { |
tim004 | 0:72dfee80b000 | 111 | display.clearPixel(x, y+1); |
tim004 | 0:72dfee80b000 | 112 | display.clearPixel(x-1, y); |
tim004 | 0:72dfee80b000 | 113 | display.clearPixel(x, y); |
tim004 | 0:72dfee80b000 | 114 | display.clearPixel(x+1, y); |
tim004 | 0:72dfee80b000 | 115 | display.clearPixel(x, y-1); |
tim004 | 0:72dfee80b000 | 116 | display.refresh(); |
tim004 | 0:72dfee80b000 | 117 | if(tabela) { |
tim004 | 0:72dfee80b000 | 118 | drawTable(); |
tim004 | 0:72dfee80b000 | 119 | osvjezi(); |
tim004 | 0:72dfee80b000 | 120 | } |
tim004 | 0:72dfee80b000 | 121 | } |
tim004 | 0:72dfee80b000 | 122 | |
tim004 | 0:72dfee80b000 | 123 | void Lijevo(int &x, int &y) |
tim004 | 0:72dfee80b000 | 124 | { |
tim004 | 0:72dfee80b000 | 125 | if(x>1){ |
tim004 | 0:72dfee80b000 | 126 | brisi(x,y); |
tim004 | 0:72dfee80b000 | 127 | x=x-1; |
tim004 | 0:72dfee80b000 | 128 | cursor(x,y); |
tim004 | 0:72dfee80b000 | 129 | |
tim004 | 0:72dfee80b000 | 130 | } |
tim004 | 0:72dfee80b000 | 131 | } |
tim004 | 0:72dfee80b000 | 132 | |
tim004 | 0:72dfee80b000 | 133 | void Desno(int &x, int &y) |
tim004 | 0:72dfee80b000 | 134 | { |
tim004 | 0:72dfee80b000 | 135 | if(x<82){ |
tim004 | 0:72dfee80b000 | 136 | brisi(x,y); |
tim004 | 0:72dfee80b000 | 137 | x=x+1; |
tim004 | 0:72dfee80b000 | 138 | cursor(x,y); |
tim004 | 0:72dfee80b000 | 139 | } |
tim004 | 0:72dfee80b000 | 140 | } |
tim004 | 0:72dfee80b000 | 141 | |
tim004 | 0:72dfee80b000 | 142 | void Gore(int &x, int &y) |
tim004 | 0:72dfee80b000 | 143 | { |
tim004 | 0:72dfee80b000 | 144 | if(y>1){ |
tim004 | 0:72dfee80b000 | 145 | brisi(x,y); |
tim004 | 0:72dfee80b000 | 146 | y=y-1; |
tim004 | 0:72dfee80b000 | 147 | cursor(x,y); |
tim004 | 0:72dfee80b000 | 148 | } |
tim004 | 0:72dfee80b000 | 149 | } |
tim004 | 0:72dfee80b000 | 150 | |
tim004 | 0:72dfee80b000 | 151 | void Dolje(int &x, int &y) |
tim004 | 0:72dfee80b000 | 152 | { |
tim004 | 0:72dfee80b000 | 153 | if(y<46){ |
tim004 | 0:72dfee80b000 | 154 | brisi(x,y); |
tim004 | 0:72dfee80b000 | 155 | y=y+1; |
tim004 | 0:72dfee80b000 | 156 | cursor(x,y); |
tim004 | 0:72dfee80b000 | 157 | } |
tim004 | 0:72dfee80b000 | 158 | } |
tim004 | 0:72dfee80b000 | 159 | |
tim004 | 0:72dfee80b000 | 160 | void tekst(); |
tim004 | 0:72dfee80b000 | 161 | |
tim004 | 0:72dfee80b000 | 162 | void inicijalizirajDisplej(){ |
tim004 | 0:72dfee80b000 | 163 | tekst(); |
tim004 | 0:72dfee80b000 | 164 | } |
tim004 | 0:72dfee80b000 | 165 | |
tim004 | 0:72dfee80b000 | 166 | void tekst() { |
tim004 | 0:72dfee80b000 | 167 | display.setXYAddress(0, 0); |
tim004 | 0:72dfee80b000 | 168 | display.printChar('I'); |
tim004 | 0:72dfee80b000 | 169 | display.printChar('z'); |
tim004 | 0:72dfee80b000 | 170 | display.printChar('a'); |
tim004 | 0:72dfee80b000 | 171 | display.printChar('b'); |
tim004 | 0:72dfee80b000 | 172 | display.printChar('e'); |
tim004 | 0:72dfee80b000 | 173 | display.printChar('r'); |
tim004 | 0:72dfee80b000 | 174 | display.printChar('i'); |
tim004 | 0:72dfee80b000 | 175 | display.printChar('t'); |
tim004 | 0:72dfee80b000 | 176 | display.printChar('e'); |
tim004 | 0:72dfee80b000 | 177 | display.printChar(' '); |
tim004 | 0:72dfee80b000 | 178 | display.printChar('m'); |
tim004 | 0:72dfee80b000 | 179 | display.printChar('o'); |
tim004 | 0:72dfee80b000 | 180 | display.printChar('d'); |
tim004 | 0:72dfee80b000 | 181 | display.printChar(':'); |
tim004 | 0:72dfee80b000 | 182 | display.setXYAddress(0, 2); |
tim004 | 0:72dfee80b000 | 183 | display.printChar('1'); |
tim004 | 0:72dfee80b000 | 184 | display.printChar(' '); |
tim004 | 0:72dfee80b000 | 185 | display.printChar('i'); |
tim004 | 0:72dfee80b000 | 186 | display.printChar('g'); |
tim004 | 0:72dfee80b000 | 187 | display.printChar('r'); |
tim004 | 0:72dfee80b000 | 188 | display.printChar('a'); |
tim004 | 0:72dfee80b000 | 189 | display.printChar('c'); |
tim004 | 0:72dfee80b000 | 190 | display.setXYAddress(0, 4); |
tim004 | 0:72dfee80b000 | 191 | display.printChar('2'); |
tim004 | 0:72dfee80b000 | 192 | display.printChar(' '); |
tim004 | 0:72dfee80b000 | 193 | display.printChar('i'); |
tim004 | 0:72dfee80b000 | 194 | display.printChar('g'); |
tim004 | 0:72dfee80b000 | 195 | display.printChar('r'); |
tim004 | 0:72dfee80b000 | 196 | display.printChar('a'); |
tim004 | 0:72dfee80b000 | 197 | display.printChar('c'); |
tim004 | 0:72dfee80b000 | 198 | display.printChar('a'); |
tim004 | 0:72dfee80b000 | 199 | |
tim004 | 0:72dfee80b000 | 200 | } |
tim004 | 0:72dfee80b000 | 201 | |
tim004 | 0:72dfee80b000 | 202 | void drawTable() { |
tim004 | 0:72dfee80b000 | 203 | for(int i = 0; i < 84; i++) { |
tim004 | 0:72dfee80b000 | 204 | display.setPixel(i, 15); |
tim004 | 0:72dfee80b000 | 205 | display.setPixel(i, 31); |
tim004 | 0:72dfee80b000 | 206 | } |
tim004 | 0:72dfee80b000 | 207 | for(int i = 0; i < 48; i++) { |
tim004 | 0:72dfee80b000 | 208 | display.setPixel(27, i); |
tim004 | 0:72dfee80b000 | 209 | display.setPixel(55, i); |
tim004 | 0:72dfee80b000 | 210 | } |
tim004 | 0:72dfee80b000 | 211 | display.refresh(); |
tim004 | 0:72dfee80b000 | 212 | } |
tim004 | 0:72dfee80b000 | 213 | |
tim004 | 0:72dfee80b000 | 214 | void singleplayerMod(){ |
tim004 | 0:72dfee80b000 | 215 | display.clear(); |
tim004 | 0:72dfee80b000 | 216 | mod = 1; |
tim004 | 0:72dfee80b000 | 217 | tabela = true; |
tim004 | 0:72dfee80b000 | 218 | drawTable(); |
tim004 | 0:72dfee80b000 | 219 | } |
tim004 | 0:72dfee80b000 | 220 | |
tim004 | 0:72dfee80b000 | 221 | void multiplayerMod(){ |
tim004 | 0:72dfee80b000 | 222 | display.clear(); |
tim004 | 0:72dfee80b000 | 223 | tabela = true; |
tim004 | 0:72dfee80b000 | 224 | drawTable(); |
tim004 | 0:72dfee80b000 | 225 | mod = 2; |
tim004 | 0:72dfee80b000 | 226 | } |
tim004 | 0:72dfee80b000 | 227 | |
tim004 | 0:72dfee80b000 | 228 | void izbor (){ |
tim004 | 0:72dfee80b000 | 229 | if(_c.y >= 8*2 && _c.y <= 8*3) {singleplayerMod();} |
tim004 | 0:72dfee80b000 | 230 | else if(_c.y >= 8*4 && _c.y <= 8*5) {multiplayerMod();} |
tim004 | 0:72dfee80b000 | 231 | } |
tim004 | 0:72dfee80b000 | 232 | |
tim004 | 0:72dfee80b000 | 233 | void krajIgre() { |
tim004 | 0:72dfee80b000 | 234 | display.clear(); |
tim004 | 0:72dfee80b000 | 235 | display.printChar('R'); |
tim004 | 0:72dfee80b000 | 236 | display.printChar('e'); |
tim004 | 0:72dfee80b000 | 237 | display.printChar('z'); |
tim004 | 0:72dfee80b000 | 238 | display.printChar('u'); |
tim004 | 0:72dfee80b000 | 239 | display.printChar('l'); |
tim004 | 0:72dfee80b000 | 240 | display.printChar('t'); |
tim004 | 0:72dfee80b000 | 241 | display.printChar('a'); |
tim004 | 0:72dfee80b000 | 242 | display.printChar('t'); |
tim004 | 0:72dfee80b000 | 243 | display.printChar(':'); |
tim004 | 0:72dfee80b000 | 244 | display.printChar(' '); |
tim004 | 0:72dfee80b000 | 245 | display.printChar('0' + pobjedeX); |
tim004 | 0:72dfee80b000 | 246 | display.printChar('-'); |
tim004 | 0:72dfee80b000 | 247 | display.printChar('0' + pobjedeO); |
tim004 | 0:72dfee80b000 | 248 | wait(3); |
tim004 | 0:72dfee80b000 | 249 | display.clear(); |
tim004 | 0:72dfee80b000 | 250 | drawTable(); |
tim004 | 0:72dfee80b000 | 251 | for(int i = 0; i < 3; i++) { |
tim004 | 0:72dfee80b000 | 252 | for(int j = 0; j < 3; j++) { |
tim004 | 0:72dfee80b000 | 253 | ekran[i][j].vrijednost = 'a'; |
tim004 | 0:72dfee80b000 | 254 | } |
tim004 | 0:72dfee80b000 | 255 | } |
tim004 | 0:72dfee80b000 | 256 | brojac = 0; |
tim004 | 0:72dfee80b000 | 257 | } |
tim004 | 0:72dfee80b000 | 258 | |
tim004 | 0:72dfee80b000 | 259 | void provjeriPobjede() { |
tim004 | 0:72dfee80b000 | 260 | if( |
tim004 | 0:72dfee80b000 | 261 | (ekran[0][0].vrijednost == ekran[0][1].vrijednost && ekran[0][1].vrijednost == ekran[0][2].vrijednost && ekran[0][2].vrijednost != 'a') || |
tim004 | 0:72dfee80b000 | 262 | (ekran[1][0].vrijednost == ekran[1][1].vrijednost && ekran[1][1].vrijednost == ekran[1][2].vrijednost && ekran[1][2].vrijednost != 'a') || |
tim004 | 0:72dfee80b000 | 263 | (ekran[2][0].vrijednost == ekran[2][1].vrijednost && ekran[2][1].vrijednost == ekran[2][2].vrijednost && ekran[2][2].vrijednost != 'a') || |
tim004 | 0:72dfee80b000 | 264 | (ekran[0][0].vrijednost == ekran[1][0].vrijednost && ekran[1][0].vrijednost == ekran[2][0].vrijednost && ekran[2][0].vrijednost != 'a') || |
tim004 | 0:72dfee80b000 | 265 | (ekran[0][1].vrijednost == ekran[1][1].vrijednost && ekran[1][1].vrijednost == ekran[2][1].vrijednost && ekran[2][1].vrijednost != 'a') || |
tim004 | 0:72dfee80b000 | 266 | (ekran[0][2].vrijednost == ekran[1][2].vrijednost && ekran[1][2].vrijednost == ekran[2][2].vrijednost && ekran[2][2].vrijednost != 'a') || |
tim004 | 0:72dfee80b000 | 267 | (ekran[0][0].vrijednost == ekran[1][1].vrijednost && ekran[1][1].vrijednost == ekran[2][2].vrijednost && ekran[2][2].vrijednost != 'a') || |
tim004 | 0:72dfee80b000 | 268 | (ekran[0][2].vrijednost == ekran[1][1].vrijednost && ekran[1][1].vrijednost == ekran[2][0].vrijednost && ekran[2][0].vrijednost != 'a') |
tim004 | 0:72dfee80b000 | 269 | ) { |
tim004 | 0:72dfee80b000 | 270 | if(player1) { |
tim004 | 0:72dfee80b000 | 271 | pobjedeX++; |
tim004 | 0:72dfee80b000 | 272 | wait(1); |
tim004 | 0:72dfee80b000 | 273 | krajIgre(); |
tim004 | 0:72dfee80b000 | 274 | } |
tim004 | 0:72dfee80b000 | 275 | else { |
tim004 | 0:72dfee80b000 | 276 | pobjedeO++; |
tim004 | 0:72dfee80b000 | 277 | wait(1); |
tim004 | 0:72dfee80b000 | 278 | krajIgre(); |
tim004 | 0:72dfee80b000 | 279 | } |
tim004 | 0:72dfee80b000 | 280 | } |
tim004 | 0:72dfee80b000 | 281 | } |
tim004 | 0:72dfee80b000 | 282 | |
tim004 | 0:72dfee80b000 | 283 | void crtajX(int x, int y); |
tim004 | 0:72dfee80b000 | 284 | void crtajO(int x0, int y0, int radius); |
tim004 | 0:72dfee80b000 | 285 | |
tim004 | 0:72dfee80b000 | 286 | void klik() { |
tim004 | 0:72dfee80b000 | 287 | if(deb.read_ms() > 400) { |
tim004 | 0:72dfee80b000 | 288 | if(mod == 0) izbor(); |
tim004 | 0:72dfee80b000 | 289 | else { |
tim004 | 0:72dfee80b000 | 290 | for(int i = 0; i < 3; i++) { |
tim004 | 0:72dfee80b000 | 291 | for(int j = 0; j < 3; j++) { |
tim004 | 0:72dfee80b000 | 292 | if(_c.x >= ekran[i][j].gore_lijevo.x &&_c.x <= ekran[i][j].dolje_desno.x && _c.y >= ekran[i][j].gore_lijevo.y && _c.y <= ekran[i][j].dolje_desno.y && ekran[i][j].vrijednost == 'a') { |
tim004 | 0:72dfee80b000 | 293 | if(player1) { |
tim004 | 0:72dfee80b000 | 294 | crtajX(13+28*i, 7+16*j); |
tim004 | 0:72dfee80b000 | 295 | ekran[i][j].vrijednost = 'X'; |
tim004 | 0:72dfee80b000 | 296 | provjeriPobjede(); |
tim004 | 0:72dfee80b000 | 297 | brojac++; |
tim004 | 0:72dfee80b000 | 298 | } |
tim004 | 0:72dfee80b000 | 299 | else { |
tim004 | 0:72dfee80b000 | 300 | crtajO(13+28*i, 7+16*j, POLUPRECNIK); |
tim004 | 0:72dfee80b000 | 301 | ekran[i][j].vrijednost = 'O'; |
tim004 | 0:72dfee80b000 | 302 | provjeriPobjede(); |
tim004 | 0:72dfee80b000 | 303 | brojac++; |
tim004 | 0:72dfee80b000 | 304 | } |
tim004 | 0:72dfee80b000 | 305 | player1 = !player1; |
tim004 | 0:72dfee80b000 | 306 | if(mod == 1) { |
tim004 | 0:72dfee80b000 | 307 | for(int a = 0; a < 3; a++) { |
tim004 | 0:72dfee80b000 | 308 | for(int b = 0; b < 3; b++) { |
tim004 | 0:72dfee80b000 | 309 | if(ekran[a][b].vrijednost == 'a' && !player1) { |
tim004 | 0:72dfee80b000 | 310 | crtajO(13+28*a, 7+16*b, POLUPRECNIK); |
tim004 | 0:72dfee80b000 | 311 | ekran[a][b].vrijednost = 'O'; |
tim004 | 0:72dfee80b000 | 312 | provjeriPobjede(); |
tim004 | 0:72dfee80b000 | 313 | player1 = !player1; |
tim004 | 0:72dfee80b000 | 314 | brojac++; |
tim004 | 0:72dfee80b000 | 315 | } |
tim004 | 0:72dfee80b000 | 316 | } |
tim004 | 0:72dfee80b000 | 317 | } |
tim004 | 0:72dfee80b000 | 318 | } |
tim004 | 0:72dfee80b000 | 319 | if(brojac == 9) { |
tim004 | 0:72dfee80b000 | 320 | wait(1); |
tim004 | 0:72dfee80b000 | 321 | krajIgre(); |
tim004 | 0:72dfee80b000 | 322 | } |
tim004 | 0:72dfee80b000 | 323 | } |
tim004 | 0:72dfee80b000 | 324 | } |
tim004 | 0:72dfee80b000 | 325 | } |
tim004 | 0:72dfee80b000 | 326 | } |
tim004 | 0:72dfee80b000 | 327 | deb.reset(); |
tim004 | 0:72dfee80b000 | 328 | } |
tim004 | 0:72dfee80b000 | 329 | } |
tim004 | 0:72dfee80b000 | 330 | |
tim004 | 0:72dfee80b000 | 331 | void crtajX(int x, int y) { |
tim004 | 0:72dfee80b000 | 332 | display.setPixel(x, y); |
tim004 | 0:72dfee80b000 | 333 | for(int i = 1; i <= 5; i++) { |
tim004 | 0:72dfee80b000 | 334 | display.setPixel(x+i, y+i); |
tim004 | 0:72dfee80b000 | 335 | display.setPixel(x+i, y-i); |
tim004 | 0:72dfee80b000 | 336 | display.setPixel(x-i, y+i); |
tim004 | 0:72dfee80b000 | 337 | display.setPixel(x-i, y-i); |
tim004 | 0:72dfee80b000 | 338 | } |
tim004 | 0:72dfee80b000 | 339 | display.refresh(); |
tim004 | 0:72dfee80b000 | 340 | } |
tim004 | 0:72dfee80b000 | 341 | |
tim004 | 0:72dfee80b000 | 342 | void crtajO(int x0, int y0, int radius) { |
tim004 | 0:72dfee80b000 | 343 | int x = radius, y = 0; |
tim004 | 0:72dfee80b000 | 344 | int radiusError = 1-x; |
tim004 | 0:72dfee80b000 | 345 | |
tim004 | 0:72dfee80b000 | 346 | while(x >= y) |
tim004 | 0:72dfee80b000 | 347 | { |
tim004 | 0:72dfee80b000 | 348 | display.setPixel(x + x0, y + y0); |
tim004 | 0:72dfee80b000 | 349 | display.setPixel(y + x0, x + y0); |
tim004 | 0:72dfee80b000 | 350 | display.setPixel(-x + x0, y + y0); |
tim004 | 0:72dfee80b000 | 351 | display.setPixel(-y + x0, x + y0); |
tim004 | 0:72dfee80b000 | 352 | display.setPixel(-x + x0, -y + y0); |
tim004 | 0:72dfee80b000 | 353 | display.setPixel(-y + x0, -x + y0); |
tim004 | 0:72dfee80b000 | 354 | display.setPixel(x + x0, -y + y0); |
tim004 | 0:72dfee80b000 | 355 | display.setPixel(y + x0, -x + y0); |
tim004 | 0:72dfee80b000 | 356 | y++; |
tim004 | 0:72dfee80b000 | 357 | if (radiusError<0) |
tim004 | 0:72dfee80b000 | 358 | { |
tim004 | 0:72dfee80b000 | 359 | radiusError += 2 * y + 1; |
tim004 | 0:72dfee80b000 | 360 | } else { |
tim004 | 0:72dfee80b000 | 361 | x--; |
tim004 | 0:72dfee80b000 | 362 | radiusError+= 2 * (y - x + 1); |
tim004 | 0:72dfee80b000 | 363 | } |
tim004 | 0:72dfee80b000 | 364 | } |
tim004 | 0:72dfee80b000 | 365 | display.refresh(); |
tim004 | 0:72dfee80b000 | 366 | } |
tim004 | 0:72dfee80b000 | 367 | |
tim004 | 0:72dfee80b000 | 368 | void osvjezi() { |
tim004 | 0:72dfee80b000 | 369 | for(int i = 0; i < 3; i++) { |
tim004 | 0:72dfee80b000 | 370 | for(int j = 0; j < 3; j++) { |
tim004 | 0:72dfee80b000 | 371 | if(ekran[i][j].vrijednost == 'X') { |
tim004 | 0:72dfee80b000 | 372 | crtajX(13+28*i, 7+16*j); |
tim004 | 0:72dfee80b000 | 373 | } |
tim004 | 0:72dfee80b000 | 374 | else if(ekran[i][j].vrijednost == 'O') { |
tim004 | 0:72dfee80b000 | 375 | crtajO(13+28*i, 7+16*j, POLUPRECNIK); |
tim004 | 0:72dfee80b000 | 376 | } |
tim004 | 0:72dfee80b000 | 377 | } |
tim004 | 0:72dfee80b000 | 378 | } |
tim004 | 0:72dfee80b000 | 379 | } |
tim004 | 0:72dfee80b000 | 380 | |
tim004 | 0:72dfee80b000 | 381 | int main() { |
tim004 | 0:72dfee80b000 | 382 | enable = 1; |
tim004 | 0:72dfee80b000 | 383 | SW.mode(PullUp); |
tim004 | 0:72dfee80b000 | 384 | pobjedeX = 0; |
tim004 | 0:72dfee80b000 | 385 | pobjedeO = 0; |
tim004 | 0:72dfee80b000 | 386 | _c.x = 1; |
tim004 | 0:72dfee80b000 | 387 | _c.y = 1; |
tim004 | 0:72dfee80b000 | 388 | mod = 0; |
tim004 | 0:72dfee80b000 | 389 | display.init(); |
tim004 | 0:72dfee80b000 | 390 | SW.rise(&klik); |
tim004 | 0:72dfee80b000 | 391 | deb.start(); |
tim004 | 0:72dfee80b000 | 392 | inicijalizirajDisplej(); |
tim004 | 0:72dfee80b000 | 393 | postaviPolja(); |
tim004 | 0:72dfee80b000 | 394 | while(1) { |
tim004 | 0:72dfee80b000 | 395 | if(mod == 0) tekst(); |
tim004 | 0:72dfee80b000 | 396 | if(VRx < 1.0/3.0) Lijevo(_c.x, _c.y); |
tim004 | 0:72dfee80b000 | 397 | else if(VRx > 2.0/3.0) Desno(_c.x, _c.y); |
tim004 | 0:72dfee80b000 | 398 | if(VRy < 1.0/3.0) Gore(_c.x, _c.y); |
tim004 | 0:72dfee80b000 | 399 | else if(VRy > 2.0/3.0) Dolje(_c.x, _c.y); |
tim004 | 0:72dfee80b000 | 400 | } |
tim004 | 0:72dfee80b000 | 401 | } |