VC++ 2008开发网络百家乐街机游戏(下)
2009-02-27 20:03:11 来源:WEB开发网在OnKeyDown函数中响应玩家的所有按键操作,编码如下:
void CTH_ROUND_WINDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
//响应关机按钮
if(nChar==VK_RETURN)
{
typedef int (CALLBACK*SHUTDOWNDLG)(int);
HINSTANCE hInst=LoadLibrary("shell32.dll");
SHUTDOWNDLG ShutDownDialog;
if(hInst!=NULL)
{
ShutDownDialog=(SHUTDOWNDLG)GetProcAddress(hInst,(LPSTR)60);
(*ShutDownDialog)(0);
}
exit(0);
}
//一号机到十号机的按键划分
if(nChar==81||nChar==87||nChar==69||nChar==85||nChar==82||nChar==73)
Mac_sf01(nChar);//一号机按键函数
……
if(nChar==71||nChar==72||nChar==0x1B||nChar==0x75||nChar==0x73||nChar==0x7A)
Mac_sf10(nChar);//十号机按键函数
CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
}
以一号机为例介绍按键函数部分编码如下:
void CTH_ROUND_WINDlg::Mac_sf01(UINT nChar)
{
CString strdjs;
m_djs.GetWindowText(strdjs);
int intdjs=atoi(strdjs.operator LPCTSTR());
if(nChar==81)//小分按键
{
m_sf[0].ShowWindow(SW_SHOW);
m_sf[0].SetText(string_dzsf1);
return;
}
if(nChar==87)//大分按键
{
m_sf[0].ShowWindow(SW_SHOW);
m_sf[0].SetText(string_dzsf2);
return;
}
if(nChar==69&&intdjs>10)//取消按键分值
{
……
try
{
CDATABE_ADO m_datado;
m_datado.Open("TH_ROUND","admin/admin","flyingtjf");
m_datado.OpenTable("select * from th_round_single01");
m_datado.SetField("single_ztf",string_hyzsf);
m_datado.SetField("red","0");
m_datado.SetField("black","0");
m_datado.SetField("green","0");
m_zsf[0].SetWindowText(string_hyzsf);
m_red[0].SetWindowText("0");
m_black[0].SetWindowText("0");
m_green[0].SetWindowText("0");
m_datado.Close();
}
catch(...)
{
}
m_sf[0].ShowWindow(SW_HIDE);
return;
}
if(nChar==85&&(intdjs>10||string_bjlprec!="红色"))//红色下分
{
……
if(Determined_sf(atoi(string_dzsf.operator LPCTSTR()),0))
{
try
{
CDATABE_ADO m_datado;
m_datado.Open("TH_ROUND","admin/admin","flyingtjf");
m_datado.OpenTable("select * from th_round_single01");
int intsf=atoi(string_dzsf.operator LPCTSTR());
int intsingle_ztf=atoi(m_datado.GetField("single_ztf").operator LPCTSTR());
int int_red=atoi(string_red.operator LPCTSTR());
if(intsingle_ztf-intsf>=0)
{
intsingle_ztf-=intsf;
CString strsingle_ztf;
strsingle_ztf.Format("%d",intsingle_ztf);
int_red+=intsf;
CString strsingle_red;
strsingle_red.Format("%d",int_red);
m_datado.SetField("single_ztf",strsingle_ztf);
m_datado.SetField("red",strsingle_red);
m_zsf[0].SetWindowText(strsingle_ztf);
m_red[0].SetWindowText(strsingle_red);
}
m_datado.Close();
}
catch(...)
{
}
}
m_sf[0].ShowWindow(SW_HIDE);
return;
}
if(nChar==82&&(intdjs>10||string_bjlprec!="黑色"))//黑色下分
{
……
}
if(nChar==73&&(intdjs>10||string_bjlprec!="绿色"))//绿色下分
{
……
}
}
更多精彩
赞助商链接