📄 gouyuappview.cpp
字号:
/* Copyright (c) 2003, Nokia. All rights reserved */
#include <aknutils.h>
#include <eiklabel.h>
#include "GouYuAppView.h"
#include "GouYu.mbg"
#include "GouYuEngine.h"
#include "Player.h"
#include "Card.h"
_LIT (MBMFilename,"GouYu.mbm");
_LIT (P0WIN,"player0 wins!");
_LIT (DRAW,"DRAW!");
_LIT (P1WIN,"player1 wins!");
_LIT (WELCOME,"welcome to fishing!");
CGouYuAppView* CGouYuAppView::NewL(const TRect& aRect)
{
CGouYuAppView* self = CGouYuAppView::NewLC(aRect);
CleanupStack::Pop(self);
return self;
}
CGouYuAppView* CGouYuAppView::NewLC(const TRect& aRect)
{
CGouYuAppView* self = new (ELeave) CGouYuAppView;
CleanupStack::PushL(self);
self->ConstructL(aRect);
return self;
}
CGouYuAppView::CGouYuAppView():iLabel(NULL)
{
// No implementation required
}
CGouYuAppView::~CGouYuAppView()
{
// No implementation required
delete iLabel;
iLabel=NULL;
delete iDesk;
delete iCard;
delete iBack;
isfish = 0 ;
delete iOffScrnBmp;
delete iOffScrnBmpDevice;
delete iOffScrnContext;
}
void CGouYuAppView::ConstructL(const TRect& aRect)
{
TFileName fullname(MBMFilename);
CompleteWithAppPath(fullname);//自动为文件名添加文件路径
CreateWindowL();
iGameStart=EFalse;
iLabel = new (ELeave) CEikLabel;
iLabel->SetContainerWindowL(*this);
iLabel->SetFont( LatinBold12());
SetRect(aRect);
_LIT(KInfo,"Please Config Bluetooth First!\n");
iLabel->SetTextL(KInfo);
isfish = 0 ;
is_f_s = 0 ;
ctr_2 = 0 ;
ct1 = 0 ;
is_f = 0 ;
iDesk = iEikonEnv->CreateBitmapL(fullname,EMbmGouyuDesk);
iBack = iEikonEnv->CreateBitmapL(fullname,EMbmGouyuBack);
SetExtentToWholeScreen();
iOffScrnBmp = new (ELeave)CFbsBitmap;
User::LeaveIfError(iOffScrnBmp->Create(Size(),EColor4K));
iOffScrnBmpDevice = CFbsBitmapDevice::NewL(iOffScrnBmp);
User::LeaveIfError(iOffScrnBmpDevice->CreateContext(iOffScrnContext));
iAppEngine = CEngine::NewL();
iAppEngine->Initial();
// iAppEngine->GenerateCards();
// iAppEngine->Start();
for(TInt i = 0 ; i < 54 ; i++)
{
iAppEngine->cards[i].LoadCard(iEikonEnv->CreateBitmapL(fullname,i));
}
// iDesk = new(ELeave)CFbsBitmap();
// iCard = new(ELeave)CFbsBitmap();
// User::LeaveIfError(iDesk->Load(fullname,54));
ActivateL();
}
void CGouYuAppView::SizeChanged()
{
iLabel->SetRect( Rect() );
}
TInt CGouYuAppView::CountComponentControls() const
{
return 1;
}
CCoeControl* CGouYuAppView::ComponentControl(TInt aIndex) const
{
switch(aIndex)
{
case 0:
return iLabel;
default:
return NULL;
}
}
void CGouYuAppView::NewRound()
{
//for(TInt i= 0;i<iAppEngine->players[iAppEngine->iPlayerNum].handing_cards.Count();i++)
//{
// iAppEngine->players[iAppEngine->iPlayerNum].handing_cards.Reset();
//}
//for(tint i = 0;i<iappengine->players[1].handing_cards.count();i++)
//{
//iappengine->players[1].handing_cards.remove(i);
//}
//for(TInt i = 0;i<iAppEngine->players[iAppEngine->iPlayerNum].score_cards.Count();i++)
//{
// iAppEngine->players[iAppEngine->iPlayerNum].score_cards.Reset();
//}
//for(TInt i = 0;i<iAppEngine->players[1].score_cards.Count();i++)
//{
// iAppEngine->players[1].score_cards.Remove(i);
//}
if( iAppEngine->iPlayerNum == 0)
{
iAppEngine->players[iAppEngine->iPlayerNum].handing_cards.Reset();
iAppEngine->table_cards.Reset();
iAppEngine->GenerateCards();
iAppEngine->Start();
if(iAppEngine->first_compare()==0)
iAppEngine->activeplayer=1;
else
iAppEngine->activeplayer=0;
}
else //if(iAppEngine->iPlayerNum ==1 )
{
// iAppEngine->Start();
/* TInt i=0;
for(;i<2;i++)
{
while(iAppEngine->players[i].handing_cards.Count()>0)
iAppEngine->players[i].handing_cards.Remove(0);
while(iAppEngine->players[i].score_cards.Count()>0)
iAppEngine->players[i].score_cards.Remove(0);
}*/
}
DrawMove();
}
void CGouYuAppView::HandleControlEventL(CCoeControl*,TCoeEvent )
{
}
void CGouYuAppView::ShowMessageL(const TDesC& aMsg)
{
iLabel->SetTextL(aMsg);
DrawNow();
}
void CGouYuAppView::MoveRight() const
{
if(isfish == 0)
{
iAppEngine->iCurrentSelectedCard++;
if(iAppEngine->iCurrentSelectedCard>=iAppEngine->players[iAppEngine->activeplayer].handing_cards.Count())
iAppEngine->iCurrentSelectedCard=0;
DrawMove();
}
if(isfish == 1)
{
iAppEngine->ifishselectedcard++;
iAppEngine->i_table = -1;
if(iAppEngine->ifishselectedcard>=iAppEngine->table_cards.Count())
{
iAppEngine->ifishselectedcard = 0;
}
DrawMove();
}
}
void CGouYuAppView::MoveLeft() const
{
if(isfish == 0)
{
iAppEngine->iCurrentSelectedCard--;
if(iAppEngine->iCurrentSelectedCard<0)
iAppEngine->iCurrentSelectedCard = iAppEngine->players[iAppEngine->activeplayer].handing_cards.Count() - 1;
DrawMove();
}
if(isfish ==1)
{
iAppEngine->ifishselectedcard--;
iAppEngine->i_table = -1;
if(iAppEngine->ifishselectedcard<0)
{
iAppEngine->ifishselectedcard = iAppEngine->table_cards.Count()-1;
}
DrawMove();
}
}
void CGouYuAppView::SelectCard() const
{
if(isfish == 0)
{
if(iAppEngine->iCurrentSelectedCard < 0|| iAppEngine->iCurrentSelectedCard>=iAppEngine->players[iAppEngine->activeplayer].handing_cards.Count())
return;
iAppEngine->iSelectedCardsArray.InsertInOrder(iAppEngine->iCurrentSelectedCard);
DrawMove();
}
if(isfish == 1)
{
if(iAppEngine->ifishselectedcard < 0 || iAppEngine->ifishselectedcard >= iAppEngine->table_cards.Count())
return;
iAppEngine->i_table=iAppEngine->ifishselectedcard;
iAppEngine->is_select = 1;
DrawMove();
}
}
void CGouYuAppView::CancelSelectCards() const
{
if(isfish == 0)
{
if(iAppEngine->iCurrentSelectedCard<0||iAppEngine->iCurrentSelectedCard>=iAppEngine->players[iAppEngine->activeplayer].handing_cards.Count())
return ;
TInt index = iAppEngine->iSelectedCardsArray.FindInOrder(iAppEngine->iCurrentSelectedCard);
if(index ==KErrNotFound)
return ;
else
iAppEngine->iSelectedCardsArray.Remove(index);
DrawMove();
}
if(isfish == 1)
{
if(iAppEngine->ifishselectedcard<0||iAppEngine->ifishselectedcard>=iAppEngine->table_cards.Count())
return;
// TInt index = iAppEngine->i_table_SelectedCardsArray.FindInOrder(iAppEngine->ifishselectedcard);
// if(index == KErrNotFound)
// return;
else
{
if(iAppEngine->table_cards.Count()!=0)
iAppEngine->i_table=-1;
}
DrawMove();
}
}
void CGouYuAppView::Giveup() const
{
iAppEngine->isGiveup=1;
// iAppEngine->iPos_count = 0;
if(iAppEngine->iSelectedCardsArray.Count()==1)
{
iAppEngine->table_cards.Append(iAppEngine->players[iAppEngine->activeplayer].handing_cards[iAppEngine->iSelectedCardsArray[0]]);
iAppEngine->players[iAppEngine->activeplayer].handing_cards.Remove(iAppEngine->iSelectedCardsArray[0]);
iAppEngine->iSelectedCardsArray.Remove(0);
if(iAppEngine->iPos <= 53)
{
iAppEngine->DealCards();
}
else
{
iAppEngine->ctrl_1 = 0 ;
}
iAppEngine->activeplayer = 1-iAppEngine->activeplayer;
iAppEngine->iCurrentSelectedCard = 0 ;
iAppEngine->isok = 0;
DrawMove();
}
}
void CGouYuAppView::Dofish() const
{
if(iAppEngine->ctrl_1 != 1)
{
iAppEngine->isGiveup=0;
iAppEngine->ifishselectedcard = 0;
iAppEngine->i_table = -1 ;
DrawMove();
}
}
void CGouYuAppView::Fishing() const
{
iAppEngine->ax = iAppEngine->cards[iAppEngine->table_cards[iAppEngine->i_table]].value+1;
for(TInt i =0;i<iAppEngine->iSelectedCardsArray.Count();i++)
{
iAppEngine->ay = iAppEngine->ay + iAppEngine->cards[iAppEngine->players[iAppEngine->activeplayer].handing_cards[iAppEngine->iSelectedCardsArray[i]]].value+1;
}
TInt asum = iAppEngine->ax + iAppEngine->ay ;
if(asum == 14 || asum == -2 )
{
iAppEngine->is_success = 1 ;
for(TInt i = 0 ;i<iAppEngine->iSelectedCardsArray.Count();i++)
{
iAppEngine->players[iAppEngine->activeplayer].score_cards.Append(iAppEngine->players[iAppEngine->activeplayer].handing_cards[iAppEngine->iSelectedCardsArray[i]]);
}
iAppEngine->players[iAppEngine->activeplayer].score_cards.Append(iAppEngine->table_cards[iAppEngine->i_table]);
// iAppEngine->iSelectedCardsArray
// iAppEngine->counting = iAppEngine->players[iAppEngine->activeplayer].handing_cards.Count()-iAppEngine->iSelectedCardsArray.Count();
// iAppEngine->table_cards.Remove(iAppEngine->i_table);
// iAppEngine->i_table = -1 ;
// DrawMove();
// while(iAppEngine->iSelectedCardsArray.Count()>0)
iAppEngine->iSelectedCardsArray.Sort();
for(TInt i = iAppEngine->iSelectedCardsArray.Count()-1 ;i>=0;i--)
{
// TInt Index = iAppEngine->players[iAppEngine->activeplayer].handing_cards.FindInOrder(iAppEngine->iSelectedCardsArray[i]);
// if(Index!=KErrNotFound)
// {
iAppEngine->players[iAppEngine->activeplayer].handing_cards.Remove(iAppEngine->iSelectedCardsArray[i]);
// }
}
/* for(TInt j = 0 ; j<=iAppEngine->iSelectedCardsArray.Count() ;j++)
{
iAppEngine->iSelectedCardsArray.Remove(j);
}
*/
while(iAppEngine->iSelectedCardsArray.Count()>0)
{
iAppEngine->iSelectedCardsArray.Remove(iAppEngine->iSelectedCardsArray.Count()-1);
}
// if(iAppEngine->iPos <= 53)
// {
iAppEngine->DealCards();
// }
/*else
{
iAppEngine->ctrl_1 = 0;
iAppEngine->activeplayer=1-iAppEngine->activeplayer;
}*/
DrawMove();
// iAppEngine->ctrl_1=1;
iAppEngine->is_success = 0 ;
iAppEngine->ax = 0;
iAppEngine->ay = 0;
iAppEngine->iCurrentSelectedCard = 0;
if(iAppEngine->iPos<54)
{
iAppEngine->isok = 1;
}
else
{
iAppEngine->isok = 0;
}
}
else
{
while(iAppEngine->iSelectedCardsArray.Count()>0)
{
iAppEngine->iSelectedCardsArray.Remove(iAppEngine->iSelectedCardsArray.Count()-1);
}
iAppEngine->not_success = 1 ;
iAppEngine->is_success = 0 ;
iAppEngine->ax = 0;
iAppEngine->ay = 0;
iAppEngine->iCurrentSelectedCard = 0;
iAppEngine->i_table = -1 ;
DrawMove();
}
}
void CGouYuAppView::DrawMove() const
{
CWindowGc& gc = SystemGc();
gc.Activate( *DrawableWindow() );
/* if(flp1==1)
{
UpdateDisplay1();
}
if(flp2==1)
{
UpdateDisplay2();
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -