Thread: Slight Confusion

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    11

    Slight Confusion

    So first off, i'm new to this. Very Very new.

    I'm currently writing a text based game in Ansi C (some of you may of noticed a few of us doing this and asking around here for guidance).

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    #define North=0
    #define East=1
    #define South=2
    #define West=3
    typedef struct{
      char RoomName[30];
      char Description[500];
      unsigned int Exit[4];
    }Location;
    Location Room[7];
    void SetupRooms()
    {
    strcpy(Room[1].RoomName, "AirLock");
    strcpy(Room[1].Description,"As you enter the facility you find your comms channels have scrambled. \nYou appear to be in some kind of air lock. \nIn front of you the light turns green and you can hear bolts shifting.");
    Room[1].Exit[North]=2;
    Room[1].Exit[East]=0;
    Room[1].Exit[South]=50;
    Room[1].Exit[West]=0;
    strcpy(Room[2].RoomName, "Main Canteen");
    strcpy(Room[2].Description,"\"Arrrgghhhhhhh\" A muffled scream dies out somewhere up ahead as you \nstep into a wide berthed room full of regimented tables and chairs, \nto the left is a food station. Looks like your in the canteen.");
    Room[2].Exit[North]=3;
    Room[2].Exit[East]=4;
    Room[2].Exit[South]=1;
    Room[2].Exit[West]=5;
    strcpy(Room[3].RoomName, "Stasis Chamber");
    strcpy(Room[3].Description,"After a brief scan from the remaining functional automatic \nsystems you enter a completely white room with a large bank of computer systems next to a row of malfunctioning cryogenic bays. \nBehind you comes those sounds from earlier, very very close. Its found you.\n No time for lockdown, There is only one other door aside from where you came in. To the escape pods!");
    Room[3].Exit[North]=0;
    Room[3].Exit[East]=0;
    Room[3].Exit[South]=0;
    Room[3].Exit[West]=7;
    strcpy(Room[4].RoomName, "Decontamination Chamber");
    strcpy(Room[4].Description,"Tentatively you follow the big warning signs and step into a room with plastic shawls on each side with shower heads poking through. Its impossible to tell how big the room actually is beyond this and shadows dance menacingly behind every surface.");
    Room[4].Exit[North]=0;
    Room[4].Exit[East]=0;
    Room[4].Exit[South]=0;
    Room[4].Exit[West]=2;
    strcpy(Room[5].RoomName, "Containment Facility");
    strcpy(Room[5].Description,"The doors are heavy, but warped and twisted. You crouch and make your way through a gap whilst trying not to question the damp surface. Once in you can see that the containment room itself is severly damaged, chemical burns splatter the walls and a metallic odour flips your stomach. Suddenly a wet \"Thud\" and snarl sounds from the corridor in front of you leading to the cages. Everything in your body wants to turn back.");
    Room[5].Exit[North]=0;
    Room[5].Exit[East]=2;
    Room[5].Exit[South]=0;
    Room[5].Exit[West]=6;
    strcpy(Room[6].RoomName, "Cages");
    strcpy(Room[6].Description,"Against everything, you carry on towards the sound. This is the place where they must have been keeping whatever it is. What you've been sent to secure. The air is heavy here and there are definite sounds of life from the end cage. Whatever it is, its in there. Now you must isolate the facility from the central control unit in the crews stasis chamber and leave as quickly as you can.");
    Room[6].Exit[North]=0;
    Room[6].Exit[East]=5;
    Room[6].Exit[South]=0;
    Room[6].Exit[West]=0;
    strcpy(Room[7].RoomName, "Escape Pods");
    strcpy(Room[7].Description,"Houses the household computer and bookshelves filled to the brim. Rob is in the corner fapping. Its too late, the creature has found you...its Paedobear. The next scene has been censored.");
    Room[7].Exit[North]=50;
    Room[7].Exit[East]=0;
    Room[7].Exit[South]=0;
    Room[7].Exit[West]=0;
    }
    void DescribeRoom(unsigned int i)
    {
     printf("You are sent to a home facility for testing of new biological sciences after it stopped responding to communications. \nYou are to secure that the stored subjects are still within the facility and initilise lockdown.\n \n");
     printf("%15d- Maps indicate that your are in the ");
     printf(Room[i].RoomName);
     printf(" -0\n\n\n\n");
     printf(Room[i].Description);
     printf("\n\n");
    }
    void DescribeExits(unsigned int i)
    {
     printf("There are doors to your;\n");
     if(Room[i].Exit[North]!=0) printf("North\n");
     if(Room[i].Exit[East]!=0) printf("East\n");
     if(Room[i].Exit[South]!=0) printf("South\n");
     if(Room[i].Exit[West]!=0) printf("West\n");
     printf("\nInput the first letter of your desired direction to move. \nPress q to quit the system.\n");
    }
    int GetDirection(unsigned int i)
    {
     char test;
     unsigned int NewDirection=0;
     while(1)
     {
      test=getch();
      if(test=='n') NewDirection=Room[i].Exit[North];
      if(test=='e') NewDirection=Room[i].Exit[East];
      if(test=='s') NewDirection=Room[i].Exit[South];
      if(test=='w') NewDirection=Room[i].Exit[West];
      if(test=='q') NewDirection=50;
      
      if(NewDirection!=0) return(NewDirection);
      printf("Theres no way you can go there.\n");
     }
    }
     
    void main()
    {
     unsigned int RoomNumber = 1; 
     unsigned int Direction;
     SetupRooms();
      while(1)
      {
       system("cls");
       DescribeRoom(RoomNumber);
       DescribeExits(RoomNumber);
       Direction = GetDirection(RoomNumber);
       if(Direction==50)exit(0);
       if(Direction>0)RoomNumber= Direction;
      }
    }
    void print_house(unsigned int RoomNumber, unsigned int Direction){ // set up Room numbers and Directions
     char Room_x[RoomNumbers];
     unsigned int i;
     for ( i=0; i<RoomNumbers; ++i )
      Room_x[i] = ' ';
     Room_x[RoomNumber] = 'X';
     printf("___________________________________________________________\n");
     printf("|                    _____________________                |\n");
     printf("|                    |                   |                |\n");
     printf("|        __________  |                   |                |\n");
     printf("|       /          | |                   |                |\n");
     printf("|      /           |_|     Stasis        |                |\n");
     printf("|     / Escape             Chamber       |                |\n", Room_x[7]);
     printf("|     \  Pod  %c    _                    |                |\n");
     printf("|      \           | |        %c         |                |\n", Room_x[3]);
     printf("|       \__________| |                   |                |\n");
     printf("|                    |                   |                |\n");
     printf("|                    |________   ________|                |\n");
     printf("|                     _______|   |________                |\n");
     printf("|                     |                  |                |\n");
     printf("|                     |                  |                |\n");
     printf("|________  ___________|                  | _______________|\n");
     printf("|        ||           |                  ||               |\n");
     printf("|  Cages ||Containment|                  ||Decontamination|\n");
     printf("|   %c      Facility                           Chamber    |\n", Room_x[6]);
     printf("|              %c                                         |\n", Room_x[5]);
     printf("|        ||           |     Canteen      ||       %c      |\n", Room_x[4]);
     printf("|________||___________|                  ||_______________|\n");
     printf("|                     |        %c        |                |\n", Room_x[2]);
     printf("|                     |                  |                |\n");
     printf("|                     |                  |                |\n");
     printf("|                     |                  |                |\n");
     printf("|                     |                  |                |\n");
     printf("|                     |                  |                |\n");
     printf("|                     |                  |                |\n");
     printf("|                     |                  |                |\n");
     printf("|                     |                  |                |\n");
     printf("|                     |_____     ________|                |\n");
     printf("|                        |         |                      |\n");
     printf("|________________________| Airlock |______________________|\n");
     printf("                         |   %c    |                       \n", Room_x[1]);
     printf("                         |___   ___|                       \n");
    }

    I understand my program may be very confused and inefficient, but for now the main issue i am trying to tacke is the text map seen near the bottom. At the moment i have the errors:

    Undefined Symbol RoomNumbers in function 'print_house'.
    And
    Non Scalar or negative array index in function 'print_house'

    both on line 111.

    I understand that i've not properly defined RoomNumbers, but everytime i put a char in for it i get 'internal error'

    Any advice would be greatly appreciated. On the problem at hand first, and then i can start to worry about other things.

    Thanks
    Last edited by L.Firth; 04-28-2012 at 09:04 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Slight dilemma...
    By Junior89 in forum C++ Programming
    Replies: 6
    Last Post: 10-06-2005, 06:26 AM
  2. slight problem
    By duvernais28 in forum C Programming
    Replies: 4
    Last Post: 02-03-2005, 11:03 AM
  3. slight problem on win app tut
    By JustPlay4Fun in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2005, 11:42 AM
  4. some slight help..
    By ahming in forum C Programming
    Replies: 9
    Last Post: 09-05-2004, 08:02 AM
  5. Slight problem...
    By Fordy in forum A Brief History of Cprogramming.com
    Replies: 20
    Last Post: 08-10-2002, 01:32 PM