洗牌的一個C++類! (轉)

worldblog發表於2007-08-16
洗牌的一個C++類! (轉)[@more@]

這是一個洗牌的類!
提供了幾個簡單的藉口!
bool __fastcall Refresh();洗牌
int __fastcall Getbyindex(int _index);根據順序引數來取牌;
GRefresh_Card(int _CardNum=54);初始化,_CardNum是牌的張數,預設的事54;
void free();用來釋放一些必要的東西;
AnsiString Getusefully(int _index);真實取牌,帶色!Code如下:

//---------------------------------------------------------------------------


#pragma hdrstop

#include "RefC.h"
#include
#include
#include
#include
//---------------------------------------------------------------------------

#pragma package(smart_init)
GRefresh_Card::~GRefresh_Card()
{
  //Îö¹¹
  free();

}

bool __fastcall GRefresh_Card::Refresh()
{
  //Ï´ÅÆ
  bool Card_Result=false;
  srand((unsigned)time(NULL));  //+ Ôö¼ÓÕâÒ»ÐУ¬ÒÔʱ¼ä×÷ΪËæ»úÊýÖÖ×Ó
  std::ran_shuffle(Card->begin(),Card->end());
  return Card_Result;
}

int __fastcall GRefresh_Card::Getbyindex(int _index)
{
  //ÄÇÅÆ£»
  return (_index>=0 && _indexoperator [](_index):0;

}

GRefresh_Card::GRefresh_Card(int _CardNum)
{
  //³õʼ»¯£»
  Card_Num=_CardNum;
  Card=new std::vector;
  for(int i=0;i<54;i++)
  Card->push_back(i);
  Card_color=new TStringList();
  Card_color->Add("·½¿é");
  Card_color->Add("÷»¨");
  Card_color->Add("ºìÌÒ");
  Card_color->Add("ºÚÌÒ");
}

void GRefresh_Card::free()
{
  delete  Card;
  Card=NULL;
  delete Card_color;
  Card_color=NULL;
}

AnsiString GRefresh_Card::Getusefully(int _index)
{
  int _color=Getbyindex(_index)%13;
  int _value=Getbyindex(_index)/13;
  if(_value>3)
  {
  AnsiString result;
  _color? result="´óÍõ":result="СÍõ";
  return result;
  }
  else
  {
  AnsiString result=Card_color->operator [](_value)+IntToStr(_color+1);
  return result;
  }
}

//---------------------------------------------------------------------------

#ifndef RefCH
#define RefCH
#include
#include
//---------------------------------------------------------------------------
class GRefresh_Card {
protected:
  int Card_Num;
  std::vector * Card;
  TStringList * Card_color;
public:
  ~GRefresh_Card();
  bool __fastcall Refresh();
  int __fastcall Getbyindex(int _index);
  GRefresh_Card(int _CardNum=54);
  void free();
  AnsiString Getusefully(int _index);};
#endif


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752043/viewspace-962104/,如需轉載,請註明出處,否則將追究法律責任。

相關文章