A begginer writing a text based dungeon game.

This is a discussion on A begginer writing a text based dungeon game. within the C Programming forums, part of the General Programming Boards category; This will be the first of many questions to come This is an assinment so dont give me code i ...

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    29

    A begginer writing a text based dungeon game.

    This will be the first of many questions to come
    This is an assinment so dont give me code i won't understand becouse i wont use it, even if you give me code i understand i still won't use it but i will learn from it.

    in this code i am trying to get a specific number to print out when the user types n, e, s, or w.
    for example: n would be 1, and e would be -1.
    all it dose is give me some strange error called signal 10 (sigbus) then it pulls up a debugger window sorry if this sounds to common it's never happend to me before.



    Code:
    #include <stdio.h>
    #include <stdlib.h>
    int main(void)
    {
    int room0[4]={1,2,-1,-1};
    char i;
    
    char n=0;
    char s=1;
    char e=2;
    char w=4;
    
    
    
    printf("number...err letter:");
          scanf("%c\n",i);
    
    printf("print the god dam numb. %i",room0[i]);
    
    
    	
    
    	return 0;
    }


    please before reading whats below, can you answer the above question first even if it will not help me with the game, it's how i learn things,i am very new at this got no experience at all.

    as for the text base game this is how its planned, so far i am planning to have 4 rooms and am writing the code in 4 parts, 1 for each room it sounds tedius but i just want to get from 1 room to the other for right now. the rooms have numbers 0-3, you get from each room by pressing n,s,e,w. if you try to go the wrong way its a -1. i am thinking the use of arrays, if else statements and goto statment. if there is more things i should or not use don't be shy speek up.

    and now for my stupid questions

    1)can you get an array of letters to equal an array of numbers.
    i guess that will be it for now i will post more questions as soon as they become more prevalent to the main question.

    lastly you are all probably wondering what text i am using, well i am using Programming in C third edition Stephen G. Kochan Developer's Library

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    scanf("%c\n",&i);

    so how are you going to change that code to your code?
    Quote Originally Posted by deadherorising View Post
    1)can you get an array of letters to equal an array of numbers.
    what do you mean?

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    29
    Quote Originally Posted by robwhit View Post
    scanf("%c\n",&i);

    so how are you going to change that code to your code?

    what do you mean?
    thanks, first question: i am not sure what your talking about. i hope i did it.
    but i changed the code a little. now for some resign every thing equals 1
    and i changed every thing to int values.
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    int main(void)
    {
    int room0[4]={1,2,-1,-1};
    int i;
    int g=room0[i];
    int n=0;
    int s=1;
    int e=2;
    int w=4;
    
    printf("number...err whatever:");
    scanf("%i\n",&i);
    
    printf("print the god dam numb. %i",g);
    
    
    	
    
    	return 0;
    }


    and for my stupid question,
    i mean somthing like this

    int room[4]={1,2,3,4}
    int die[4]={'n','s','e','w'}

    int die[]=room[]

    and now for my second stupid question
    2) can i make an array of letters equal to letsay 0-3 using the for loop.

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Code:
    int room0[4]={1,2,-1,-1};
    int i;
    int g=room0[i]; //i is not initialized.
    > int die[]=room[]
    what would this do?
    > 2) can i make an array of letters equal to letsay 0-3 using the for loop.
    you mean an array of chars?

    char arr[4] = {0,1,2,3};
    Last edited by robwhit; 10-26-2007 at 10:08 PM.

  5. #5
    Registered User
    Join Date
    Oct 2007
    Posts
    29
    Quote Originally Posted by robwhit View Post
    Code:
    int room0[4]={1,2,-1,-1};
    int i;
    int g=room0[i]; //i is not initialized.
    > int die[]=room[]
    what would this do?
    > 2) can i make an array of letters equal to letsay 0-3 using the for loop.
    you mean an array of chars?

    char arr[4] = {0,1,2,3};
    what do you mean i is not initialized i is initilized right above it with int i;

    1) int die[]=room[], i was hoping they would equal each other i guess not, dam.

    2) ya an array of chars!
    "char arr[4]={0,1,2,3}"
    i thought that would just ment that there are 4 places 0=0 1=1 2=2 3=3.
    i want in this case n=0 s=1 e=2 w=3.

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    > what do you mean i is not initialized i is initilized right above it with int i;
    that's declared. int i=5; is initialized.
    >1) int die[]=room[], i was hoping they would equal each other i guess not, dam.
    nope, have to do a loop to do that.
    > i want in this case n=0 s=1 e=2 w=3.
    sounds like you want a map.

    like this?

    arr[n] == 0
    but not
    arr[0] == n

    there's not an easy way to do maps in C.

  7. #7
    Registered User
    Join Date
    Oct 2007
    Posts
    29
    Quote Originally Posted by robwhit View Post
    > what do you mean i is not initialized i is initilized right above it with int i;
    that's declared. int i=5; is initialized.

    why would i want it initilized, i want it declared so the user can put a letter in for it and the letter equals a number, then i want that number to one of the 4 rooms0 integer values wich will finaly spit out one of the initilized numbers from rooms0[4]. i hope.

    > i want in this case n=0 s=1 e=2 w=3.
    sounds like you want a map.

    like this?

    arr[n] == 0
    but not
    arr[0] == n

    there's not an easy way to do maps in C.
    whats the diffrence between them?
    and yes kinda a map with 4 rooms.

  8. #8
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    > why would i want it initilized,

    because you use its value on this line:
    int g=room0[i]; //i is not initialized.
    actually, I don't think you can declare an array like that with a variable though.
    >i want it declared so the user can put a letter in for it and the letter equals a number,
    >then i want that number to one of the 4 rooms0 integer values wich will finaly spit out one of the initilized numbers from rooms0[4]. i hope.
    >whats the diffrence between them?
    arrays can only take numbers in the index.
    >and yes kinda a map with 4 rooms.
    no not cartography, I meant the data structure map. it's like an array but you index it with one type of variable and get the corresponding one back, but of a different type than the index type. I was being confusing, sorry.

    can you show what you are thinking of in code or in psuedo code?

  9. #9
    Registered User
    Join Date
    Oct 2007
    Posts
    29
    Quote Originally Posted by robwhit View Post
    > why would i want it initilized,

    because you use its value on this line:
    int g=room0[i]; //i is not initialized.
    actually, I don't think you can declare an array like that with a variable though.
    >i want it declared so the user can put a letter in for it and the letter equals a number,
    >then i want that number to one of the 4 rooms0 integer values wich will finaly spit out one of the initilized numbers from rooms0[4]. i hope.
    Code:
    int room0[4]={1,2,-1,-1};
    int i;
    
    int n=0;
    int s=1;
    int e=2;
    int w=4;
    
    printf("number...err whatever:");
    scanf("&#37;i\n",&i);
    
    int g=room0[i];
    
    printf("print the god dam numb. %i",g);
    is that better? and theres got to be a way to make a variable equal to the index.
    >whats the diffrence between them?
    arrays can only take numbers in the index.
    >

    well there goes all my bright ideas, but that defiantly answerd that question.

    and yes kinda a map with 4 rooms.
    no not cartography, I meant the data structure map. it's like an array but you index it with one type of variable and get the corresponding one back, but of a different type than the index type. I was being confusing, sorry.
    can you show what you are thinking of in code or in psuedo code?
    now i will answer you with a stupid question #3 what is psuedo code?

    if i showed you in code then i would be asking these questions.

    [/QUOTE]I was being confusing, sorry.[/QUOTE]
    and no you are not beeing confusing that is what i am aiming for this room, this is one room. i am planning to put the rooms together using a matrix.

    kinda like this

    -- n | s | e | w
    0| 1 | 2 |-1 | -1
    1| 2 | 0 |-1 |-1
    2| 0 | 1 |-1 | 3
    3|-1 | -1| 2 | -1

    heres a more visual idea.
    1
    |
    0
    |
    2--3

    the 1 and 2 are connected
    Last edited by deadherorising; 10-27-2007 at 01:04 AM.

  10. #10
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Code:
    int room0[4]={1,2,-1,-1};
    int i;
    
    int n=0;
    int s=1;
    int e=2;
    int w=4;
    int g;
    printf("number...err whatever:");
    scanf("&#37;i\n",&i);
    
    g=room0[i];
    
    printf("print the god dam numb. %i",g);
    syntactically, the above is correct. I don't know what you want it to do though.


    >now i will answer you with a stupid question #3 what is psuedo code?

    fake code.
    if the thing is true
    do the super_function
    add the variable
    endif


    -- n | s | e | w
    0| 1 | 2 |-1 | -1
    1| 2 | 0 |-1 |-1
    2| 0 | 1 |-1 | 3
    3|-1 | -1| 2 | -1
    Code:
    int arr[4][4]{
    {1,2,-1,-1},
    {2,0,-1,-1},
    {0,1,-1,3},
    {-1,-1,2,-1}};
    
    int main()
    
    {
    int i=0;
    int j=0;
    for (i=0;i<4; i++)
        for (j=0; j<4;j++)
            printf("%d ",arr[i][j]);
    }
    like that?
    heres a more visual idea.
    1
    |
    0
    |
    2--3

    the 1 and 2 are connected
    dunno what that is.

  11. #11
    Registered User
    Join Date
    Oct 2007
    Posts
    29
    [/code]syntactically, the above is correct. I don't know what you want it to do though.
    yes it dose work if you put the #0-3 in but i want to put the letters in and get the same print as i would by putting the numbers. wich dose not seem to be working.


    Code:
    int arr[4][4]{
    {1,2,-1,-1},
    {2,0,-1,-1},
    {0,1,-1,3},
    {-1,-1,2,-1}};
    
    int main()
    
    {
    int i=0;
    int j=0;
    for (i=0;i<4; i++)
        for (j=0; j<4;j++)
            printf("&#37;d ",arr[i][j]);
    }
    like that?
    ya like that, but for some resion i feel we have strayed from the original question, but some how the original question has just became the main question i think so let me focus on the main question first, then when i get to this part i will deal withit.

    heres a more visual idea.
    1
    |
    0
    |
    2--3

    the 1 and 2 are connected
    >dunno what that is.
    that was my attempt to draw the map. the numbers were the rooms.
    Last edited by deadherorising; 10-27-2007 at 05:34 AM.

  12. #12
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,340
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  13. #13
    Registered User
    Join Date
    Oct 2007
    Posts
    29
    Quote Originally Posted by Salem View Post
    > 1000 x 1000 x 30
    30Mbytes of storage (at least).

    But that's just the tip of the iceberg, you've got to initialise all those locations with meaningful data, unless you have a lot of

    N
    There is ocean here
    N
    There is ocean here
    N
    There is ocean here
    N
    There is ocean here
    N
    There is ocean here

    Not only that, no user will ever visit every location in your RPG, it would simply take too long (1 room per second for almost a year, non-stop)

    Your RPG will have at most a few hundred locations (that are interesting in some way). I suggest you store the connectivity of the locations within the data, then you only need to store the locations which interest you

    Perhaps something like this
    Code:
    enum { NONE, KITCHEN, HALL, STAIRS };
    enum { NORTH, SOUTH, WEST, EAST };
    
    struct room {
        char    *name;
        int      next[4];   // N,S,W,E from this location
    } rooms[] = {
        { "None" },
        { "Kitchen",    { NONE,    HALL,   NONE, NONE } },
        { "Hall",       { KITCHEN, STAIRS, NONE, NONE } },
        { "Stairs",     { HALL,    NONE,   NONE, NONE } },
    };
    If you have
    int room_num = KITCHEN;

    Moving south is just
    room_num = rooms[room_num].next[SOUTH];
    humm interesting i see some things but i deont see others like
    were dose the north south east west become initilized, is he even using them, or is he just using the hall ,kitchen and stairs as the directions.

    still this dose not answer my question, how do i make a variable equal to the index.

  14. #14
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,340
    Separate your data from your code.

    Each room contains up to 4 directions which lead to other rooms. You can have as many rooms as you like.

    If you want, you can add "up" and "down" to the possible directions, so that stairs for example do the right thing.

    > or is he just using the hall ,kitchen and stairs as the directions.
    No, they're places at the destination of moving in a direction.

    Design your map, design your data structures, read from a file.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  15. #15
    Registered User
    Join Date
    Oct 2007
    Posts
    29
    so i should get all the numbers to work first and add all the data first than worry about adding the north south east weast, and other descriptions later. ok thanks

Page 1 of 4 1234 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C Programming 2d Array Question
    By jeev2005 in forum C Programming
    Replies: 3
    Last Post: 04-26-2006, 03:18 PM
  2. OpenGL - 2d text in 3d game
    By mikeb1986 in forum C++ Programming
    Replies: 1
    Last Post: 03-22-2006, 12:24 PM
  3. PC Game project requires c++ programmers
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 02-21-2006, 11:23 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Outputting String arrays in windows
    By Xterria in forum Game Programming
    Replies: 11
    Last Post: 11-13-2001, 06:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21