📄 arrestdlg.cpp
字号:
}
}
void CArrestDlg::ShowStepsStat()
{
CPaintDC dc(this);// 设备上下文
CWnd* pWnd = GetDlgItem(IDC_STATICFIELD);// 获取绘制坐标的文本框
CDC* pDC = pWnd->GetDC();// 指针
CFont * pOldFont;
CFont newFont;
newFont.CreateFont(
20, // nHeight
0, // nWidth
0, // nEscapement
0, // nOrientation
FW_SEMIBOLD, // nWeight
FALSE, // bItalic
FALSE, // bUnderline
0, // cStrikeOut
ANSI_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_DEFAULT_PRECIS, // nClipPrecision
DEFAULT_QUALITY, // nQuality
DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
"Arial"); // lpszFacename
CString str;
str .Format("%d",m_iStepsStat);
str+=" ";
pOldFont = pDC->SelectObject(&newFont);
pDC->TextOut(iEDGE1*2/3+iEDGE2/3+100,iEDGE2+15,str);
pDC->SelectObject(pOldFont);
}
void CArrestDlg::OnButtonreset()
{
// TODO: Add your control notification handler code here
m_bStartPhase = true;
m_bKeyControl = false;
m_iStepsStat = 0;
m_ThiefMenuDir = STILL;
GetDlgItem(IDC_BUTTONSTART)->SetWindowText("开始");
InitPersonPosition();
DrawField(m_iFieldSize);
DrawPerson(false);
ShowStepsStat();
EnableComboxes(true);
GetDlgItem(IDC_BUTTONSTART)->EnableWindow(true);
m_comThief.SetCurSel(1);
m_comPolice1.SetCurSel(1);
m_comPolice2.SetCurSel(1);
m_comPolice3.SetCurSel(1);
m_comPolice4.SetCurSel(1);
m_comPolice5.SetCurSel(0);
m_comPolice6.SetCurSel(0);
}
void CArrestDlg::EnableComboxes(bool bEnable)
{
m_comboFieldSize.EnableWindow(bEnable);
m_comThief.EnableWindow(bEnable);
m_comPolice1.EnableWindow(bEnable);
m_comPolice2.EnableWindow(bEnable);
m_comPolice3.EnableWindow(bEnable);
m_comPolice4.EnableWindow(bEnable);
m_comPolice5.EnableWindow(bEnable);
m_comPolice6.EnableWindow(bEnable);
}
void CArrestDlg::OnButtonstart()
{
int iNumPolice=0;
int iCombox = 0;
bool bWrongStrategy = false;
// TODO: Add your control notification handler code here
if (m_bStartPhase)
{
iCombox = m_comThief.GetCurSel();
if (iCombox ==CB_ERR)
{
iCombox = 1;
bWrongStrategy = true;
}
m_iPersonStrategy[0] = m_dqThiefStrategy[iCombox];
iCombox = m_comPolice1.GetCurSel();
if (iCombox ==CB_ERR)
{
iCombox = 1;
bWrongStrategy = true;
}
m_iPersonStrategy[1] = m_dqPoliceStrategy[iCombox];
iCombox = m_comPolice2.GetCurSel();
if (iCombox ==CB_ERR)
{
iCombox = 1;
bWrongStrategy = true;
}
m_iPersonStrategy[2] = m_dqPoliceStrategy[iCombox];
iCombox = m_comPolice3.GetCurSel();
if (iCombox ==CB_ERR)
{
iCombox = 1;
bWrongStrategy = true;
}
m_iPersonStrategy[3] = m_dqPoliceStrategy[iCombox];
iCombox = m_comPolice4.GetCurSel();
if (iCombox ==CB_ERR)
{
iCombox = 1;
bWrongStrategy = true;
}
m_iPersonStrategy[4] = m_dqPoliceStrategy[iCombox];
iCombox = m_comPolice5.GetCurSel();
if (iCombox ==CB_ERR)
{
iCombox = 1;
bWrongStrategy = true;
}
m_iPersonStrategy[5] = m_dqPoliceStrategy[iCombox];
iCombox = m_comPolice6.GetCurSel();
if (iCombox == CB_ERR)
{
iCombox = 1;
bWrongStrategy = true;
}
m_iPersonStrategy[6] = m_dqPoliceStrategy[iCombox];
if(bWrongStrategy)
{
MessageBox("策略输入有误,调用默认策略代替!");
}
for (int i=1;i<MAX_NUM_PERSON;i++)
{
if(m_iPersonStrategy[i]!=0)
iNumPolice++;
}
if(iNumPolice<2)
{
MessageBox("警察数目不足!");
return;
}
EnableComboxes(false);
m_bStartPhase = false;
GetDlgItem(IDC_BUTTONSTART)->SetWindowText("下一步");
if (m_iPersonStrategy[0] == 0)
{
m_bKeyControl = true;
GetDlgItem(IDC_BUTTONSTART)->EnableWindow(false);
SetFocus();//让对话框获取键盘出入消息
return;
}
}
m_arsField.SetFieldSize(m_iFieldSize);
if (m_iPersonStrategy[0] == 0)
{
m_arsField.SetThiefMenuDirection(m_ThiefMenuDir);
}
DrawPerson(true);
if(m_arsField.ToArrest(m_ptPerson,m_iPersonStrategy,MAX_NUM_PERSON))
{
MessageBox("围捕成功!");
GetDlgItem(IDC_BUTTONSTART)->EnableWindow(false);
m_bKeyControl = false;
}
m_iStepsStat++;
ShowStepsStat();
DrawPerson(false);
}
void CArrestDlg::ReadStrategy()
{
char tmpName[32];
m_comThief.AddString("人工");
m_dqThiefStrategy.push_back(0);
m_comPolice1.AddString("关闭");
m_comPolice2.AddString("关闭");
m_comPolice3.AddString("关闭");
m_comPolice4.AddString("关闭");
m_comPolice5.AddString("关闭");
m_comPolice6.AddString("关闭");
m_dqPoliceStrategy.push_back(0);
for(int i=0;i<(int)ARSAction::ms_dequeActionRegister.size();i++)
{
//读取贼策略
if (strncmp("Th",ARSAction::ms_dequeActionRegister[i].name,2)==0)
{
strcpy(tmpName,ARSAction::ms_dequeActionRegister[i].name);
m_comThief.InsertString(-1,tmpName);
m_dqThiefStrategy.push_back(i+1);
}
//读取警察策略
if (strncmp("Po",ARSAction::ms_dequeActionRegister[i].name,2)==0)
{
strcpy(tmpName,ARSAction::ms_dequeActionRegister[i].name);
m_dqPoliceStrategy.push_back(i+1);
m_comPolice1.InsertString(-1,tmpName);
m_comPolice2.InsertString(-1,tmpName);
m_comPolice3.InsertString(-1,tmpName);
m_comPolice4.InsertString(-1,tmpName);
m_comPolice5.InsertString(-1,tmpName);
m_comPolice6.InsertString(-1,tmpName);
}
}
m_comThief.SetCurSel(1);
m_comPolice1.SetCurSel(1);
m_comPolice2.SetCurSel(1);
m_comPolice3.SetCurSel(1);
m_comPolice4.SetCurSel(1);
m_comPolice5.SetCurSel(0);
m_comPolice6.SetCurSel(0);
}
void CArrestDlg::OnSelendokCombopolice1()
{
// TODO: Add your control notification handler code here
int iComBox ,iPerson = 1;//
int x=1,y=1,tmp;
iComBox = m_comPolice1.GetCurSel();//
if (iComBox == CB_ERR)
{
return;
}
if (iComBox == 0)
{
if (m_ptPerson[iPerson].x != 0||m_ptPerson[iPerson].y!=0)
{
m_iPersonNum = iPerson;
DrawRect(m_ptPerson[iPerson].x,m_ptPerson[iPerson].y,true);
m_ptPerson[iPerson].x = m_ptPerson[iPerson].y = 0;
}
}
else
{
if (m_ptPerson[iPerson].x == 0&&m_ptPerson[iPerson].y==0)
{
m_iPersonNum = iPerson;
while (ChoicePerson(x,y,tmp))
{
x++;
}
m_ptPerson[iPerson].x = x;
m_ptPerson[iPerson].y = y;
DrawRect(m_ptPerson[iPerson].x,m_ptPerson[iPerson].y,false);
}
}
}
void CArrestDlg::OnSelendokCombopolice2()
{
// TODO: Add your control notification handler code here
int iComBox ,iPerson = 2;//
int x=1,y=1,tmp;
iComBox = m_comPolice2.GetCurSel();//
if (iComBox == CB_ERR)
{
return;
}
if (iComBox == 0)
{
if (m_ptPerson[iPerson].x != 0||m_ptPerson[iPerson].y!=0)
{
m_iPersonNum = iPerson;
DrawRect(m_ptPerson[iPerson].x,m_ptPerson[iPerson].y,true);
m_ptPerson[iPerson].x = m_ptPerson[iPerson].y = 0;
}
}
else
{
if (m_ptPerson[iPerson].x == 0&&m_ptPerson[iPerson].y==0)
{
m_iPersonNum = iPerson;
while (ChoicePerson(x,y,tmp))
{
x++;
}
m_ptPerson[iPerson].x = x;
m_ptPerson[iPerson].y = y;
DrawRect(m_ptPerson[iPerson].x,m_ptPerson[iPerson].y,false);
}
}
}
void CArrestDlg::OnSelendokCombopolice3()
{
// TODO: Add your control notification handler code here
int iComBox ,iPerson = 3;//
int x=1,y=1,tmp;
iComBox = m_comPolice3.GetCurSel();//
if (iComBox == CB_ERR)
{
return;
}
if (iComBox == 0)
{
if (m_ptPerson[iPerson].x != 0||m_ptPerson[iPerson].y!=0)
{
m_iPersonNum = iPerson;
DrawRect(m_ptPerson[iPerson].x,m_ptPerson[iPerson].y,true);
m_ptPerson[iPerson].x = m_ptPerson[iPerson].y = 0;
}
}
else
{
if (m_ptPerson[iPerson].x == 0&&m_ptPerson[iPerson].y==0)
{
m_iPersonNum = iPerson;
while (ChoicePerson(x,y,tmp))
{
x++;
}
m_ptPerson[iPerson].x = x;
m_ptPerson[iPerson].y = y;
DrawRect(m_ptPerson[iPerson].x,m_ptPerson[iPerson].y,false);
}
}
}
void CArrestDlg::OnSelendokCombopolice4()
{
// TODO: Add your control notification handler code here
int iComBox ,iPerson = 4;//
int x=1,y=1,tmp;
iComBox = m_comPolice4.GetCurSel();//
if (iComBox == CB_ERR)
{
return;
}
if (iComBox == 0)
{
if (m_ptPerson[iPerson].x != 0||m_ptPerson[iPerson].y!=0)
{
m_iPersonNum = iPerson;
DrawRect(m_ptPerson[iPerson].x,m_ptPerson[iPerson].y,true);
m_ptPerson[iPerson].x = m_ptPerson[iPerson].y = 0;
}
}
else
{
if (m_ptPerson[iPerson].x == 0&&m_ptPerson[iPerson].y==0)
{
m_iPersonNum = iPerson;
while (ChoicePerson(x,y,tmp))
{
x++;
}
m_ptPerson[iPerson].x = x;
m_ptPerson[iPerson].y = y;
DrawRect(m_ptPerson[iPerson].x,m_ptPerson[iPerson].y,false);
}
}
}
void CArrestDlg::OnSelendokCombopolice5()
{
// TODO: Add your control notification handler code here
int iComBox ,iPerson = 5;//
int x=1,y=1,tmp;
iComBox = m_comPolice5.GetCurSel();//
if (iComBox == CB_ERR)
{
return;
}
if (iComBox == 0)
{
if (m_ptPerson[iPerson].x != 0||m_ptPerson[iPerson].y!=0)
{
m_iPersonNum = iPerson;
DrawRect(m_ptPerson[iPerson].x,m_ptPerson[iPerson].y,true);
m_ptPerson[iPerson].x = m_ptPerson[iPerson].y = 0;
}
}
else
{
if (m_ptPerson[iPerson].x == 0&&m_ptPerson[iPerson].y==0)
{
m_iPersonNum = iPerson;
while (ChoicePerson(x,y,tmp))
{
x++;
}
m_ptPerson[iPerson].x = x;
m_ptPerson[iPerson].y = y;
DrawRect(m_ptPerson[iPerson].x,m_ptPerson[iPerson].y,false);
}
}
}
void CArrestDlg::OnSelendokCombopolice6()
{
// TODO: Add your control notification handler code here
int iComBox ,iPerson = 6;//
int x=1,y=1,tmp;
iComBox = m_comPolice6.GetCurSel();//
if (iComBox == CB_ERR)
{
return;
}
if (iComBox == 0)
{
if (m_ptPerson[iPerson].x != 0||m_ptPerson[iPerson].y!=0)
{
m_iPersonNum = iPerson;
DrawRect(m_ptPerson[iPerson].x,m_ptPerson[iPerson].y,true);
m_ptPerson[iPerson].x = m_ptPerson[iPerson].y = 0;
}
}
else
{
if (m_ptPerson[iPerson].x == 0&&m_ptPerson[iPerson].y==0)
{
m_iPersonNum = iPerson;
while (ChoicePerson(x,y,tmp))
{
x++;
}
m_ptPerson[iPerson].x = x;
m_ptPerson[iPerson].y = y;
DrawRect(m_ptPerson[iPerson].x,m_ptPerson[iPerson].y,false);
}
}
}
BOOL CArrestDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
bool bAvailable = false;
if(pMsg->message==WM_KEYDOWN)
{
if (m_bKeyControl)
{
switch(pMsg->wParam)
{
case 88://X
m_ThiefMenuDir = DOWN;
bAvailable = true;
break;
case 65://A
m_ThiefMenuDir = LEFT;
bAvailable = true;
break;
case 83://S
m_ThiefMenuDir = STILL;
bAvailable = true;
break;
case 68://D
m_ThiefMenuDir = RIGHT;
bAvailable = true;
break;
case 87://W
m_ThiefMenuDir = UP;
bAvailable = true;
break;
default:
break;
}
if (bAvailable)
{
OnButtonstart();
}
}
}
return CDialog::PreTranslateMessage(pMsg);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -