From b912d3d9409aab2954cd30db2c7a2bb7e6e896d4 Mon Sep 17 00:00:00 2001 From: glenda Date: Fri, 1 Jan 1988 06:08:06 +0000 Subject: [PATCH] little basic programs! --- maze.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ mkfile | 13 +++++++++++++ pong.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 maze.c create mode 100644 mkfile create mode 100644 pong.c diff --git a/maze.c b/maze.c new file mode 100644 index 0000000000000000000000000000000000000000..b43a2ff5299b8599d146d6010b4783baa851343f --- /dev/null +++ b/maze.c @@ -0,0 +1,46 @@ +#include +#include +#include + +// FIXME: assumes vga font +int +getcols(void) +{ + int x1, y1, x2, y2; + FILE* fp; + + fp = fopen("/dev/wctl", "r"); + + fscanf(fp, "%d %d %d %d", &x1, &y1, &x2, &y2); + + fclose(fp); + + return (x2 - x1) / 8 / 2 * 2 - 4; +} + +void +main(void) +{ + while(1) + { + int cols = getcols(); + char* outbuf1 = calloc(cols + 1, 1); + char* outbuf2 = calloc(cols + 1, 1); + for (int i = 0; i < (cols / 2); i ++) + { + if (rand() % 2) + { + strcat(outbuf1, " /"); + strcat(outbuf2, "/ "); + } + else + { + strcat(outbuf1, "\\ "); + strcat(outbuf2, " \\"); + } + } + print("%s\n%s\n", outbuf1, outbuf2); + free(outbuf1); + free(outbuf2); + } +} diff --git a/mkfile b/mkfile new file mode 100644 index 0000000000000000000000000000000000000000..cb2c93dc4e13254c685a8032a37e62cab04765a7 --- /dev/null +++ b/mkfile @@ -0,0 +1,13 @@ + +#include + +int score1, score2; + +void +usage(void) +{ + fprint(2,"usage: %s [-p points]\n", argv0); + exits("usage"); +} + +void +do_round(void) +{ + +} + +void +main(int argc, char* argv[]) +{ + int playto = 10; + + ARGBEGIN{ + case 'p': + playto = atoi(EARGF(usage())); + if (playto == 0) + usage(); + break; + default: + usage(); + break; + } ARGEND + + if (argv[0]) + usage(); + + print("playing to %d points\n", playto); + + score1 = 0; + score2 = 0; + + while (score1 < playto && score2 < playto) + do_round(); + + if (score1 > score2) + print("Player 1 wins!\n"); + else + print("Player 2 wins!\n"); +}