📄 gouyuengine.cpp
字号:
#include "GouYuEngine.h"
#include <e32math.h>
#include <aknutils.h>
#include <AknNoteWrappers.h>//?
#include "GouYuAppView.h"
CEngine* CEngine::NewLC(/*CGouYuAppView* aAppView*/)
{
CEngine * self = new (ELeave)CEngine(/*aAppView*/);
CleanupStack::PushL(self);
self->ConstructL(/*aAppView*/);
return self;
}
CEngine* CEngine::NewL(/*CGouYuAppView* aAppView*/)
{
CEngine * self = CEngine::NewLC(/*aAppView*/);
CleanupStack::Pop(self);
return self;
}
CEngine::CEngine(/*CGouYuAppView* aAppView*/)
{
// iAppView = aAppView ;
cards = new (ELeave) CCard[54];
players = new (ELeave) Player[2];
temp = new (ELeave) TInt8[54];
}
void CEngine::ConstructL(/*CGouYuAppView* aAppView*/)
{
// iAppView = aAppView ;
}
CEngine::~CEngine()
{
for(TInt i = 0 ; i<2 ; i++)
{
for(TInt j = 0 ;j<players[i].handing_cards.Count();j++)
players[i].handing_cards.Remove(0);
}
iSelectedCardsArray.Close();
delete cards;
delete players;
delete temp;
// delete iAppView;
}
void CEngine::GenerateCards()
{
TTime now;
now.HomeTime();
TInt64 irandomseed = now.Int64();
TInt i = 0 ;
while(i<54)
{
TInt8 num = Math::Rand(irandomseed)%54;
TInt flag = 0 ;
for(TInt j = 0;j<i;j++)
{
if(temp[j] == num)
{
flag = 1 ;
break ;
}
}
if(flag == 0)
{
temp[i] = num;
i++;
}
}
}
void CEngine::DealCards()
{
iPos_count = 0;
if(isGiveup == 1)
{
if(players[activeplayer].handing_cards.Count()==3) //或许将成为隐患之一solved
{}
else
{
if(iPos<=53)
{
players[activeplayer].handing_cards.Append(temp[iPos++]);
iPos_count = 1;
}
else
{
}
}
ctrl_1 = 0;
}
if(is_success == 1)
{
while( players[activeplayer].handing_cards.Count()< 4)
{
if(iPos<=53)
{
players[activeplayer].handing_cards.Append(temp[iPos++]);
iPos_count++;
}
if(iPos >= 54)
{
break;
}
// else
// {
// players[activeplayer].handing_cards.Append(temp[iPos]);
// iPos_count++;
// break;
// }
}
isGiveup = 1 ;
ctrl_1 = 1 ;
if(/*iPos >= 54 && */players[activeplayer].handing_cards.Count() <= 3)
{
activeplayer = 1 - activeplayer ;
ctrl_1 = 0;
}
}
/*iPos = iPos+iPos_count*/;
}
void CEngine::Start()
{
iPos = 0;
TInt i=0;
for(;i<2;i++)
{
while(players[i].handing_cards.Count()>0)
players[i].handing_cards.Remove(0);
while(players[i].score_cards.Count()>0)
players[i].score_cards.Remove(0);
}
i = 0 ;
while(i<6)
{
players[0].handing_cards.Append(temp[i]);
players[1].handing_cards.Append(temp[i+1]);
i+=2;
}
table_cards.Append(temp[6]);
table_cards.Append(temp[7]);
players[0].ipos=10;
players[1].ipos=120;
iPos = 8;
}
void CEngine::Initial()
{
iCurrentSelectedCard = 0 ;
ifishselectedcard = -1 ;
is_select = 0;
i_table = 0;
is_success=0;
isGiveup =0;
not_success = 0;
ax = 0 ;
ay = 0 ;
ctrl_1 = 0 ;
iPos_count = 0;
isok = 0;
// counting = 0;
// deal_label = 0 ;
for(TInt8 i = 0;i<52;i++)
{
cards[i].id = i ;
cards[i].type = i/13 ;
cards[i].value = i%13 ;
// cards[i].type为扑克牌的花色,0为方片,1为草花,2为红桃,3为黑桃
// cards[i].value为扑克牌的大小,各花色分别从0到12,小王为13,大王为14,其中小王和大王的大小无用
if(cards[i].type==0)
cards[i].point=1;
if(cards[i].type==1)
cards[i].point=2;
if(cards[i].type==2)
cards[i].point=3;
if(cards[i].type==3)
cards[i].point=4;
}
cards[52].id=52;
cards[52].type=3;
cards[52].value=-2;
cards[52].point=4;
cards[53].id=53;
cards[53].type=2;
cards[53].value=-2;
cards[53].point=3;
}
TInt CEngine::first_compare()
{
if(table_cards[0]<table_cards[1])
return 0;
else
return 1;
}
CCard* CEngine::GetCard(TInt cid)
{
return &cards[cid];
}
void CEngine::CountPoint(TInt i)
{
TInt totalcount=players[i].score_cards.Count();
TInt tscore=0;
for(TInt j=0;j<totalcount;j++)
{
if(cards[players[i].score_cards[j]].type==0)
{
tscore+=1;
}
if(cards[players[i].score_cards[j]].type==1)
{
tscore+=2;
}
if(cards[players[i].score_cards[j]].type==2)
{
tscore+=3;
}
if(cards[players[i].score_cards[j]].type==3)
{
tscore+=4;
}
}
players[i].iPoint=tscore;
}
TInt CEngine::CompareScore(TInt i,TInt j)
{
if(players[i].iPoint>players[j].iPoint)
return 0 ;
if(players[i].iPoint==players[j].iPoint)
return -1 ;
if(players[i].iPoint>players[j].iPoint)
return 1 ;
}
void CEngine::SetPlayerNum(TInt8 aNum)
{
iPlayerNum = aNum;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -