1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
struct scrabble loaddata(games players[4], scrabble variable){
int k, j, l;
FILE *load;
if ((load=fopen("scrabble.txt", "r"))==NULL){
printf("No existing save game. Loading new game\n");
variable.n=100;
variable.p = 1;
variable.no = 0;
strcpy(variable.letter, "{'A','A','A','A','A','A','A','A','A','B','B','C','C','D','D','D','D','E','E','E','E','E','E','E','E','E','E','E','E','F','F','G','G','G','H','H','I','I','I','I','I','I','I','I','I','J','K','L','L','L','L','M','M','N','N','N','N','N','N','O','O','O','O','O','O','O','O','P','P','Q','R','R','R','R','R','R','S','S','S','S','T','T','T','T','T','T','U','U','U','U','V','V','W','W','X','Y','Y','Z',' ',' '}");
}else{
fscanf(load, "%d\n", &variable.n);
fscanf(load, "%d\n", &variable.p);
fscanf(load, "%d\n", &variable.no);
for(k=1;k<=variable.no;k++){
fscanf(load,"%c\n",players[k].tiles);
fscanf(load,"%d\n",&players[k].score);
}
for(k=1;k<=100;k++){
fscanf(load, "%d\n", variable.letter[k]);
}
for(k=0; k<24; k++){
for(j=0; j<=12; j++){
if (k==0 && j!=12){
fscanf(load, "____");
}
if (j==0 && k!=0){
fscanf(load, "|");
}
if (k==1 && j!=0 && j!=1){
fscanf(load, " %d", j-2);
}
if (j==1 && k%2==0 && k!=0){
fscanf(load, "%d", k/2 - 1);
}
if (k>1 && k%2==0 && j>1){
if(j==2){
if(k==22){ fscanf(load, " %c", variable.board[k][j]);
}else fscanf(load, " %c", variable.board[k][j]);
}else fscanf(load, " %c", variable.board[k][j]);
}
}
fprintf(load, "\n");
}
fclose(load);
}
return scrabble variable;
}
|