Added help command and removed warnings
This commit is contained in:
parent
499a2525ef
commit
7b9ef39ac7
|
@ -3,13 +3,14 @@
|
||||||
#include <stdio.h> /* for printf */
|
#include <stdio.h> /* for printf */
|
||||||
#include <stdlib.h> /* for malloc */
|
#include <stdlib.h> /* for malloc */
|
||||||
#include <termios.h>/* */
|
#include <termios.h>/* */
|
||||||
|
#include <time.h> /* for time */
|
||||||
#include <unistd.h> /* for getopts */
|
#include <unistd.h> /* for getopts */
|
||||||
|
|
||||||
// Repeat an expression y, x times */
|
// Repeat an expression y, x times */
|
||||||
#define ITER(x, y)\
|
#define ITER(x, expr)\
|
||||||
do {\
|
do {\
|
||||||
int i;\
|
int i;\
|
||||||
for (i = 0; i < x; i++){y;}\
|
for (i = 0; i < x; i++){ expr;}\
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
/* Allocates a square pointer of array of arrays onto heap */
|
/* Allocates a square pointer of array of arrays onto heap */
|
||||||
|
@ -177,7 +178,8 @@ void rand_block()
|
||||||
void draw_grid()
|
void draw_grid()
|
||||||
{
|
{
|
||||||
printf("SCORE: %d ", s);
|
printf("SCORE: %d ", s);
|
||||||
printf(sl ? "(+%d)\n" : "\n", sl);
|
if (sl) printf("(+%d)", sl);
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
// alter this SZ + 1 to match abitrary grid size
|
// alter this SZ + 1 to match abitrary grid size
|
||||||
ITER(SZ + 1, printf("-----"));
|
ITER(SZ + 1, printf("-----"));
|
||||||
|
@ -218,7 +220,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
/* parse options */
|
/* parse options */
|
||||||
int c;
|
int c;
|
||||||
while ((c = getopt(argc, argv, "s:b:")) != -1) {
|
while ((c = getopt(argc, argv, "hs:b:")) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
// different board sizes
|
// different board sizes
|
||||||
case 's':
|
case 's':
|
||||||
|
@ -230,6 +232,18 @@ int main(int argc, char **argv)
|
||||||
case 'b':
|
case 'b':
|
||||||
n_blocks = atoi(optarg);
|
n_blocks = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
|
case 'h':
|
||||||
|
printf("Controls:\n"
|
||||||
|
" hjkl, wasd Movement\n"
|
||||||
|
" q Quit\n"
|
||||||
|
"\n"
|
||||||
|
"Usage:\n"
|
||||||
|
" 2048 [options]\n"
|
||||||
|
"\n"
|
||||||
|
"Options:\n"
|
||||||
|
" -b <size> Set the grid border length\n"
|
||||||
|
" -s <rate> Set the block spawn rate\n");
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user