diff options
author | Frederick Yin <fkfd@fkfd.me> | 2022-06-01 18:32:49 +0800 |
---|---|---|
committer | Frederick Yin <fkfd@fkfd.me> | 2022-06-01 18:34:43 +0800 |
commit | 3b8ecc1d1864f4368e1621284b482996ed87b72f (patch) | |
tree | 29b2cdeba87ffdce58371e0fecdaa53f8e9232d2 /sirtet.c | |
parent | 6912d144a5a7ae5abf2480a2a9a8842a4907edf4 (diff) |
-h, -w, -p arguments
Diffstat (limited to 'sirtet.c')
-rw-r--r-- | sirtet.c | 42 |
1 files changed, 36 insertions, 6 deletions
@@ -1,5 +1,7 @@ #include <stdlib.h> #include <stdbool.h> +#include <stdio.h> +#include <getopt.h> #include <time.h> #include <locale.h> #include <ncurses.h> @@ -60,11 +62,7 @@ int clearfull(char** map, int mapH, int mapW) { return (rtc_count * mapW + ctc_count * mapH - rtc_count * ctc_count); } -void sirtet() { - const int H = 8; // canvas height - const int W = 8; // canvas width - const int P = 3; // maximum # of pieces at hand - +void sirtet(int H, int W, int P) { // init memory and game state char** map = malloc(H * sizeof(char*)); for (int r = 0; r < H; r++) { @@ -241,6 +239,38 @@ void sirtet() { } int main(int argc, char *argv[]) { - sirtet(); + int H = 8; // map height + int W = 8; // map width + int P = 3; // max # of pieces at hand + + // handle CLI arguments + int opt = 0; + while (opt != -1) { + opt = getopt(argc, argv, "h:w:p:"); + switch (opt) { + case 'h': + sscanf(optarg, "%d", &H); + if (H < 4) { + printf("Map height cannot be less than 4\n"); + return 1; + } + break; + case 'w': + sscanf(optarg, "%d", &W); + if (W < 4) { + printf("Map width cannot be less than 4\n"); + return 1; + } + break; + case 'p': + sscanf(optarg, "%d", &P); + if (P < 1) { + printf("You must wield at least one piece\n"); + return 1; + } + break; + } + } + sirtet(H, W, P); return 0; } |