TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Jonathon Weller
from: Kurt Kuzba
date: 1998-12-25 00:35:26
subject: Array Problem

JW>   store characters in an array and make a map out of them.
   The curley braces in here need moving. I saved a few lines
   to fit it all into a single message.
   See if this gives you any ideas:
 /*   GAMEROOM.C   public domain   Kurt Kuzba   12/25/1998 */
#include 
#include 
typedef struct { int dat[5][5]; } Gameroom;
typedef struct { Gameroom XY[3][4]; } Playfield;
void init_rooms(Playfield *Grid)
{
   char *RX = {
      "####################"
      "#..$##...##...##...#"
      "#..................#"
      "#...##...##...##$..#"
      "##.#########.#######"
      "##.#########.#######"
      "#...##..$##...##...#"
      "#........##........#"
      "#...##...##...##...#"
      "#######.#########.##"
      "#######.#########.##"
      "#.$.##...##..$##...#"
      "#..................#"
      "#...##...##...##...#"
      "####################" };
   int x, ry, lx, ly;
   for(x = 0; x < 300; x++)
      Grid->XY[x / 100][(x / 5) % 4]
         .dat[(x / 20 % 5)][x % 5] = RX[x] & 255;
}
void ShowRoom(Gameroom *Room, int cx, int cy, int rx, int ry)
{
   int X, Y;
   short attrib, *Vid = (short*)0xb8000000L;
   char buf[128];
   for(X = 0; X < 5; X++)  {
      for(Y = 0; Y < 5; Y++)  {
         switch(Room->dat[X][Y])  {
            case '#': attrib = '\xfe' + 0x1900; break;
            case '.': attrib = ' ' + 0x0a00; break;
            case '$': attrib = 'o' + 0x0e00; break;  }
         *(Vid + X * 80 + Y) = attrib;
      }
   }
   *(Vid + cx * 80 + cy) = '{at}' + 0x0a00;
   sprintf(buf, " Room %d:%d :: Location %d:%d ",
      rx, ry, cx, cy);
   for(Y = 0; buf[Y]; X++, Y++)
      *(Vid + 800 + Y) = (short)((buf[Y] & 127) + 0x7100);
}
int move(int x, int y, Gameroom Room, int d)
{
   x = x - (d == -72) + (d == -80);
   y = y - (d == -75) + (d == -77);
   if(x > 4 || y > 4 || x < 0 || y < 0)   return -1;
   return (Room.dat[x][y] != '#') ? 1 : 0;
}
int main(void)
{
   Playfield Rooms;
   int locX = 1, locY = 1, RoomX = 0, RoomY = 0, key;
   init_rooms(&Rooms);
   printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
      "Use cursors to move. ENTER or Esc exit.\n");
   ShowRoom(&Rooms.XY[RoomX][RoomY], locX, locY, RoomX, RoomY);
   do {
      key = getch();   if(!key)   key = -getch();
      switch(key)  {
         case -72: case -75: case -77: case -80:  {
            switch(move(locX, locY, Rooms.XY[RoomX][RoomY], key))  {
               case -1:
                  if(key == -80 || key == -72)  {
                     RoomX = RoomX + ((key == -80) ? 1 : -1);
                     locX = (key == -80) ? 0 : 4;  }
                  else  {
                     RoomY = RoomY + ((key == -77) ? 1 : -1);
                     locY = (key == -77) ? 0 : 4;  }
                  break;
               case 0: printf("\a"); break;
               case 1:
                  locX = locX + (key == -80) - (key == -72);
                  locY = locY + (key == -77) - (key == -75);
                  break;
            }
            ShowRoom(&Rooms.XY[RoomX][RoomY], locX, locY, RoomX, RoomY);
         }
         case '\r': case '\x1b': break;  }
   }  while(key != '\r' && key != '\x1b');
   return 0;
}

> ] For Christmas, a remote control for the voices in your head.

---
* Origin: *YOPS ]I[* 8.4 GIG * RA/FD/FE * Milwaukee, WI (1:154/750)
SEEN-BY: 396/1 632/0 371 633/260 262 267 270 371 634/397 635/506 728 639/252
SEEN-BY: 670/218
@PATH: 154/750 222 396/1 633/260 635/506 728 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.