I need this to work so I can check each number on the card for a bingo. |
What's not working?
Line 13: Needs ::
1 2
|
Bingocard::Bingocard()
{}
|
line 63,64: anzahlKarten is undefined. Do you mean numberCards ?
Line 57: You're allocating maxNumberCards. Why do you even have Player::newCard() ?
This is going to cause a memory leak because you've already allocated the array of cards in your constructor.
Lines 55,56: These seem redundant. If you're allocating the maximum number of cards in your constructor, then numberCards a maxNumberCards serve the same purpose.
BTW, a traditional bingo card has 5 rows and columns.
As a matter of good style, I would suggest adding after line 2:
|
static const unsigned CARD_SIZE = 4; // or 5 if you choose
|
Then every place you hard code a 4, use CARD_SIZE instead. This will allow you to easily change the size of the bingo card without making lots of changes.
Since you've made card private to BingoCard, then all access to the card array must be through functions provided in the BingoCard class. Player should not need to know how card is represented inside BingoCard.
Edit:
You can simplify two of your constructors and your assignment operator by providing a Copy function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
void Copy (const int Card[CARD_SIZE][CARD_SIZE])
{ for (int i=0; i<CARD_SIZE; i++)
for (int j=0; j<CARD_SIZE; j++)
card[i][j] = Card[i][j];
}
//...
Bingocard::Bingocard(int Card[CARD_SIZE][CARD_SIZE])
{ Copy (Card);
}
Bingocard::Bingocard(const Bingocard& Card)
{ Copy (Card.card);
}
Bingocard & Bingocard::operator=(const Bingocard& Card)
{ Copy (Card.card);
return (*this);
}
|
Line 31: BingoCard should be returned by reference, not value.
You need to keep two pieces of information for each cell on a bingo card before you can check for a winner:
- The value (number) of the cell.
- Whether the number has been drawn yet.
Currently, you don't appear to be initializing your BingoCard anywhere.
I would suggest adding a bool array to your BingoCard class.
1 2
|
bool drawn[CARD_SIZE][CARD_SIZE]
|
Don't forget to initialize the bool array to false.
You're also going to need a bool array for the numbers drawn by the caller (computer).