Solitaire for the TI-84 Plus CE!
at main 120 lines 2.5 kB view raw
1// Kabufuda Solitaire / KBFDSLTR for the TI-84 Plus CE 2// Copyright (C) 2024 euphory 3// 4// This program is free software: you can redistribute it and/or modify 5// it under the terms of the GNU General Public License as published by 6// the Free Software Foundation, either version 3 of the License, or 7// (at your option) any later version. 8// 9// This program is distributed in the hope that it will be useful, 10// but WITHOUT ANY WARRANTY; without even the implied warranty of 11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12// GNU General Public License for more details. 13// 14// You should have received a copy of the GNU General Public License 15// along with this program. If not, see <https://www.gnu.org/licenses/>. 16 17#include "save.h" 18 19#include <sys/rtc.h> 20#include <fileioc.h> 21#include <stdlib.h> 22 23#include "variables.h" 24#include "drawing.h" 25 26void deal() 27{ 28 srand(rtc_Time()); 29 30 for (unsigned char i = 0; i < 10; i++) 31 { 32 for (unsigned char j = 0; j < 4; j++) 33 { 34 while (true) 35 { 36 unsigned char dStack = rand() % 8; 37 unsigned char dIndex = rand() % 5; 38 39 if (tableau[dStack][dIndex] == 11) 40 { 41 tableau[dStack][dIndex] = i; 42 break; 43 } 44 } 45 } 46 } 47 48 fcUnlocked = 1; 49 progress = 0; 50 51 animateDeal(); 52} 53 54void load() 55{ 56 unsigned char saveHandle = ti_Open(SAVE_VAR_NAME, "r"); 57 58 if (saveHandle == 0) 59 { 60 // no save present 61 deal(); 62 } 63 else 64 { 65 // load save 66 ti_Read(freeCells, 1, NUM_FREECELLS, saveHandle); 67 ti_Read(tableau, 1, NUM_TABLSLOTS * TABL_STACK_SIZE, saveHandle); 68 69 // how far along does that make us? 70 progress = 0; 71 fcUnlocked = 1; 72 for (unsigned char i = 0; i < NUM_FREECELLS; i++) 73 { 74 if (freeCells[i] > 11) 75 { 76 progress++; 77 } 78 } 79 for (unsigned char i = 0; i < NUM_TABLSLOTS; i++) 80 { 81 if (tableau[i][0] > 11) 82 { 83 progress++; 84 fcUnlocked++; 85 } 86 } 87 } 88 89 ti_Close(saveHandle); 90} 91 92void save() 93{ 94 unsigned char saveHandle = ti_Open(SAVE_VAR_NAME, "w"); 95 96 ti_Write(freeCells, 1, NUM_FREECELLS, saveHandle); 97 ti_Write(tableau, 1, NUM_TABLSLOTS * TABL_STACK_SIZE, saveHandle); 98 99 ti_Close(saveHandle); 100} 101 102void deleteSave() 103{ 104 ti_Delete(SAVE_VAR_NAME); 105} 106 107void loadWins() 108{ 109 numWins = 0; 110 unsigned char winsHandle = ti_Open(WINS_VAR_NAME, "r"); 111 if (winsHandle != 0) ti_Read(&numWins, 1, 1, winsHandle); 112 ti_Close(winsHandle); 113} 114 115void saveWins() 116{ 117 unsigned char const winsHandle = ti_Open(WINS_VAR_NAME, "w"); 118 ti_Write(&numWins, 1, 1, winsHandle); 119 ti_Close(winsHandle); 120}