#include "c.h"

/**
 * In a loop do:
 * 1) Use the provided R() (in util.c) function to pick:
 *   - A random x coordinate
 *   - A random y coordinate
 *   - A random width between 1-20
 *   - A random height between 1-10
 *   - A random color (0-7)
 * 
 * 2) Then draw a box of that width and height and color with the upper left
 *    corner at the randomly picked x,y position.
 * 3) Use the 'usleep' function (man 3 usleep) to wait for about 1/20 of a
 *    second.  There are 1,000,000 microseconds in a second.
 * 4) Attempt to read a character with getch() and if it is a 'q' or 'Q',
 *    stop the loop and exit the program.
 */
int main(void)
{
  int ch;
  init_curses();
  nodelay(stdscr,TRUE);

  do {
    int x = R(0,COLS-1);
    int y = R(0,LINES-1);
    int w = R(1,20);
    int h = R(1,10);
    int color = R(0,7);

    int rev = R(0,10) > 5;
    for(int r = 0; r < h; r++) {
      for(int c = 0; c < w; c++) {
	if (rev) {
	  mvaddch(y+r,x+c,' ' | COLOR_PAIR(color*8+COLOR_BLACK)|A_REVERSE);
	} else {
	  mvaddch(y+r,x+c,' ' | COLOR_PAIR(COLOR_WHITE*8+color));
	}
      }
      refresh();
    }
    usleep(50000);
    ch = getch();
  } while (ch != 'q' && ch != 'Q');

  leave_curses();
  return 0;
}
