//*****************************************************************************
// 
// Blackjack - an X windows program of the casino game.
// Copyright (C) 1997  Tom Daley 
// 
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
// 
// The license is in the file COPYING.
// 
// Tom Daley
// 1309 W. Lorraine Ave.
// Woodland Park, CO  80863-2329
// 
// daley@codenet.net (Tom Daley)
// http://users.codenet.net/daley
// 
//*****************************************************************************

#ifndef _BLACKJACK_INCLUDED_
#define _BLACKJACK_INCLUDED_

#include <qpopmenu.h>
#include <qmenubar.h> 
#include <qdict.h>

#include "user_input.h" 
#include "status_display.h" 
#include "table.h" 
#include "shoe.h"

//*****************************************************************************

#define DEFAULT_HELP_FILE ".blackjackrc"
#define MAX_SPLITS	3

//*****************************************************************************

class BlackJack : public QWidget {
      Q_OBJECT
   private:
      enum HelpLevel { FULL_HELP, WARNING, PICKEY, NO_HELP, BAD_HELP };
      enum ShuffleCode { NO_SHUFFLE, DECKS_CHANGED, OUT_OF_CARDS };
      HelpLevel _help;
      QMenuBar *_menu_bar_p;
      StatusDisplay *_status_p; 
      UserInput *_input_p; 
      CardTable *_table_p; 
      Shoe *_shoe_p; 
      int   _current_player_hand;	// starts at 1
      short _dealer_must_play;
      short _hand_in_progress;
      float _min_bet;
      float _max_bet;
      float _bet_inc;
      float _bank_roll;
      int   _shuffle;		// re-shuffle after current hand (flag)
      int   _decks;		// number of decks in shoe
      int   _shuffle_threshold;	// shuffle if # cards in shoe falls below
      int   _max_splits;
      QDict<QString> _help_dict;
 
      void playDealerHand(void);
      void insurance(void);
      void checkShuffle(void);
      void dealCards(void);
      void postDealChecks(void);
      void endOfHands(void);
      void nextHand(void);
      void checkForSplit(void);

      void    readHelpFile(char *name = "");
      QString createHelpFile(QString name);
      QString readHelpLine(QString line);
      QString readVariableLine(QString line);
      QString makeOptionLine(QString name);
      int     addHelpEntry(QString key, QString value);
      QString getHelpIndex(void);
      QString getHelpText(QString help_letters);
      void    checkPreHelp(void); // Full help gives msg before player action
      int     checkPostHelp(char action); // other help gives message after

   public:
      BlackJack(QWidget *parent=0, const char *name=0);
      ~BlackJack();

   private:
      void makeValid(UserInput::InputFlags flags) {
           _input_p->makeValid(flags);
      }
      void makeInvalid(UserInput::InputFlags flags) {
           _input_p->makeInvalid(flags);
      }
      void setHelp(const char *help_text) { 
           _status_p->setHelp(help_text); 
      }
      void setResults(float mult, float bet) {
           _status_p->setResults(mult, bet);
      }
      void outOfCards(void);
   protected:
      void resizeEvent(QResizeEvent *);
   public slots:
      void hit();
      void split();
      void doubleDown();
      void stand();
      void bet();
      void noHelp() { _help = NO_HELP; _status_p->setHelp("No Help"); }
      void warnHelp() { _help = WARNING; _status_p->setHelp("Warning"); }
      void pickeyHelp() { _help = PICKEY; _status_p->setHelp("Pickey"); }
      void fullHelp() { _help = FULL_HELP; checkPreHelp(); }
      void betOptions();
      void tableOptions();
      void saveOptions();
      void about();
      void aboutQt();
};

#endif

//*****************************************************************************

