home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / netds / rpc / mazelord / readsgrd.c < prev    next >
C/C++ Source or Header  |  1996-01-07  |  4KB  |  133 lines

  1. /***********************************************************************
  2. File:   ReadSGrd.c
  3.  
  4. Abstract:
  5.  
  6.     This module contains the entrypoint for ReadSubGrids(). This is a file
  7.     to read in the text versions of the various subgrids which users can
  8.     choose from. The subgrids are read into SubGrids[], and translated into
  9.     their various cells with flags of NORTH SOUTH EAST WEST saying what
  10.     walls are present for that cell.
  11.  
  12.     COMMENTS:   This file needs more error checking put into it. In particular,
  13.                 an error routine with popups for missing or invalid files.
  14.  
  15.  
  16. Contents:
  17.  
  18.     ReadSubGrids() -- Reads subgrids in from the resources.
  19.  
  20. ************************************************************************/
  21.  
  22. #include "winmaze.h"
  23. #include "mazproto.h"
  24.  
  25.  
  26.  
  27. /*=====================================================================
  28. Function:   ReadSubGrids()
  29.  
  30. Inputs:     none
  31.  
  32. Outputs:    returns success/failure
  33.  
  34. Abstract:
  35.     This will read in subgrids from the linked resources, convert them
  36.     from text to bytes with walls, filling the subgrid structre.
  37. ======================================================================*/
  38.  
  39. int ReadSubGrids(
  40.     VOID
  41.     )
  42. {
  43.     char GridName[]="SUBGRID00";
  44.     HRSRC hGrid;
  45.     LPSTR lpBuff;
  46.     HGLOBAL hMem;
  47.  
  48.     int i,j,k,m;
  49.  
  50.     //
  51.     // Initialize all cells of each subgrid to 0.
  52.     //
  53.     for (k=0;k<NUM_SUBGRIDS;k++) {
  54.         for (i=0;i<X_CELLS_PER_SUBGRID;i++) {
  55.             for (j=0;j<Y_CELLS_PER_SUBGRID;j++) {
  56.                 SubGrids[k].Cell[j][i] = 0;
  57.                 }
  58.             }
  59.         }
  60.  
  61.     //
  62.     // Fill Subgrids with info from SubGrixx.TXT files
  63.     //
  64.     for(i=0;i<NUM_SUBGRIDS;i++) {       // Loop through all subgrids
  65.         GridName[7]=(char) ('0'+(i/10));
  66.         GridName[8]=(char) ('0'+(i%10));
  67.         hGrid = FindResource(hInst,(LPCTSTR)GridName,(LPCTSTR)RT_RCDATA);
  68.         if (hGrid == (HRSRC)NULL) {
  69.             MessageBox((HWND)NULL,GetStringRes(IDS_LDSGRIDRESFAIL),"ReadSubGrids",
  70.                        MB_ICONEXCLAMATION|MB_APPLMODAL);
  71.             }
  72.  
  73.  
  74.         hMem = (HGLOBAL) LoadResource(hInst,hGrid);
  75.         lpBuff = LockResource(hMem);
  76.         if (lpBuff == (LPSTR)NULL) {
  77.             MessageBox((HWND)NULL,GetStringRes(IDS_LDSGRIDRESFAIL),"ReadSubGrids",
  78.                          MB_ICONEXCLAMATION|MB_APPLMODAL);
  79.             }
  80.  
  81.  
  82.  
  83.         j=0;
  84.  
  85.     //
  86.     // For each file, loop through all lines. The top line
  87.     // is ONLY the North wall for the first row.
  88.     // The sixth row in the file will be the fifth row of the subgrid.
  89.     //
  90.     for(m=0;m<6;m++) {
  91.         //
  92.         // Get the NORTH/SOUTH walls.
  93.         //
  94.         for (k=1;k<2*X_CELLS_PER_SUBGRID;k+=2) {
  95.             if (lpBuff[k] == '_') {
  96.                 if (j<Y_CELLS_PER_SUBGRID) {
  97.                     SubGrids[i].Cell[k/2][j] |= NORTH;
  98.                     }
  99.                 if (j>0) {
  100.                     SubGrids[i].Cell[k/2][j-1] |= SOUTH;
  101.                     }
  102.                 }
  103.             }
  104.  
  105.         //
  106.         // Get the EAST/WEST walls.
  107.         //
  108.         if (j > 0){
  109.             for (k=0;k<2*X_CELLS_PER_SUBGRID+1;k+=2) {
  110.                 if (lpBuff[k] == '|') {
  111.                     if ((k/2) < X_CELLS_PER_SUBGRID){
  112.                         SubGrids[i].Cell[k/2][j-1] |= WEST;
  113.                         }
  114.                     if (((int) (k/2))>0) {
  115.                         SubGrids[i].Cell[(k/2)-1][j-1] |= EAST;
  116.                         }
  117.                     }
  118.                 }
  119.             }
  120.  
  121.         while (*lpBuff != '\0') {
  122.             lpBuff++;
  123.             }
  124.         lpBuff++;
  125.  
  126.         j++;
  127.         }
  128.     }
  129.  
  130.     return(1);
  131. }
  132.  
  133.