Skip to content

Commit ab65482

Browse files
committed
moved cardgame to solutions folder
1 parent 39b7f90 commit ab65482

File tree

8 files changed

+48
-8
lines changed

8 files changed

+48
-8
lines changed

cardgame/datastructure/card.cpp renamed to SOLUTIONS/Exercise 6.9.1/datastructure/card.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
Card::Card(int faceNbr, int suitNbr)
66
: m_FaceNbr(faceNbr), m_SuitNbr(suitNbr){}
77

8-
QString Card::toString()
8+
QString Card::toString() const
99
{
1010
// return getFace() + " " + getSuit();
1111
return QString("%1 %2").arg(getFace()).arg(getSuit());
1212
}
1313

1414
// returns value of card based on rules of bridge
15-
int Card::getValue()
15+
int Card::getValue() const
1616
{
1717
switch(m_FaceNbr) {
1818
case 10: return 1; // jack
@@ -35,6 +35,6 @@ QStringList Card::s_Faces = QStringList() << "A" << "2" << "3" << "4"
3535
QStringList Card::s_Suits = QStringList() << "Clubs" << "Diamonds"
3636
<< "Hearts" << "Spades";
3737

38-
QString Card::getFace() { return s_Faces[m_FaceNbr]; }
39-
QString Card::getSuit() { return s_Suits[m_SuitNbr]; }
38+
QString Card::getFace() const { return s_Faces[m_FaceNbr]; }
39+
QString Card::getSuit() const { return s_Suits[m_SuitNbr]; }
4040

cardgame/datastructure/card.h renamed to SOLUTIONS/Exercise 6.9.1/datastructure/card.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ class Card
77
{
88
public:
99
Card(int faceNbr, int suitNbr);
10-
QString toString();
11-
QString getFace();
12-
QString getSuit();
13-
int getValue();
10+
QString toString() const;
11+
QString getFace() const;
12+
QString getSuit() const;
13+
int getValue() const;
1414

1515
private:
1616
int m_FaceNbr;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* This is example code provided to the student */
2+
//start
3+
#include "carddeck.h"
4+
#include <QtWidgets>
5+
#include <QTextStream>
6+
7+
int main(int argc, char* argv[]) {
8+
QApplication app(argc, argv);
9+
QTextStream cout(stdout);
10+
CardDeck deck;
11+
12+
13+
CardHand hand;
14+
int handSize, playerScore, progScore;
15+
cout << "How many cards in a hand? " << flush;
16+
handSize = QInputDialog::getInt(0, QString("getInt()"),
17+
QString("How many cards in hand?"), 1, 5);
18+
QMessageBox::StandardButton sb;
19+
do {
20+
hand = deck.deal(handSize);
21+
cout << "Here is your hand:" << endl;
22+
cout << hand.toString() << endl;
23+
playerScore = hand.getValue();
24+
cout << QString("Your score is: %1 points.")
25+
.arg(playerScore) << endl;
26+
// Now a hand for the dealer:
27+
hand = deck.deal(handSize);
28+
progScore = hand.getValue();
29+
cout << "Here is my hand:" << endl;
30+
cout << hand.toString() << endl;
31+
cout << QString("My score is: %1 points.")
32+
.arg(progScore) << endl;
33+
cout << QString("%1 win!!")
34+
.arg((playerScore > progScore)?"You":"I") << endl;
35+
sb = QMessageBox::question(0, QString("QMessageBox::question()"),
36+
QString("Another hand?"), QMessageBox::Yes | QMessageBox::No);
37+
} while (sb == QMessageBox::Yes);
38+
return 0;
39+
}
40+

0 commit comments

Comments
 (0)