home *** CD-ROM | disk | FTP | other *** search
/ Quake 'em / QUAKEEM.BIN / quake / programs / qube / temp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-07  |  1.7 KB  |  97 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4. #include "area.h"
  5.  
  6. static void DumpArea(Area *a);
  7. static void DumpSpace(Area *a);
  8.  
  9. main()
  10. {
  11.     int x1, y1, x2, y2;
  12.         Area *area1 = AreaCreate();
  13.  
  14.     clrscr();
  15.         randomize();
  16.  
  17.     while (1) {
  18.         x1 = random(80);
  19.         x2 = random(80);
  20.         y1 = random(24);
  21.         y2 = random(24);
  22.  
  23.         if (x1 > x2) {
  24.             int t = x1;
  25.             x1 = x2;
  26.             x2 = t;
  27.         }
  28.         if (y1 > y2) {
  29.             int t = y1;
  30.             y1 = y2;
  31.             y2 = t;
  32.         }
  33.  
  34.         gotoxy(1, 25);
  35.         cprintf("(%d,%d)-(%d,%d)        ", x1, y1, x2, y2);
  36.  
  37.         textattr(0x70);
  38.                 gotoxy(x1+1, y1+1);
  39.         cprintf("[");
  40.         gotoxy(x1+1, y2);
  41.         cprintf("{");
  42.         gotoxy(x2, y1+1);
  43.         cprintf("]");
  44.         gotoxy(x2, y2);
  45.         cprintf("}");
  46.         textattr(0x07);
  47.  
  48.         gotoxy(1, 25);
  49.                 if (getch() == 27) exit(1);
  50.  
  51.         if (random(3))
  52.             area1 = AreaUnionRect(area1, x1, y1, x2, y2);
  53.         else
  54.             area1 = AreaSubRect(area1, x1, y1, x2, y2);
  55.  
  56.                 DumpSpace(area1);
  57.     }
  58. }
  59.  
  60. static void DumpArea(Area *a)
  61. {
  62.         int i;
  63.  
  64.     printf("%d\n", a->count);
  65.  
  66.     for (i = 0; i < a->count; i++)
  67.         printf("(%d,%d)-(%d,%d)\n", a->rects[i].x1, a->rects[i].y1, a->rects[i].x2, a->rects[i].y2);
  68.  
  69.     printf("***\n");
  70. }
  71.  
  72. static void DumpSpace(Area *a)
  73. {
  74.     int aspace[25][80];
  75.     int x, y, i;
  76.  
  77.         for (y = 0; y < 23; y++)
  78.         for (x = 0; x < 80; x++)
  79.             aspace[y][x] = 0;
  80.     for (i = 0; i < a->count; i++)
  81.         for (y = a->rects[i].y1; y < a->rects[i].y2; y++)
  82.             for (x = a->rects[i].x1; x < a->rects[i].x2; x++)
  83.                 aspace[y][x]++;
  84.  
  85.     for (y = 0; y < 23; y++) {
  86.         for (x = 0; x < 79; x++) {
  87.             gotoxy(x+1, y+1);
  88.             if (aspace[y][x]) cprintf("%d", aspace[y][x]);
  89.             else cprintf(" ");
  90.         }
  91.     }
  92.  
  93.     gotoxy(1, 25);
  94.         if (getch() == 27) exit(1);
  95. }
  96.  
  97.