Creating a game with ADT List

This is a discussion on Creating a game with ADT List within the C++ Programming forums, part of the General Programming Boards category; Hi...I need some syntax help with my game! I'm still putting together the declaration files, and I'm using a provided ...

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    56

    Define data structure

    Hi...I need some syntax help with my game! I'm still putting together the declaration files, and I'm using a provided ADT header file, such as follows:
    Code:
    const int MAX_LIST = 52;
    typedef CSomeClass ListItemType;
    
    // The following structure is what I am asking questions about:
    struct card
    {
         int value;
         char suit;
    };
    
    class List
    {
    public:
       List(); 
    
       bool isEmpty() const;
    
       int getLength() const;
    
       void insert(int index, ListItemType newItem,
                   bool& success);
    
       void remove(int index, bool& success);
    
       void retrieve(int index, ListItemType& dataItem,
                     bool& success) const;
    
    private:
       ListItemType items[MAX_LIST]; 
       int          size;            
    
       int translate(int index) const;
    };
    Now...how would I go about building the deck to assign a value to each card structure? Because I want an array of data type cards. Of course I can just manipulate the display to show the appropriate value and suite for the card number, but this seemed funner.
    I don't even have the foggiest clue. With the old-fashioned std linked list one could just typedef the list and say something like
    Code:
    for(int x=1; x<=52; x++)
    {
         cur->value = x;
    }
    but that doesn't really seem to apply in this case.

    Thanks in advance for any suggestions!
    Last edited by marQade; 05-15-2008 at 01:17 PM.

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    I suppose items are inserted into the "List" using its insert member function. The arguments are pretty self-explanatory (although passing the success bool as an out parameter looks a bit stupid).

    Items are probably modified by calling retrieve first to get the item and then calling insert to apply the changes (again something that would be much easier if this class just overloaded operator[]).

    You would probably be better off using standard containers. In this case you probably don't want a list (which is a linked list, unlike this one, which looks like a plain array to me), but rather a vector.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    56
    I see. I believe you're quite right. Thanks very much!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My Game Programming Book List
    By Trennto in forum Game Programming
    Replies: 9
    Last Post: 07-11-2008, 09:11 PM
  2. Game Engine Link Prob
    By swgh in forum Game Programming
    Replies: 2
    Last Post: 01-25-2006, 11:14 PM
  3. instantiated from here: errors...
    By advocation in forum C++ Programming
    Replies: 5
    Last Post: 03-27-2005, 08:01 AM
  4. problem with structures and linked list
    By Gkitty in forum C Programming
    Replies: 6
    Last Post: 12-12-2002, 05:40 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM

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