Solitaire for the TI-84 Plus CE!
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactoring

euphory 0e51a809 0c90c255

+406 -336
+80
src/drawing.c
··· 1 + #include "drawing.h" 2 + 3 + #include <graphx.h> 4 + #include "gfx/gfx.h" 5 + #include "variables.h" 6 + 7 + gfx_sprite_t* cardSprite[11]; 8 + 9 + void drawCursor(unsigned char X, unsigned char Y) 10 + { 11 + if (cursorMode == SELECT) gfx_TransparentSprite(selcorner, X - 2, Y - 2); 12 + else gfx_TransparentSprite(drpcorner, X - 2, Y - 2); 13 + } 14 + 15 + void drawFrame() 16 + { 17 + gfx_FillScreen(BKGND_COLOR); 18 + gfx_SetColor(BORDER_COLOR); 19 + gfx_FillRectangle(0, 0, GFX_LCD_WIDTH, TOP_BORDER); 20 + 21 + for (unsigned char i = 0; i < NUM_FREECELLS; i++) 22 + { 23 + unsigned char cardX = FC_HPOS + i * (CARD_WIDTH + CARD_SPACING); 24 + 25 + if (freeCells[i] == 11) gfx_Sprite(freespace, cardX, FC_VPOS); 26 + else if (freeCells[i] > 11) gfx_Sprite(cardSprite[10], cardX, FC_VPOS); 27 + else gfx_Sprite(cardSprite[freeCells[i]], cardX, FC_VPOS); 28 + 29 + if (i >= fcUnlocked) 30 + { 31 + gfx_Sprite(lock, cardX + LOCK_ICON_HOFFSET, FC_VPOS + LOCK_ICON_VOFFSET); 32 + } 33 + 34 + if (i == cursorStack) drawCursor(cardX, FC_VPOS); 35 + } 36 + 37 + for (unsigned char i = 0; i < NUM_TABLSLOTS; i++) 38 + { 39 + for (unsigned char j = 0; j < TABL_STACK_SIZE; j++) 40 + { 41 + unsigned char cardX = TABL_HPOS + i * (CARD_WIDTH + CARD_SPACING); 42 + unsigned char cardY = TABL_VPOS + j * CARD_VOFFSET; 43 + 44 + if (progress < 10) if (i + NUM_FREECELLS == cursorStack) if (j == cursorIndex) 45 + drawCursor(cardX, cardY); 46 + 47 + const unsigned char x = tableau[i][j]; 48 + 49 + if (x == 11) break; 50 + if (x > 11) gfx_Sprite(cardSprite[10], cardX, cardY); 51 + else gfx_Sprite(cardSprite[x], cardX, cardY); 52 + } 53 + } 54 + 55 + if (progress < 10) 56 + { 57 + gfx_SetTextXY(SELCARD_DISP_X, SELCARD_DISP_Y); 58 + if (selectedCard != 11) 59 + { 60 + gfx_PrintUInt(selectedCard + 1, 1); 61 + if (selectedQty > 1) 62 + { 63 + gfx_PrintString(" x"); 64 + gfx_PrintUInt(selectedQty, 1); 65 + } 66 + } 67 + else gfx_PrintString("EMPTY"); 68 + } 69 + 70 + if (progress == 10) 71 + gfx_PrintStringXY("COMPLETE", GFX_LCD_WIDTH / 2 - 4 * TEXT_CHAR_WIDTH, SELCARD_DISP_Y); 72 + else if (cursorMode == SELECT) 73 + gfx_PrintStringXY("SELECT", GFX_LCD_WIDTH / 2 - 3 * TEXT_CHAR_WIDTH, SELCARD_DISP_Y); 74 + else gfx_PrintStringXY("DROP", GFX_LCD_WIDTH / 2 - 2 * TEXT_CHAR_WIDTH, SELCARD_DISP_Y); 75 + 76 + gfx_SetTextXY(NUMWINS_DISP_X, SELCARD_DISP_Y); 77 + gfx_PrintUInt(numWins, 3); 78 + 79 + gfx_BlitBuffer(); 80 + }
+17
src/drawing.h
··· 1 + #ifndef drawing_include_file 2 + #define drawing_include_file 3 + 4 + #include <graphx.h> 5 + #include <gfx/gfx.h> 6 + 7 + #define CARD_HEIGHT card1_height 8 + #define CARD_WIDTH card1_width 9 + #define CARD_SPACING 5 10 + #define CARD_VOFFSET 8 11 + 12 + extern gfx_sprite_t* cardSprite[11]; 13 + 14 + void drawCursor(unsigned char X, unsigned char Y); 15 + void drawFrame(); 16 + 17 + #endif
+127
src/input.c
··· 1 + #include "input.h" 2 + 3 + #include <stdlib.h> 4 + #include <keypadc.h> 5 + #include "variables.h" 6 + #include "ops.h" 7 + 8 + unsigned char down, left, right, up; 9 + 10 + bool doInput() 11 + { 12 + const bool prevSecond = kb_IsDown(kb_Key2nd); 13 + const bool prevEnter = kb_IsDown(kb_KeyEnter); 14 + const bool prevAlpha = kb_IsDown(kb_KeyAlpha); 15 + const bool prevClear = kb_IsDown(kb_KeyClear); 16 + 17 + kb_Scan(); 18 + 19 + up = kb_IsDown(kb_KeyUp) ? up + 1 : 0; 20 + down = kb_IsDown(kb_KeyDown) ? down + 1 : 0; 21 + left = kb_IsDown(kb_KeyLeft) ? left + 1 : 0; 22 + right = kb_IsDown(kb_KeyRight) ? right + 1 : 0; 23 + 24 + const bool select = (kb_IsDown(kb_Key2nd) && !prevSecond) || (kb_IsDown(kb_KeyEnter) && !prevEnter); 25 + const bool clear = (kb_IsDown(kb_KeyClear) && !prevClear) || (kb_IsDown(kb_KeyAlpha) && !prevAlpha); 26 + 27 + if (select) 28 + { 29 + if (cursorMode == SELECT && canGrabCard()) 30 + { 31 + orgStack = cursorStack; 32 + orgIndex = cursorIndex; 33 + cursorMode = DROP; 34 + } 35 + else if (canDropCard()) 36 + { 37 + dropCard(); 38 + cursorMode = SELECT; 39 + } 40 + else if (cursorStack == orgStack) 41 + { 42 + cursorMode = SELECT; 43 + } 44 + } 45 + else if (clear) cursorMode = SELECT; 46 + 47 + unsigned char prevCursorStack = cursorStack; 48 + 49 + if (down == 1 || down > HOLD_TIME) 50 + { 51 + cursorIndex++; 52 + } 53 + else if (left == 1 || left > HOLD_TIME) 54 + { 55 + do 56 + { 57 + if (cursorStack == 0) cursorStack = NUM_FREECELLS + NUM_TABLSLOTS - 1; // wrap 58 + else cursorStack--; 59 + } 60 + while (cursorOnCollapsed() || cursorOnLocked()); // skip useless stacks 61 + } 62 + else if (right == 1 || right > HOLD_TIME) 63 + { 64 + do 65 + { 66 + if (cursorStack > NUM_FREECELLS + NUM_TABLSLOTS - 2) cursorStack = 0; // wrap 67 + else cursorStack++; 68 + } 69 + while (cursorOnCollapsed() || cursorOnLocked()); // skip useless stacks 70 + } 71 + else if (up == 1 || up > HOLD_TIME) 72 + { 73 + if (cursorIndex > 0) cursorIndex--; 74 + } 75 + 76 + if (cursorStack < NUM_FREECELLS) 77 + { 78 + cursorIndex = 0; 79 + } 80 + else if (cursorMode == DROP) 81 + { 82 + // if dropping cards, the cursor should always be at the top of the stack it's on 83 + // except maxCursorIndex() doesn't work so well on empty tableau stacks 84 + if (cursorStack != orgStack) 85 + { 86 + if (tableau[cursorStack - NUM_FREECELLS][0] == 11) 87 + { 88 + cursorIndex = 0; 89 + } 90 + else 91 + { 92 + maxCursorIndex(); 93 + cursorIndex++; 94 + } 95 + } 96 + else cursorIndex = orgIndex; // also this makes it more clear if we are trying to drop 97 + // back on the original cards 98 + } 99 + else if (cursorStack != prevCursorStack) 100 + { 101 + maxCursorIndex(); 102 + } 103 + else 104 + { 105 + while (tableau[cursorStack - NUM_FREECELLS][cursorIndex] == 11 && cursorIndex > 0) cursorIndex--; 106 + } 107 + 108 + if (cursorMode == SELECT) 109 + { 110 + selectedQty = 1; 111 + if (cursorStack < NUM_FREECELLS) selectedCard = freeCells[cursorStack]; 112 + else 113 + { 114 + selectedCard = tableau[cursorStack - NUM_FREECELLS][cursorIndex]; 115 + for (int i = cursorIndex + 1; tableau[cursorStack - NUM_FREECELLS][i] == selectedCard; i++) 116 + selectedQty++; 117 + } 118 + 119 + if (selectedCard > 11) 120 + { 121 + selectedCard -= 12; 122 + selectedQty = 4; 123 + } 124 + } 125 + 126 + return (!kb_On) && (progress < 10); 127 + }
+8
src/input.h
··· 1 + #ifndef input_include_file 2 + #define input_include_file 3 + 4 + #include <stdbool.h> 5 + 6 + bool doInput(); 7 + 8 + #endif
+4 -336
src/main.c
··· 1 1 #include <sys/rtc.h> 2 2 #include <fileioc.h> 3 - #include <graphx.h> 4 - #include <keypadc.h> 5 - 6 - #include "gfx/gfx.h" 7 - 8 3 #include <stdlib.h> 9 - #include <stdio.h> 10 4 #include <math.h> 11 5 #include <time.h> 12 - 13 - #define SAVE_VAR_NAME "KBFDWINS" 14 - 15 - #define BKGND_COLOR 2 16 - #define BORDER_COLOR 1 17 - #define TOP_BORDER 25 6 + #include <keypadc.h> 18 7 19 - #define FRAME_TIME 3277 20 - #define HOLD_TIME 2 21 - 22 - #define CARD_HEIGHT card1_height 23 - #define CARD_WIDTH card1_width 24 - #define CARD_SPACING 5 25 - #define CARD_VOFFSET 8 26 - #define NUM_FREECELLS 4 27 - #define NUM_TABLSLOTS 8 28 - #define TABL_STACK_SIZE 16 29 - #define LOCK_ICON_VOFFSET 17 30 - #define LOCK_ICON_HOFFSET 9 31 - #define FC_VPOS 50 32 - #define TABL_VPOS 100 33 - #define FC_HPOS 102 34 - #define TABL_HPOS 42 35 - 36 - #define TEXT_CHAR_WIDTH 8 37 - #define SELCARD_DISP_X 5 38 - #define SELCARD_DISP_Y 9 39 - #define NUMWINS_DISP_X (GFX_LCD_WIDTH - 5 - 3 * TEXT_CHAR_WIDTH) 40 - 41 - gfx_sprite_t* cardSprite[11]; 8 + #include "variables.h" 9 + #include "input.h" 10 + #include "drawing.h" 42 11 43 12 unsigned char tableau[NUM_TABLSLOTS][TABL_STACK_SIZE]; 44 13 unsigned char freeCells[NUM_FREECELLS]; 45 14 unsigned char fcUnlocked; 46 - 47 - unsigned char cursorStack; 48 - unsigned char cursorIndex; 49 - enum { SELECT, DROP } cursorMode; 50 - unsigned char selectedCard; 51 - unsigned char selectedQty; 52 - unsigned char orgStack; 53 - unsigned char orgIndex; 54 - 55 - unsigned char down, left, right, up; 56 - 57 15 unsigned char progress; 58 16 unsigned char numWins; 59 17 ··· 101 59 cursorIndex = 40 / NUM_TABLSLOTS - 1; 102 60 103 61 selectedCard = 1; 104 - } 105 - 106 - void drawCursor(unsigned char X, unsigned char Y) 107 - { 108 - if (cursorMode == SELECT) gfx_TransparentSprite(selcorner, X - 2, Y - 2); 109 - else gfx_TransparentSprite(drpcorner, X - 2, Y - 2); 110 - } 111 - 112 - void drawFrame() 113 - { 114 - gfx_FillScreen(BKGND_COLOR); 115 - gfx_SetColor(BORDER_COLOR); 116 - gfx_FillRectangle(0, 0, GFX_LCD_WIDTH, TOP_BORDER); 117 - 118 - for (unsigned char i = 0; i < NUM_FREECELLS; i++) 119 - { 120 - unsigned char cardX = FC_HPOS + i * (CARD_WIDTH + CARD_SPACING); 121 - 122 - if (freeCells[i] == 11) gfx_Sprite(freespace, cardX, FC_VPOS); 123 - else if (freeCells[i] > 11) gfx_Sprite(cardSprite[10], cardX, FC_VPOS); 124 - else gfx_Sprite(cardSprite[freeCells[i]], cardX, FC_VPOS); 125 - 126 - if (i >= fcUnlocked) 127 - { 128 - gfx_Sprite(lock, cardX + LOCK_ICON_HOFFSET, FC_VPOS + LOCK_ICON_VOFFSET); 129 - } 130 - 131 - if (i == cursorStack) drawCursor(cardX, FC_VPOS); 132 - } 133 - 134 - for (unsigned char i = 0; i < NUM_TABLSLOTS; i++) 135 - { 136 - for (unsigned char j = 0; j < TABL_STACK_SIZE; j++) 137 - { 138 - unsigned char cardX = TABL_HPOS + i * (CARD_WIDTH + CARD_SPACING); 139 - unsigned char cardY = TABL_VPOS + j * CARD_VOFFSET; 140 - 141 - if (progress < 10) if (i + NUM_FREECELLS == cursorStack) if (j == cursorIndex) 142 - drawCursor(cardX, cardY); 143 - 144 - const unsigned char x = tableau[i][j]; 145 - 146 - if (x == 11) break; 147 - if (x > 11) gfx_Sprite(cardSprite[10], cardX, cardY); 148 - else gfx_Sprite(cardSprite[x], cardX, cardY); 149 - } 150 - } 151 - 152 - if (progress < 10) 153 - { 154 - gfx_SetTextXY(SELCARD_DISP_X, SELCARD_DISP_Y); 155 - if (selectedCard != 11) 156 - { 157 - gfx_PrintUInt(selectedCard + 1, 1); 158 - if (selectedQty > 1) 159 - { 160 - gfx_PrintString(" x"); 161 - gfx_PrintUInt(selectedQty, 1); 162 - } 163 - } 164 - else gfx_PrintString("EMPTY"); 165 - } 166 - 167 - if (progress == 10) 168 - gfx_PrintStringXY("COMPLETE", GFX_LCD_WIDTH / 2 - 4 * TEXT_CHAR_WIDTH, SELCARD_DISP_Y); 169 - else if (cursorMode == SELECT) 170 - gfx_PrintStringXY("SELECT", GFX_LCD_WIDTH / 2 - 3 * TEXT_CHAR_WIDTH, SELCARD_DISP_Y); 171 - else gfx_PrintStringXY("DROP", GFX_LCD_WIDTH / 2 - 2 * TEXT_CHAR_WIDTH, SELCARD_DISP_Y); 172 - 173 - gfx_SetTextXY(NUMWINS_DISP_X, SELCARD_DISP_Y); 174 - gfx_PrintUInt(numWins, 3); 175 - 176 - gfx_BlitBuffer(); 177 - } 178 - 179 - bool canGrabCard() 180 - { 181 - if (cursorStack < NUM_FREECELLS) return freeCells[cursorStack] < 11; 182 - 183 - if (tableau[cursorStack - NUM_FREECELLS][0] > 11) return false; 184 - for (unsigned char i = cursorIndex + 1; i < TABL_STACK_SIZE; i++) 185 - { 186 - const unsigned char x = tableau[cursorStack - NUM_FREECELLS][i]; 187 - if (x == 11) return true; 188 - if (x != selectedCard) return false; 189 - } 190 - 191 - return true; 192 - } 193 - 194 - bool canDropCard() 195 - { 196 - if (cursorStack < NUM_FREECELLS) 197 - { 198 - const unsigned char x = freeCells[cursorStack]; 199 - if (cursorStack < fcUnlocked) 200 - { 201 - if (selectedQty == 1 || selectedQty == 4) return x == 11; 202 - else return x == selectedCard && selectedQty == 3; 203 - } 204 - else return false; 205 - } 206 - else if (cursorIndex == 0) return true; 207 - else return tableau[cursorStack - NUM_FREECELLS][cursorIndex - 1] == selectedCard; 208 - } 209 - 210 - bool checkTableauCollapse(unsigned char stackToCheck) 211 - { 212 - const unsigned char x = tableau[stackToCheck][0]; 213 - for (unsigned char i = 1; i < 5; i++) 214 - { 215 - const unsigned char y = tableau[stackToCheck][i]; 216 - if (i == 4 && y == 11) return true; 217 - if (y != x) return false; 218 - } 219 - 220 - return false; 221 - } 222 - 223 - void dropCard() 224 - { 225 - if (cursorStack == orgStack) return; 226 - 227 - unsigned char const prevProgress = progress; 228 - 229 - if (cursorStack < NUM_FREECELLS) 230 - { 231 - if (selectedQty == 1) freeCells[cursorStack] = selectedCard; 232 - else 233 - { 234 - progress++; 235 - freeCells[cursorStack] = 12 + selectedCard; 236 - } 237 - } 238 - else 239 - { 240 - for (unsigned char i = cursorIndex; i < cursorIndex + selectedQty; i++) 241 - tableau[cursorStack - NUM_FREECELLS][i] = selectedCard; 242 - if (checkTableauCollapse(cursorStack - NUM_FREECELLS)) 243 - { 244 - fcUnlocked++; 245 - progress++; 246 - tableau[cursorStack - NUM_FREECELLS][0] = selectedCard + 12; 247 - for (int i = 1; i < 4; i++) tableau[cursorStack - NUM_FREECELLS][i] = 11; 248 - } 249 - } 250 - 251 - if (orgStack < NUM_FREECELLS) freeCells[orgStack] = 11; 252 - else for (unsigned char i = orgIndex; i < orgIndex + selectedQty; i++) 253 - tableau[orgStack - NUM_FREECELLS][i] = 11; 254 - 255 - if (progress == 10 && prevProgress < 10) numWins++; 256 - } 257 - 258 - void maxCursorIndex() 259 - { 260 - if (cursorStack < NUM_FREECELLS) return; 261 - 262 - cursorIndex = TABL_STACK_SIZE - 1; 263 - while (tableau[cursorStack - NUM_FREECELLS][cursorIndex] == 11 && cursorIndex > 0) cursorIndex--; 264 - } 265 - 266 - bool cursorOnCollapsed() 267 - { 268 - return cursorStack < NUM_FREECELLS ? freeCells[cursorStack] > 11 269 - : tableau[cursorStack - NUM_FREECELLS][0] > 11; 270 - } 271 - 272 - bool cursorOnLocked() 273 - { 274 - return cursorStack >= fcUnlocked && cursorStack < NUM_FREECELLS; 275 - } 276 - 277 - bool doInput() 278 - { 279 - const bool prevSecond = kb_IsDown(kb_Key2nd); 280 - const bool prevEnter = kb_IsDown(kb_KeyEnter); 281 - const bool prevAlpha = kb_IsDown(kb_KeyAlpha); 282 - const bool prevClear = kb_IsDown(kb_KeyClear); 283 - 284 - kb_Scan(); 285 - 286 - up = kb_IsDown(kb_KeyUp) ? up + 1 : 0; 287 - down = kb_IsDown(kb_KeyDown) ? down + 1 : 0; 288 - left = kb_IsDown(kb_KeyLeft) ? left + 1 : 0; 289 - right = kb_IsDown(kb_KeyRight) ? right + 1 : 0; 290 - 291 - const bool select = (kb_IsDown(kb_Key2nd) && !prevSecond) || (kb_IsDown(kb_KeyEnter) && !prevEnter); 292 - const bool clear = (kb_IsDown(kb_KeyClear) && !prevClear) || (kb_IsDown(kb_KeyAlpha) && !prevAlpha); 293 - 294 - if (select) 295 - { 296 - if (cursorMode == SELECT && canGrabCard()) 297 - { 298 - orgStack = cursorStack; 299 - orgIndex = cursorIndex; 300 - cursorMode = DROP; 301 - } 302 - else if (canDropCard()) 303 - { 304 - dropCard(); 305 - cursorMode = SELECT; 306 - } 307 - else if (cursorStack == orgStack) 308 - { 309 - cursorMode = SELECT; 310 - } 311 - } 312 - else if (clear) cursorMode = SELECT; 313 - 314 - unsigned char prevCursorStack = cursorStack; 315 - 316 - if (down == 1 || down > HOLD_TIME) 317 - { 318 - cursorIndex++; 319 - } 320 - else if (left == 1 || left > HOLD_TIME) 321 - { 322 - do 323 - { 324 - if (cursorStack == 0) cursorStack = NUM_FREECELLS + NUM_TABLSLOTS - 1; // wrap 325 - else cursorStack--; 326 - } 327 - while (cursorOnCollapsed() || cursorOnLocked()); // skip useless stacks 328 - } 329 - else if (right == 1 || right > HOLD_TIME) 330 - { 331 - do 332 - { 333 - if (cursorStack > NUM_FREECELLS + NUM_TABLSLOTS - 2) cursorStack = 0; // wrap 334 - else cursorStack++; 335 - } 336 - while (cursorOnCollapsed() || cursorOnLocked()); // skip useless stacks 337 - } 338 - else if (up == 1 || up > HOLD_TIME) 339 - { 340 - if (cursorIndex > 0) cursorIndex--; 341 - } 342 - 343 - if (cursorStack < NUM_FREECELLS) 344 - { 345 - cursorIndex = 0; 346 - } 347 - else if (cursorMode == DROP) 348 - { 349 - // if dropping cards, the cursor should always be at the top of the stack it's on 350 - // except maxCursorIndex() doesn't work so well on empty tableau stacks 351 - if (cursorStack != orgStack) 352 - { 353 - if (tableau[cursorStack - NUM_FREECELLS][0] == 11) 354 - { 355 - cursorIndex = 0; 356 - } 357 - else 358 - { 359 - maxCursorIndex(); 360 - cursorIndex++; 361 - } 362 - } 363 - else cursorIndex = orgIndex; // also this makes it more clear if we are trying to drop 364 - // back on the original cards 365 - } 366 - else if (cursorStack != prevCursorStack) 367 - { 368 - maxCursorIndex(); 369 - } 370 - else 371 - { 372 - while (tableau[cursorStack - NUM_FREECELLS][cursorIndex] == 11 && cursorIndex > 0) cursorIndex--; 373 - } 374 - 375 - if (cursorMode == SELECT) 376 - { 377 - selectedQty = 1; 378 - if (cursorStack < NUM_FREECELLS) selectedCard = freeCells[cursorStack]; 379 - else 380 - { 381 - selectedCard = tableau[cursorStack - NUM_FREECELLS][cursorIndex]; 382 - for (int i = cursorIndex + 1; tableau[cursorStack - NUM_FREECELLS][i] == selectedCard; i++) 383 - selectedQty++; 384 - } 385 - 386 - if (selectedCard > 11) 387 - { 388 - selectedCard -= 12; 389 - selectedQty = 4; 390 - } 391 - } 392 - 393 - return (!kb_On) && (progress < 10); 394 62 } 395 63 396 64 bool run()
+111
src/ops.c
··· 1 + #include "ops.h" 2 + 3 + #include <stdlib.h> 4 + #include "variables.h" 5 + 6 + unsigned char cursorStack; 7 + unsigned char cursorIndex; 8 + enum cursorMode_t cursorMode; 9 + unsigned char selectedCard; 10 + unsigned char selectedQty; 11 + unsigned char orgStack; 12 + unsigned char orgIndex; 13 + 14 + bool canGrabCard() 15 + { 16 + if (cursorStack < NUM_FREECELLS) return freeCells[cursorStack] < 11; 17 + 18 + if (tableau[cursorStack - NUM_FREECELLS][0] > 11) return false; 19 + for (unsigned char i = cursorIndex + 1; i < TABL_STACK_SIZE; i++) 20 + { 21 + const unsigned char x = tableau[cursorStack - NUM_FREECELLS][i]; 22 + if (x == 11) return true; 23 + if (x != selectedCard) return false; 24 + } 25 + 26 + return true; 27 + } 28 + 29 + bool canDropCard() 30 + { 31 + if (cursorStack < NUM_FREECELLS) 32 + { 33 + const unsigned char x = freeCells[cursorStack]; 34 + if (cursorStack < fcUnlocked) 35 + { 36 + if (selectedQty == 1 || selectedQty == 4) return x == 11; 37 + else return x == selectedCard && selectedQty == 3; 38 + } 39 + else return false; 40 + } 41 + else if (cursorIndex == 0) return true; 42 + else return tableau[cursorStack - NUM_FREECELLS][cursorIndex - 1] == selectedCard; 43 + } 44 + 45 + bool checkTableauCollapse(unsigned char stackToCheck) 46 + { 47 + const unsigned char x = tableau[stackToCheck][0]; 48 + for (unsigned char i = 1; i < 5; i++) 49 + { 50 + const unsigned char y = tableau[stackToCheck][i]; 51 + if (i == 4 && y == 11) return true; 52 + if (y != x) return false; 53 + } 54 + 55 + return false; 56 + } 57 + 58 + void dropCard() 59 + { 60 + if (cursorStack == orgStack) return; 61 + 62 + unsigned char const prevProgress = progress; 63 + 64 + if (cursorStack < NUM_FREECELLS) 65 + { 66 + if (selectedQty == 1) freeCells[cursorStack] = selectedCard; 67 + else 68 + { 69 + progress++; 70 + freeCells[cursorStack] = 12 + selectedCard; 71 + } 72 + } 73 + else 74 + { 75 + for (unsigned char i = cursorIndex; i < cursorIndex + selectedQty; i++) 76 + tableau[cursorStack - NUM_FREECELLS][i] = selectedCard; 77 + if (checkTableauCollapse(cursorStack - NUM_FREECELLS)) 78 + { 79 + fcUnlocked++; 80 + progress++; 81 + tableau[cursorStack - NUM_FREECELLS][0] = selectedCard + 12; 82 + for (int i = 1; i < 4; i++) tableau[cursorStack - NUM_FREECELLS][i] = 11; 83 + } 84 + } 85 + 86 + if (orgStack < NUM_FREECELLS) freeCells[orgStack] = 11; 87 + else for (unsigned char i = orgIndex; i < orgIndex + selectedQty; i++) 88 + tableau[orgStack - NUM_FREECELLS][i] = 11; 89 + 90 + if (progress == 10 && prevProgress < 10) numWins++; 91 + } 92 + 93 + void maxCursorIndex() 94 + { 95 + if (cursorStack < NUM_FREECELLS) return; 96 + 97 + cursorIndex = TABL_STACK_SIZE - 1; 98 + while (tableau[cursorStack - NUM_FREECELLS][cursorIndex] == 11 && cursorIndex > 0) cursorIndex--; 99 + } 100 + 101 + bool cursorOnCollapsed() 102 + { 103 + return cursorStack < NUM_FREECELLS ? freeCells[cursorStack] > 11 104 + : tableau[cursorStack - NUM_FREECELLS][0] > 11; 105 + } 106 + 107 + bool cursorOnLocked() 108 + { 109 + return cursorStack >= fcUnlocked && cursorStack < NUM_FREECELLS; 110 + } 111 +
+16
src/ops.h
··· 1 + #ifndef ops_include_file 2 + #define ops_include_file 3 + 4 + #include <stdbool.h> 5 + 6 + bool canGrabCard(); 7 + bool canDropCard(); 8 + bool checkTableauCollapse(unsigned char stackToCheck); 9 + 10 + void dropCard(); 11 + void maxCursorIndex(); 12 + 13 + bool cursorOnCollapsed(); 14 + bool cursorOnLocked(); 15 + 16 + #endif
+43
src/variables.h
··· 1 + #ifndef variables_include_file 2 + #define variables_include_file 3 + 4 + #define SAVE_VAR_NAME "KBFDWINS" 5 + 6 + #define BKGND_COLOR 2 7 + #define BORDER_COLOR 1 8 + #define TOP_BORDER 25 9 + 10 + #define FRAME_TIME 3277 11 + #define HOLD_TIME 2 12 + 13 + #define NUM_FREECELLS 4 14 + #define NUM_TABLSLOTS 8 15 + #define TABL_STACK_SIZE 16 16 + #define LOCK_ICON_VOFFSET 17 17 + #define LOCK_ICON_HOFFSET 9 18 + #define FC_VPOS 50 19 + #define TABL_VPOS 100 20 + #define FC_HPOS 102 21 + #define TABL_HPOS 42 22 + 23 + #define TEXT_CHAR_WIDTH 8 24 + #define SELCARD_DISP_X 5 25 + #define SELCARD_DISP_Y 9 26 + #define NUMWINS_DISP_X (GFX_LCD_WIDTH - 5 - 3 * TEXT_CHAR_WIDTH) 27 + 28 + extern unsigned char tableau[NUM_TABLSLOTS][TABL_STACK_SIZE]; 29 + extern unsigned char freeCells[NUM_FREECELLS]; 30 + extern unsigned char fcUnlocked; 31 + 32 + extern unsigned char cursorStack; 33 + extern unsigned char cursorIndex; 34 + extern enum cursorMode_t { SELECT, DROP } cursorMode; 35 + extern unsigned char selectedCard; 36 + extern unsigned char selectedQty; 37 + extern unsigned char orgStack; 38 + extern unsigned char orgIndex; 39 + 40 + extern unsigned char progress; 41 + extern unsigned char numWins; 42 + 43 + #endif