// // CardSet::locate() - 内部での target のカードの位置を返す(-1: ない) // int CardSet::locate(const Card & target) const { for(int i = 0; i < numcard; i++) if(target.equal(cards[i])) return i; return -1; // 見つからなかった }
int main() { cout << ">> Memory starting" << endl; int score = 0; int x = 6; Board board(x); board.shuffle(); board.shuffle(); board.print(); while (score < x) { cout << "Specify the cards to turn" << endl; unsigned int a, b; cin >> a >> b; a--; b--; if (a == b) { cout << "These cards are the same" << endl; } else { Card *ca = board.get(a); Card *cb = board.get(b); if (ca == nullptr || cb == nullptr) { cout << "Could not find card " << a << " or card " << b << endl; } else { ca->turn(); cb->turn(); board.print(); if (ca->equal(*cb)) { cout << "Yes, I found a match" << endl; score++; cout << "Your score is: " << score << endl; } else { ca->turn(); cb->turn(); } } } } cout << "<< Memory finished" << endl; return 0; }