Reading a .TXT map in a text game

This is a discussion on Reading a .TXT map in a text game within the Game Programming forums, part of the General Programming Boards category; I want to have a text game map that looks like this: *********** *+++---------* *--------------* *------- &----* * -----#------* *********** ...

  1. #1
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373

    Reading a .TXT map in a text game

    I want to have a text game map that looks like this:

    ***********
    *+++---------*
    *--------------*
    *------- &----*
    * -----#------*
    ***********

    Then have the program run like this:
    if the square the user is on is a + sign, then heal him/
    If the square is &, give him a gun,
    if the square is #, take 25 health from him.

    How could i do that.
    Last edited by Blizzarddog; 03-03-2003 at 01:01 PM.
    This war, like the next war, is a war to end war.

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640

  3. #3
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373
    Travis, i already know how to do that using fout in a binary format. It uses .dat, or .txt. I need to know how to manipulate tyhat into map coordinates!
    This war, like the next war, is a war to end war.

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Code:
    if(WorldMap[Xpos][Ypos] == '+')
    {
       HealPlayer();
    }
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  5. #5
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373
    Er. okay, this may cometo be a suprise, but HOW IN THE HECK CAN I MAKE THE PLAYER WALK AROUND ON THE GRID, thats what im asking.
    This war, like the next war, is a war to end war.

  6. #6
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    You're asking how to make an entire RPG now...

  7. #7
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373
    well, sorta, i was aking how i could make the map, then put in into the game for the player to walk arounf on it. A simple 6x6 grid. Its much easier to do that then, say, RoDs' thing:
    (on a 25x 25 grid)
    Code:
    if (player_location_Y == 4 && player_location_X == 6)
    {
    if (amulet == 1)
    {
    ...
    }
    else if (amulet == 0)
    {
    ...
    }
    }
    For every dang square.
    This war, like the next war, is a war to end war.

  8. #8
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Make an array of amulets and store their position in it...

  9. #9
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373
    listen, i've used structs. I've used arrays, and all it did was not work. I had structs for every single thing in the ame, with the structs taking up 970 by them selves, and i could put the player loctaion y to 6000, with no max y, and it would put him right back to y: -1... arrays, same thing. So i need to finsd a better way to do that. Preferrably the .TXT map. Or a .XLS. Maybe .DAT.
    This war, like the next war, is a war to end war.

  10. #10
    Registered User
    Join Date
    Mar 2003
    Posts
    6
    Yeah.... Im not sure you need a 2d array if you use this:..

    Have an 1d array of gunsx, gunsy, healthx healthy, etc

    and 2 ints, to represent the guys coords

    when you move, munipulate the x, y coords, and after that, write a function to search through each array iteratively to see if a number in the guns array, matches the x and y coords... there is a good advantage to this, in that you can have 2 or more items at one location

    advanced tip: for this, you can make it 1 array each item, if you create your own item-coord data structure: keyword: struct

    hope this helps

  11. #11
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373
    i was thinking of something like this:
    Code:
    struct item
    {
    int y;
    int x;
    string name;
    };
    
    item.health[1] = {
     {2, 2, 'health Kit'}
    };
    
    item.td[1] = {
     {0, 0, 'Travis Dane, player'}
    };
    But that is very buggy when it comes to gameplay. It's annoying to type td[1].y++, and things like that over and over and over and over and over and over and over and over and over and over and over and over. Get the picture?
    This war, like the next war, is a war to end war.

  12. #12
    Registered User
    Join Date
    Mar 2003
    Posts
    6
    Not really?

    you would call 'td[1].y++' on the up arrow keypress, so it would be automatic...?

  13. #13
    Registered User
    Join Date
    Mar 2003
    Posts
    6
    But of course, with reference to your original thread problem... you could do a text file like:

    ** TXT file start **
    1,1,"health"
    1,6,"gun"
    ** TXT file end**

    and you can load the file, a line at a time, and parse the ints and strings and add them to the appropriate part of the array... this is good because levels are actually TXT files and not hardcoded into the program... you could swap with your friends and create your own, etc

  14. #14
    Registered User SAMSAM's Avatar
    Join Date
    Nov 2001
    Posts
    218
    The logic for your movement can be done in a few ways.
    few years ago i did a chess movement game of KNIGHT,
    as sort of practice.

    another one a turtle graphic for a turtle moving in a grid
    and write to each square that he falls into.

    I lost tons of source codes ,when my comp crashed but
    here is the basics:

    use a 11 by 11 array "floor" which is initialized to 0.

    read the instructions from an instruction array constant.
    you have to keep track of all the positions "current or ++
    or --" of the user.

    put the start pos at (0,0). u can have a different one.
    commands could look like this:

    instruction what it means
    1 have health
    2 needs health
    3 step right
    4 step left
    5,5 move ahead 5 squares
    6 print floor
    7 got gun
    9 EOF

    as the user moves within grid, set the apropriate squares of array to 1 (TRUE) as being visited(keep track) and continiously
    update command 6 to print the array as visited by user, probably
    by showing a * in that TRUE element of the array.

    u can have n number of possible moves"its up to u"
    but u have to determine that at the begining .then write the command for these moves in a separate constant array.

    the current position will come in the form of 2 variables;


    rowPosition, ColumnPosition;
    keep a counter for each square(as how many times it has been visited)

    test everymove before its done just so u wont fall outside of the
    grid.

    this is a basic crude heuristic(planned strategy) method of
    programming.

    good luck .its fun.

    cheers!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 2D Game project requires extra C++ programmers, new or experienced
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 05-16-2007, 11:46 AM
  2. game map format preference
    By valis in forum Tech Board
    Replies: 2
    Last Post: 07-02-2006, 03:16 PM
  3. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 04:49 PM
  4. reading from a text file help......
    By jodders in forum C++ Programming
    Replies: 2
    Last Post: 01-25-2005, 12:51 PM
  5. Outputting String arrays in windows
    By Xterria in forum Game Programming
    Replies: 11
    Last Post: 11-13-2001, 07:35 PM

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