hiding the values in a string array

This is a discussion on hiding the values in a string array within the C++ Programming forums, part of the General Programming Boards category; Hey guys...I'm trying to make a trivial pursuit board with all the different colors being represented by 2 letter words ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    153

    hiding the values in a string array

    Hey guys...I'm trying to make a trivial pursuit board with all the different colors being represented by 2 letter words (pink = PK, etc) and I'm trying to make it look like a piece would be moving around this board so let's say on the first square you start on (array[0] = "F S") is it possible to change the value stored in that array temporarily to a 'O' or something to signal a player's piece is in that square at that moment...but once the player leaves that square it will return to the value "F S"...this is all being done in the console window (because my skills arent advanced enough to do anything else yet hehe)...any ideas or pieces of code would be cool...thanks a lot, Chap

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Well you could have one array that stores data about the colors of the board squares, etc.. and then have another value for each square that specifies the status of the board (i.e. if someone's there, and if so, what character). It would be much more efficient if you worked driectly with binary. You could use a lot less space, and learn more about C/C++ in the process. Look for the site's tutorial on bit-shifting. PM me if you want a bit more help as to how it applies to a board game.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    153
    hmmm...So first off...thanks so much for the advice...however, the bitwise tutorial lead me to an error page...I'm going to fish around the net some more and see if I can dig up some good info...the best I got so far was bitwise FAQs which didnt really make sense to me because I suck at binary math (well less sucking and more of just a lack of any exposure )
    So once again...thanks again...if you know of any good, credible tutorials or books don't be afraid to spread the good word haha, thanks a lot-Chap

  4. #4
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Basically you just need to learn how to manipulate individual bits in a char variable, and determine if certain bits are set. If you can learn that from a tutorial, you're all set. From there it's not a huge jump to see how you can use it for storing the information about your board. I'm about to go to bed, but if you can't find anything, PM me and I'll send you a little tutorial of my own.

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I don't really see it being more efficient. They've already stated that they're using a board (an array of characters), because since this is text based, they have to have something to represent what's going on. So manipulating bits really isn't going to do anything other than waste time. (Not that bitwise operations are slow, it's just unneeded.)

    Consider the following:
    Code:
    [xx][xx][xx][xx][xx][xx][xx][xx][xx][xx]
    [xx]                                [xx]
    [xx]                                [xx]
    [xx]                                [xx]
    [xx]                                [xx]
    [xx]                                [xx]
    [xx]                                [xx]
    [xx]                                [xx]
    [xx]                                [xx]
    [xx][xx][xx][xx][xx][xx][xx][xx][xx][xx]
    Here's our board. I'll use the standard Monopoly style board, because it's easy for me to quickly draw using ascii. Some place in your program you're going to have a "drawboard" function. It's really quite simple:
    Code:
    for each section of the board:
        if( character_is_here )
            draw_character_representation();
        else
            draw_board_section( here );
    So if we were to start with this one, drawing them square by square, we'd start in the upper left. If I was there, you'd draw "[Q.]", if not, you'd draw "[xx]". Then you'd move on to the next piece. If I was there, you'd draw "[Q.]". If not, you'd draw "[xx]", and so on.

    This can be even simpler if you've got objects which store their own symbol. Assuming you've got some classes, or even if you don't, you can have each player and each board piece contain the information for that type of piece. For example, my piece would be [Q.]. Pink pieces would be [Pk] or what not. Then you invoke something like:
    Code:
    board::drawboard()
    {
        for each piece in the board list
            if( thispiece.isoccupied() )
                thispiece.draw( (thispiece.getplayer()).getsymbol() );
            else
                thispiece.draw( thispiece.getsymbol() );
    }
    It's a crude example, but the point should be easy enough to follow. The hard part is figuring out what to do if you have more than one person on the same square.


    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Registered User
    Join Date
    Sep 2004
    Posts
    153
    haha awesome suggestion...I'll see what I can do with it..thanks a lot

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. String Class
    By BKurosawa in forum C++ Programming
    Replies: 117
    Last Post: 08-09-2007, 01:02 AM
  2. RicBot
    By John_ in forum C++ Programming
    Replies: 8
    Last Post: 06-13-2006, 06:52 PM
  3. can't assign proper values to an array of string
    By Duo in forum C Programming
    Replies: 1
    Last Post: 04-04-2005, 06:30 AM
  4. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  5. 3-d array assign string values
    By WaterNut in forum C++ Programming
    Replies: 8
    Last Post: 07-01-2004, 12:02 AM

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