From 5f974d83677fc6d7ee229e6a2e2720a45677e4e0 Mon Sep 17 00:00:00 2001
From: Holden Rohrer
Date: Tue, 3 Aug 2021 00:40:58 -0400
Subject: created drocks
---
source/app.d | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 80 insertions(+)
create mode 100644 source/app.d
(limited to 'source/app.d')
diff --git a/source/app.d b/source/app.d
new file mode 100644
index 0000000..4006188
--- /dev/null
+++ b/source/app.d
@@ -0,0 +1,80 @@
+import deimos.ncurses;
+import std.string : toStringz;
+import core.stdc.locale;
+import std.format;
+import board;
+import spots;
+
+void main()
+{
+ setlocale(LC_CTYPE, ""); // ncurses locales are weird
+
+ auto stdscr = initscr();
+ scope (exit)
+ endwin();
+ cbreak(); // disables line buffering for input
+ noecho(); // input doesn't display on-screen
+ intrflush(stdscr, true);
+ keypad(stdscr, true); // allows arrow keys to work
+ scrollok(stdscr, true); // allows scrolling in up/down arrows
+ nonl(); // "return" goes through input
+
+ int x;
+ int y;
+ getmaxyx(stdscr, y, x);
+
+ auto overlay = new OverlaySource(new RandomSource());
+ auto board = new Board(overlay);
+ auto disp = new BoardDisplay(board, stdscr);
+ disp.print();
+ int rocks = 0;
+ disp.status = "0";
+ refresh();
+
+ outer: while (true)
+ {
+ auto c = getch();
+ switch (c)
+ {
+ case ',':
+ case KEY_UP:
+ disp.up();
+ break;
+ case 'o':
+ case KEY_DOWN:
+ disp.down();
+ break;
+ case 'e':
+ case KEY_RIGHT:
+ disp.right();
+ break;
+ case 'a':
+ case KEY_LEFT:
+ disp.left();
+ break;
+ case KEY_RESIZE:
+ disp.getdims();
+ break;
+ case ' ':
+ if (overlay[disp.y, disp.x].isRock())
+ {
+ overlay[disp.y, disp.x] = Spot(' ');
+ rocks++;
+ disp.status = format("%d", rocks);
+ disp.print();
+ }
+ else if (rocks > 0)
+ {
+ overlay[disp.y, disp.x] = Spot('*');
+ rocks--;
+ disp.status = format("%d", rocks);
+ disp.print();
+ }
+ break;
+ case 'q':
+ break outer;
+ default:
+ continue;
+ }
+ }
+}
--
cgit