#include <iostream.h> #include "stddisp.h" #include "dealer.h" #include <ctype.h> // for tolower ostream& operator<<(ostream& s, const Card& card) { s << card.CardType() << card.SuitAsChar(); return s; } istream& operator>>(istream& s, BlackJackHand::TURN_RESULT& result) { char c = ' '; while (c != 'h' && c != 's' && c != 'd') s >> c; switch (c) { case 'h': result = BlackJackHand::HIT; break; case 'd': result = BlackJackHand::DOUBLE_DOWN; break; case 's': result = BlackJackHand::STAND; break; case 'p': result = BlackJackHand::SPLIT; break; default: throw "Undefined!"; } return s; } ostream& operator<<(ostream& s, const BlackJackHand::TURN_RESULT& result) { switch (result) { case BlackJackHand::HIT: s << "HIT"; break; case BlackJackHand::BUST: s << "BUST"; break; case BlackJackHand::STAND: s << "STAND"; break; case BlackJackHand::DOUBLE_DOWN: s << "DOUBLE_DOWN"; break; case BlackJackHand::SPLIT: s << "SPLIT"; break; default: throw "Illegal result of move"; } return s; } void StandardDisplayer::DisplayCards(const BlackJackHand& hand) { int numCards = hand.NumCards(); for (int i = 0; i < numCards; i++) cout << hand.GetCard(i) << " "; } StandardDisplayer::StandardDisplayer() { } StandardDisplayer::~StandardDisplayer() { } void StandardDisplayer::DrawCard(const BlackJackHand& hand, const Card& card) { cout << hand.GetIdentity() << " : dealt a "; if (hand.NumCards() < hand.NumCardsDealtDown()) cout << "XX"; else cout << card; cout << ' '; } void StandardDisplayer::DisplayTurn(const BlackJackHand& hand, BlackJackHand::TURN_RESULT turn) { cout << hand.GetIdentity() << "(" << hand.LowCount() << "/" << hand.HighCount() << "): " << turn << ":" ; DisplayCards(hand); cout << ' '; } void StandardDisplayer::DisplayResult(const BlackJackHand& hand, const char* result) { cout << hand.GetIdentity() << " ( " << hand.HighCount() << ")"; if (result) cout << ": resulted with a " << result << ' '; else cout << ' '; } bool StandardDisplayer::InquireInsurance(const BlackJackHand& hand) { char insurance = ' '; while (insurance != 'y' && insurance != 'n') { cout << hand.GetIdentity() << ": Insurance (y/n)? "; cin >> insurance; } return insurance == 'y'; } BlackJackHand::TURN_RESULT StandardDisplayer::InquireTurn (const BlackJackHand& hand, bool mayDouble, bool maySplit) { BlackJackHand::TURN_RESULT result; cout << hand.GetIdentity() << "(" << hand.LowCount() << "/" << hand.HighCount() << ") :"; DisplayCards(hand); cout << ' '; cout << "What do you want to do H-Hit, S-Stand "; if (mayDouble) cout << "D-DoubleDown "; if (maySplit) cout << "P-Split"; cout << ' '; cin >> result; return result; } bool StandardDisplayer::InquireNewGame() { char c = ' '; while (c != 'y' && c != 'n'){ cout << "New Game? "; cin >> c; c = tolower(c); } return c == 'y'; }
3.17.167.114