I decided to make a Black Jack program to relearn programming/c++.
I've gotten as far as making to user choose amount of decks and generating the cards. Initially I stored the card info inside a string two-dimensional array like this:
string card[CARDS_IN_A_DECK*g_number_of_decks][4];
After reading a bit about it online and running into some problems I'm reconsidering.
I want to store following information about the card:
1 2 3 4
|
char card_suit = {"S", "H", "D", "C"};
string card_rank = {"2","3","4","5","6","7","8","9","10","J","Q","K","A"};
int card_value = {2,3,4,5,6,7,8,9,10,10,10,10,0};
bool card_status = {0,1};
|
The variables will be defined in a subfunction in a separate file like this:
1 2 3 4 5 6 7 8 9 10 11
|
#include "launch_settings.h"
int launch_settings();
int create_deck(); // We don't know the dimension of the array we want returned from this function yet. Is that an issue?
int main()
{
launch_settings(); // In this function, the user enters the amount of decks used, which means we'll know the amount of cards (size of array).
create_deck(); // When calling this function, the size of the array we want returned from it will be known.
return 0;
}
|
So, the variables will be created in a subfunction, returned to main() and used as arguments to subfunctions. The variables will continuously be changed (the deck will get shuffled after a few hands and the boolean value will switch after each card has been played.
So, what is the best way to store this information?
* Inside a two-dimensional array. (Problematic since I have different types of variables; int, string, etc. Ive also read that arrays should not be returned from functions.)
* Inside multiple one dimensional arrays. (Doable, but return from function still might be an issue).
* A vector inside a vector. (Is it doable with different types?)
* Multiple vectors (one for each type of variable).
* Wrapper class. (is that too much for a beginner?)
* Should I use global variables? (They will be used in pretty much every function after all..)
Thanks in advance!