Thursday, 29 November 2018

Google + Content reposting Mar 8 2015 - 1


Digital and Interactive Games 2015 – Week 4, Session 1
7.1 – 7.4 C++ Primer

map <string, int> myMap;

myMap[“Hero”] = 1;

string        int
“Hero”        1

deckOfCards myDeck;


Q2
    → myDeck.print();

Q3
    → myDeck.shuffle();

Implementing Classes
A single card can be representing in a single struct.

Struct card {
    int suitOrder;
    int valueOrder;
    std::string suitDisplay;
    std::string valueOrder;
};

One way to set up a pack of cards

// Initialise the pack of cards
std::vector <std::string> suit{ “club”, “diamond”, “heart”, “spade” };
std::map<std::string, int> suitOrder;
for (auto i = 0; i != suit.size(); i++;) {
    suitOrder[suit[i]] = i + 1;
}
std::vector<std::string> value{“2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”, “10”, “J”, “Q”, “K”, A”};
std::map<std::string, int> valueOrder;
for (auto i = 0; i != value.size(); ++i) {
    valueOrder [value[i]] = i + 1;
}

Then you can loop through it.

std::vector<card> packOfCards;
for (auto i = 0; i != value.size(); ++i) {
    for (auto j = 0; j != suit.size(); j++;) {
        packOfCards.push_back({suitOrder[suit[i]], value[i], suit[i], suit[i])});
    }
}

If done as above, if you want to change the order of suit or value, only the initial list need be manipulated.


Assertion failed.
Expression: vector subscript out of range


#cplusplus   #gamedesign   #gameprogramming   #programming   #tafe  





No comments:

Post a Comment