/*

	card.h (Korttiolion esittely)

	V1.00 - 141096	Kimmo Teräväinen
	-----   ------  -------------------------------------
	V0.05   141096  1. proposal for card object (non-graphical)
        V0.06   151096  cKortti is inherited from caKuvio
        V0.07   201096  cKortti is not inherited from caKuvio
        V0.08   201096  cIMGKortti transfered here form handpile.h
        V0.09   031196  cKortti->cCard, cIMGKortti-> cIMGCard

*/
#ifndef DC1_POKER_CARD
#define DC1_POKER_CARD

#include "image.h"

typedef enum {
  SPADE,
  HEART,
  CROSS,
  DIAMOND,
  JOKER
} tCardSuit;

typedef int tNum;

const int A_LOW = 0;    // ACE small value
const int A     = 0;    // ACE
const int T     = 9;    // Ten, smallest card belong to Royal Flush
const int J     = 10;   // Jack
const int Q     = 11;   // Queen
const int K     = 12;   // King
const int A_HI  = 13;   // ACE huge value


const int CARD_WIDTH    = 71;   // card sizes
const int CARD_HEIGHT   = 96;   //

const int JOKER1_CARD   = 52;   // red joker
const int JOKER2_CARD   = 53;   // black joker
const int JOKER3_CARD   = 54;   // extra jokers
const int MASK_CARD     = 55;   // mask card
const int TURNED_CARD   = 56;   // background

const int MAX_JOKERS    = 8;    // biggest allowed joker amount
const int CARDS_MAX_LKM = 52 + MAX_JOKERS;

#define CARD_MASK_GFX cPoint(3*CARD_WIDTH,4*CARD_HEIGHT)
#define CARD_TURNED_GFX cPoint(4*CARD_WIDTH,4*CARD_HEIGHT)

/*****************************************************************
  cCard
*****************************************************************/
class cCard {
  tCardSuit suit;
  tNum num;
public:
  cCard() {}
  cCard(int id) { Set(id); }
  cCard(tCardSuit nsuit,tNum nnum) { suit=nsuit,num=nnum; }

  void Set(int id);
  tCardSuit Suit()   const { return suit; }
  tNum      Num()    const { return num; }
  tNum      Num_HI() const {
    if(num==A) return A_HI;
    return num;
  }
  int Suit_as_Int() const;
};


/*****************************************************************
  cIMGCard
*****************************************************************/
class cIMGCard : public cImage, public cCard {
  int turned;   // TRUE=Cover down
  int canturn;  // TRUE=Card may be turned
public:
  cIMGCard(TWindow *Wnd,const TBitmap *ncards,const cPoint &pos,const cCard &card) :
    cImage(Wnd,ncards,pos.X(),pos.Y(),CARD_WIDTH,CARD_HEIGHT),
    cCard(card)
  {
    turned=FALSE;
    canturn=FALSE;
    SetMask(CARD_MASK_GFX);
    SetGfx();
  }
  void SetGfx() {
    if(turned) {
      SetData(CARD_TURNED_GFX);
      Draw();
    } else {
      int x=Num(),y=Suit_as_Int()*CARD_HEIGHT;
      tCardSuit suit=Suit();
      if(suit==JOKER) if(x>2) x=2;
      SetData(x*CARD_WIDTH,y);
      Draw();
    }
  }

  virtual void Clicked() { Turn(); }

  void CanTurn(int attr=TRUE) { canturn=attr; }

  void Turn()           { if(canturn) { turned=!turned; SetGfx();} }
  void Turn_CoverUp()   { turned=FALSE;   SetGfx(); }
  void Turn_CoverDown() { turned=TRUE;    SetGfx(); }

  int  Turned() const   { return turned;}
#ifdef _Windows
  DECLARE_RESPONSE_TABLE(cIMGCard);
#endif
};

#endif