Add -r option to man and readme and make reset option actually prompt. Remove hardcoded merge_goal value.

This commit is contained in:
Tiehuis
2015-02-23 16:00:14 +13:00
parent 40f6419c55
commit 2d9af767d1
6 changed files with 51 additions and 19 deletions

View File

@@ -44,7 +44,34 @@ static const char* highscore_retrieve_file(void)
void highscore_reset(void)
{
const char *hsfile = highscore_retrieve_file();
const size_t resp_length = 16;
char resp[resp_length];
printf("Are you sure you want to reset your scores? Y(es) or N(o)\n");
while (1) {
fgets(resp, resp_length, stdin);
const size_t sl = strlen(resp);
if (sl < resp_length)
resp[sl - 1] = '\0';
if (!strncmp(resp, "Yes", resp_length) ||
!strncmp(resp, "Y", resp_length) ||
!strncmp(resp, "yes", resp_length) ||
!strncmp(resp, "y", resp_length) )
goto reset_scores;
else
if (!strncmp(resp, "No", resp_length) ||
!strncmp(resp, "N", resp_length) ||
!strncmp(resp, "no", resp_length) ||
!strncmp(resp, "n", resp_length) )
return;
printf("Please enter Yes or No\n");
}
reset_scores:;
FILE *fd = fopen(hsfile, "w+");
fprintf(fd, "%d", 0);
fclose(fd);

View File

@@ -1,7 +1,6 @@
#include "assert.h"
#include "merge.h"
#define MERGE_GOAL 11
#define MERGE_GOAL (int)(sizeof(merge_values)/sizeof(merge_values[0]))
const long merge_values[] = {
0, 2, 4, 8, 16, 32, 64, 128, 256, 512,

View File

@@ -8,7 +8,7 @@
/* This should return the value of a given index. 0 should default to 0 (empty) */
long merge_value(const int v1);
/* This should return the goal value */
/* This should return the goal index value */
long merge_goal(void);
/* Return if a merge is possible between two indices */

View File

@@ -1,11 +1,10 @@
#include "assert.h"
#include "merge.h"
#define MERGE_GOAL 17
#define MERGE_GOAL (int)(sizeof(merge_values)/sizeof(merge_values[0]))
const long merge_values[] = {
0, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144,
233, 377, 610, 987, 1597, 2584
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144,
233, 377, 610, 987, 1597
};
inline long merge_value(const int v1)