Added ai modes. Altered output of highscores to allow possible parsing with tools easier

This commit is contained in:
Tiehuis
2015-02-25 14:51:48 +13:00
parent 2d9f89f339
commit cf1a147078
7 changed files with 67 additions and 23 deletions
+22 -8
View File
@@ -1,11 +1,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include "highscore.h"
#include "options.h"
void print_usage(void)
{
printf("usage: 2048 [-cCaArh] [-s SIZE] [-b RATE]\n");
printf("usage: 2048 [-cCaAiIrh] [-s SIZE] [-b RATE]\n");
}
@@ -19,8 +20,10 @@ struct gameoptions* gameoptions_default(void)
opt->grid_width = DEFAULT_GRID_WIDTH;
opt->spawn_value = DEFAULT_SPAWN_VALUE;
opt->spawn_rate = DEFAULT_SPAWN_RATE;
opt->enable_color = DEFAULT_COLOR_TOGGLE;
opt->animate = DEFAULT_ANIMATE_TOGGLE;
opt->enable_color = DEFAULT_COLOR_FLAG;
opt->animate = DEFAULT_ANIMATE_FLAG;
opt->ai = DEFAULT_AI_FLAG;
opt->interactive = DEFAULT_INTERACTIVE_FLAG;
return opt;
}
@@ -33,19 +36,27 @@ void gameoptions_destroy(struct gameoptions *opt)
struct gameoptions* parse_options(struct gameoptions *opt, int argc, char **argv)
{
int c;
while ((c = getopt(argc, argv, "aArcCh:s:b:")) != -1) {
while ((c = getopt(argc, argv, "aArcCiIhHs:b:")) != -1) {
switch (c) {
case 'a':
opt->animate = 1;
opt->animate = true;
break;
case 'A':
opt->animate = 0;
opt->animate = false;
break;
case 'c':
opt->enable_color = 1;
opt->enable_color = true;
break;
case 'C':
opt->enable_color = 0;
opt->enable_color = false;
break;
case 'i':
opt->ai = true;
opt->interactive = false;
break;
case 'I':
opt->ai = true;
opt->interactive = true;
break;
case 's':;
/* Stick with square for now */
@@ -64,6 +75,9 @@ struct gameoptions* parse_options(struct gameoptions *opt, int argc, char **argv
case 'h':
print_usage();
exit(0);
case 'H':
printf("%ld\n", highscore_load(NULL));
exit(0);
}
}