diff options
Diffstat (limited to 'source/app.d')
-rw-r--r-- | source/app.d | 80 |
1 files changed, 80 insertions, 0 deletions
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; + } + } +} |