📄 single_game.cpp
字号:
// Single_Game.cpp: implementation of the CSingleGame class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "斗地主.h"
#include "MainFrm.h"
#include "My_DirectInput.h"
#include "my_directdraw.h"
#include "Playing_Cards.h"
#include "Game.h"
#include "Draw_Item_Engine.h"
#include "Draw_Cards_Engine.h"
#include "Single_Game.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CSingleGame::CSingleGame()
{
}
CSingleGame::~CSingleGame()
{
}
//决定地主 ;
int CSingleGame::DecideLord()
{
//产生地主;
m_nDefaultLord = rand()%3;
// m_nDefaultLord = 2;
pDrawItem->BringRandLord(m_nDefaultLord);
m_nCurrentLord = m_nDefaultLord;
int High = -1;
int My_Cards_Value = pCenterCards->AccountCardsValue();
int Left_Cards_Value = pLeftCards->AccountCardsValue();
int Right_Cards_Value = pRightCards->AccountCardsValue();
if( My_Cards_Value >= Right_Cards_Value )
{
if( My_Cards_Value >= Left_Cards_Value)
{
High = 1;
}
else
{
High = 0;
}
}
else
{
if( Right_Cards_Value >= Left_Cards_Value )
{
High = 2;
}
else
{
High = 0;
}
} //end if;
// char info[50];
// sprintf(info,"Left:%d Center:%d Right:%d\n",\
// Left_Cards_Value,My_Cards_Value,Right_Cards_Value);
// AfxMessageBox(info);
// Sleep(10000);
// pDraw->DebugText(info,1000);
int counter = 0;
while(1)
{
if( m_nCurrentLord ==1 )
{
while(1)
{
pDrawItem->ChooseLord();
if( pInput->IsLButtonDown(m_cYES_RECT) ) //要
{
//相关处理;
PlaySound(MAKEINTRESOURCE(IDR_CHOSE),AfxGetResourceHandle(),
SND_ASYNC|SND_RESOURCE|SND_NODEFAULT ); //
pDrawItem->GameInfo(m_nCurrentLord,0);
Sleep(500); //产生一个延时;
goto out;
}
else if( pInput->IsLButtonDown(m_cNO_RECT) ) //不要
{
//相关处理;
PlaySound(MAKEINTRESOURCE(IDR_CHOSE),AfxGetResourceHandle(),
SND_ASYNC|SND_RESOURCE|SND_NODEFAULT ); //
counter++;
if( counter == 3 )
{
m_nCurrentLord = m_nDefaultLord;
pDrawItem->GameInfo(m_nDefaultLord,2);
goto out;
}
pDrawItem->GameInfo(m_nCurrentLord,1);
Sleep(500); //产生一个延时;
m_nCurrentLord = 2;
break;
}
Sleep(50); //产生一个延时;
}
}
else if( m_nCurrentLord == 0 )
{
//根据当前牌决定是否当地主;
if( High == 0 ) //当
{
pDrawItem->GameInfo(m_nCurrentLord,0);
goto out;
}
else //不当;
{
counter++;
if( counter == 3 )
{
m_nCurrentLord = m_nDefaultLord;
pDrawItem->GameInfo(m_nDefaultLord,2);
goto out;
}
pDrawItem->GameInfo(m_nCurrentLord,1);
Sleep(500); //产生一个延时;
m_nCurrentLord = 1;
}
}
else if( m_nCurrentLord == 2 )
{
//根据当前牌决定是否当地主;
if( High == 2 ) //当
{
pDrawItem->GameInfo(m_nCurrentLord,0);
goto out;
}
else //不当;
{
counter++;
if( counter == 3 )
{
m_nCurrentLord = m_nDefaultLord;
pDrawItem->GameInfo(m_nDefaultLord,2);
goto out;
}
pDrawItem->GameInfo(m_nCurrentLord,1);
Sleep(500); //产生一个延时;
m_nCurrentLord = 0;
}
}
}//end while;
out:
return 1;
}
//int CSingleGame::Bring_Rand_Lord()
int CSingleGame::Run()
{
//开始新的牌局;
NewGame();
//显示局数;
pDrawItem->GameCounter(m_nGameCounter);
//洗牌;
ShuffleCards();
//发牌;
pDrawCards->Dealing();
pLeftCards->ScanToTable();
pRightCards->ScanToTable();
//决定地主;
DecideLord();
pDrawCards->DealingLord(m_nCurrentLord); //发地主牌;
m_bOperate = TRUE;
//开始循环;
if(m_nCurrentLord == 0)
{
LeftDoing();
::SetTimer(hWnd,20,50,NULL);
}
else if(m_nCurrentLord == 1)
{
::SetTimer(hWnd,20,50,NULL);
}
else if(m_nCurrentLord == 2)
{
RightDoing();
LeftDoing();
::SetTimer(hWnd,20,50,NULL);
}
return 1;
}
//左边玩家(电脑)思考,并决定要出的牌;
int CSingleGame::LeftDoing()
{
if( m_nRoundCounter == 3 ) //说明已经出了牌;
{
//把已经出的牌回退;
if(pLeftCards->m_nDiscardingCounter != 0)
pDrawCards->LeftBacking();
if(pCenterCards->m_nDiscardingCounter != 0)
pDrawCards->CenterBacking();
if(pRightCards->m_nDiscardingCounter != 0)
pDrawCards->RightBacking();
m_nRoundCounter = 0; //新的一圈;
}
m_nRoundCounter++;
if( m_nLordLock == 0 )
{
return -1;
}
if(pRightCards->m_cDiscardingType.m_nTypeNum == 0 &&
pCenterCards->m_cDiscardingType.m_nTypeNum == 0)
{
m_nLordLock = -1; //解锁;
//开始新的一回合,选择一种牌型出;
pLeftCards->DirectChoose();
if( pLeftCards->m_cDiscardingType.m_nTypeNum == 4 )
{
m_nBombCounter++;//加分;
}
pLeftCards->CleanUp();
pDrawCards->LeftDiscarding();
::RedrawGame();
if( pLeftCards->m_nCardsCounter == 0 )
{
//打印结束信息;
if(m_nCurrentLord == 2 )
{
PlaySound(MAKEINTRESOURCE(IDR_WIN),AfxGetResourceHandle(),
SND_ASYNC|SND_RESOURCE|SND_NODEFAULT ); //
}
else
{
PlaySound(MAKEINTRESOURCE(IDR_LOSE),AfxGetResourceHandle(),
SND_ASYNC|SND_RESOURCE|SND_NODEFAULT ); //
}
pDrawCards->m_bVisual = TRUE;
AccountScore(0);
::SetTimer(hWnd,0,0,NULL); //开始游戏;
return 0;
}
return 1;
}
//1.两者都不能大牌,我是最大;
//2.新的一回合开始,我先出;
if(pRightCards->m_cDiscardingType.m_nTypeNum != 0 )
{
//如果同伙出了比较大的牌,则不跟;
if( m_nCurrentLord == 1 &&
m_nLordLock == 1 &&
pRightCards->m_cDiscardingType.m_nTypeValue > 13 )
{
//不要;
pLeftCards->m_cDiscardingType.m_nTypeNum = 0;
pDraw->TextGDI("过牌!-",250,200,RGB(255,0,0),400,"华文新魏",lpddsprimary);
//补丁:地主一旦过牌,本轮内都不能再出牌;
Sleep(300);
return 1;
}
if( pLeftCards->CompareChoose(pRightCards->m_cDiscardingType) )
{
if( pLeftCards->m_cDiscardingType.m_nTypeNum == 4 )
{
m_nBombCounter++;//加分;
}
pLeftCards->CleanUp();
pDrawCards->LeftDiscarding();
::RedrawGame();
if( pLeftCards->m_nCardsCounter == 0 )
{
//打印结束信息;
if(m_nCurrentLord == 2 )
{
PlaySound(MAKEINTRESOURCE(IDR_WIN),AfxGetResourceHandle(),
SND_ASYNC|SND_RESOURCE|SND_NODEFAULT ); //
}
else
{
PlaySound(MAKEINTRESOURCE(IDR_LOSE),AfxGetResourceHandle(),
SND_ASYNC|SND_RESOURCE|SND_NODEFAULT ); //
}
pDrawCards->m_bVisual = TRUE;
AccountScore(0);
::SetTimer(hWnd,0,0,NULL); //开始游戏;
return 0;
}
}
else
{
//补丁:地主一旦过牌,本轮内都不能再出牌;
if( m_nCurrentLord == 0 )
{
m_nLordLock = 0;
}
//不要;
pLeftCards->m_cDiscardingType.m_nTypeNum = 0;
pDraw->TextGDI("过牌!-",250,200,RGB(255,0,0),400,"华文新魏",lpddsprimary);
Sleep(300);
}
}
else
{
//如果同伙出了比较大的牌,则不跟;
if( m_nCurrentLord == 2 &&
m_nLordLock == 2 &&
pCenterCards->m_cDiscardingType.m_nTypeValue > 13 )
{
//不要;
pLeftCards->m_cDiscardingType.m_nTypeNum = 0;
pDraw->TextGDI("过牌!-",250,200,RGB(255,0,0),400,"华文新魏",lpddsprimary);
Sleep(300);
return 1;
}
//如果上家没出牌,则根据上上家决定出牌;
if( pLeftCards->CompareChoose(pCenterCards->m_cDiscardingType) )
{
if( pLeftCards->m_cDiscardingType.m_nTypeNum == 4 )
{
m_nBombCounter++;//加分;
}
pLeftCards->CleanUp();
pDrawCards->LeftDiscarding();
::RedrawGame();
if( pLeftCards->m_nCardsCounter == 0 )
{
//打印结束信息;
if(m_nCurrentLord == 2 )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -