home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c100 / 1.ddi / OOPWLD.ZIP / BINTREE / SMAP.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-10  |  931 b   |  42 lines

  1. // SMAP.CPP
  2. #include "smap.hpp"
  3. #include <stdio.h>
  4. #include <conio.h>  // borland
  5. #include <stdlib.h>
  6. #define cprintf printf
  7. #define cputs puts
  8.  
  9. screenmap::screenmap(int ht, int wid) : width(wid), height(ht) {
  10.   map = new char*[height];
  11.   for(int i = 0; i < height; i++) {
  12.     map[i] = new char[width + 1];
  13.     for(int j = 0; j < width; j++)
  14.       map[i][j] = ' ';
  15.     map[i][j] = 0;  // null terminator
  16.   }
  17. }
  18.  
  19. screenmap::~screenmap() {
  20.   for(int i = 0; i < height; i++)
  21.     delete map[i];
  22.   delete map;
  23. }
  24.  
  25. char & screenmap::operator() (int h, int w) {
  26.   static char dummy;
  27.   if(w < 0 || w >= width) {
  28.     fprintf(stderr,"operator() width out of range");
  29.     return dummy;
  30.   }
  31.   if(h < 0 || h >= height) {
  32.     fprintf(stderr,"operator() height out of range");
  33.     return dummy;
  34.   }
  35.   return map[h][w];
  36. }
  37.  
  38. void screenmap::display() { 
  39.   for(int i = 0; i < height; i++) 
  40.     cputs(map[i]);
  41. }
  42.