?? searchpathview.cpp
字號:
{
if(m_ifLBTUp == 0)//如果在地圖制作模式里面左鍵沒有松開,而且鼠標在移動
{
int x,y;
x = point.x/5;
y = point.y/5;
map[y][x] = m_ModeOfMakeMap;
map[y-1][x] = m_ModeOfMakeMap;
map[y][x-1] = m_ModeOfMakeMap;
map[y-1][x-1] = m_ModeOfMakeMap;
Invalidate();//使窗口重繪
}
}
CView::OnMouseMove(nFlags, point);
}
void CSearchPathView::OnSaveMap()
{
// TODO: Add your command handler code here
if(m_numSaveMap >= 5)
{
AfxMessageBox("在一個文本文件中最多可以保存5幅地圖,請把同一目錄下的SaveMap文件刪除或改名,以保存更多的地圖!");
return;
}
m_numSaveMap++;//先累計用戶保存的地圖數目
ofstream outs;
outs.open("SaveMap.txt",ios::app);
outs<<"///map"<<m_numSaveMap<<"///"<<endl;
for(int i = 0;i < Height;i++)
{
for(int j = 0;j < Width;j++)
{
if(map[i][j] == 0)
{
outs<<" "<<map[i][j]<<",";
}
else
{
outs<<map[i][j]<<",";
}
}
outs<<endl;
}
outs.close();
CMenu *mainmenu;
mainmenu=AfxGetMainWnd()->GetMenu(); //得到主菜單
//(mainmenu->GetSubMenu (6))->AppendMenu (MF_SEPARATOR);//添加分隔符
CString name;
CString temp(m_numSaveMap + 48);
name = " save_map" + temp;
(mainmenu->GetSubMenu (6))->AppendMenu(MF_STRING,IDM_SaveMap1 + m_numSaveMap - 1,_T(name)); //添加新的菜單項
DrawMenuBar(); //重畫菜單
AfxMessageBox("地圖已經保存!");
}
void CSearchPathView::OnSaveMap1()
{
CFile IndexFile;
if(IndexFile.Open("SaveMap.txt",CFile::modeRead))
{}
else
{
AfxMessageBox("cant open result.txt!");
return;
}
IndexFile.SeekToBegin();
char character[1];
character[1] = NULL;
IndexFile.SeekToBegin();
while (IndexFile.Read(character,1))
{
if(character[0] == '/')
{
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
if(character[0] == '1')
{
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
for(int i = 0;i < Height;i++)
{
for(int j = 0;j < Width;j++)
{
IndexFile.Read(character,1);
IndexFile.Read(character,1);
map[i][j] = -((int)character[0] - 48);
IndexFile.Read(character,1);
}
IndexFile.Read(character,1);
IndexFile.Read(character,1);
}
break;
}
}
}
m_SearchSort = 0;//which alg are you use.
m_ifOpen = 0;//等于一的時候就可以輸入起點和終點
m_ifDouble = 0;//表示沒有雙擊
m_ifMakemap = 0;//表示不能編輯地圖
m_showMode = 0;//不顯示搜索過的節點
IndexFile.Close();
Invalidate();
}
void CSearchPathView::OnSaveMap2()
{
CFile IndexFile;
if(IndexFile.Open("SaveMap.txt",CFile::modeRead))
{}
else
{
AfxMessageBox("cant open result.txt!");
return;
}
IndexFile.SeekToBegin();
char character[1];
character[1] = NULL;
IndexFile.SeekToBegin();
while (IndexFile.Read(character,1))
{
if(character[0] == '/')
{
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
if(character[0] == '2')
{
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
for(int i = 0;i < Height;i++)
{
for(int j = 0;j < Width;j++)
{
IndexFile.Read(character,1);
IndexFile.Read(character,1);
map[i][j] = -((int)character[0] - 48);
IndexFile.Read(character,1);
}
IndexFile.Read(character,1);
IndexFile.Read(character,1);
}
break;
}
}
}
m_SearchSort = 0;//which alg are you use.
m_ifOpen = 0;//等于一的時候就可以輸入起點和終點
m_ifDouble = 0;//表示沒有雙擊
m_ifMakemap = 0;//表示不能編輯地圖
m_showMode = 0;//不顯示搜索過的節點
IndexFile.Close();
Invalidate();
}
void CSearchPathView::OnSaveMap3()
{
CFile IndexFile;
if(IndexFile.Open("SaveMap.txt",CFile::modeRead))
{}
else
{
AfxMessageBox("cant open result.txt!");
return;
}
IndexFile.SeekToBegin();
char character[1];
character[1] = NULL;
IndexFile.SeekToBegin();
while (IndexFile.Read(character,1))
{
if(character[0] == '/')
{
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
if(character[0] == '3')
{
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
for(int i = 0;i < Height;i++)
{
for(int j = 0;j < Width;j++)
{
IndexFile.Read(character,1);
IndexFile.Read(character,1);
map[i][j] = -((int)character[0] - 48);
IndexFile.Read(character,1);
}
IndexFile.Read(character,1);
IndexFile.Read(character,1);
}
break;
}
}
}
m_SearchSort = 0;//which alg are you use.
m_ifOpen = 0;//等于一的時候就可以輸入起點和終點
m_ifDouble = 0;//表示沒有雙擊
m_ifMakemap = 0;//表示不能編輯地圖
m_showMode = 0;//不顯示搜索過的節點
IndexFile.Close();
Invalidate();
}
void CSearchPathView::OnSaveMap4()
{
CFile IndexFile;
if(IndexFile.Open("SaveMap.txt",CFile::modeRead))
{}
else
{
AfxMessageBox("cant open result.txt!");
return;
}
IndexFile.SeekToBegin();
char character[1];
character[1] = NULL;
IndexFile.SeekToBegin();
while (IndexFile.Read(character,1))
{
if(character[0] == '/')
{
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
if(character[0] == '4')
{
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
for(int i = 0;i < Height;i++)
{
for(int j = 0;j < Width;j++)
{
IndexFile.Read(character,1);
IndexFile.Read(character,1);
map[i][j] = -((int)character[0] - 48);
IndexFile.Read(character,1);
}
IndexFile.Read(character,1);
IndexFile.Read(character,1);
}
break;
}
}
}
m_SearchSort = 0;//which alg are you use.
m_ifOpen = 0;//等于一的時候就可以輸入起點和終點
m_ifDouble = 0;//表示沒有雙擊
m_ifMakemap = 0;//表示不能編輯地圖
m_showMode = 0;//不顯示搜索過的節點
IndexFile.Close();
Invalidate();
}
void CSearchPathView::OnSaveMap5()
{
CFile IndexFile;
if(IndexFile.Open("SaveMap.txt",CFile::modeRead))
{}
else
{
AfxMessageBox("cant open result.txt!");
return;
}
IndexFile.SeekToBegin();
char character[1];
character[1] = NULL;
IndexFile.SeekToBegin();
while (IndexFile.Read(character,1))
{
if(character[0] == '/')
{
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
if(character[0] == '5')
{
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
for(int i = 0;i < Height;i++)
{
for(int j = 0;j < Width;j++)
{
IndexFile.Read(character,1);
IndexFile.Read(character,1);
map[i][j] = -((int)character[0] - 48);
IndexFile.Read(character,1);
}
IndexFile.Read(character,1);
IndexFile.Read(character,1);
}
break;
}
}
}
m_SearchSort = 0;//which alg are you use.
m_ifOpen = 0;//等于一的時候就可以輸入起點和終點
m_ifDouble = 0;//表示沒有雙擊
m_ifMakemap = 0;//表示不能編輯地圖
m_showMode = 0;//不顯示搜索過的節點
IndexFile.Close();
Invalidate();
}
void CSearchPathView::OnShowShade()
{
// TODO: Add your command handler code here
m_showMode = 2;
Invalidate();//使窗口重繪
}
void CSearchPathView::OnShowNode()
{
// TODO: Add your command handler code here
m_showMode = 1;
Invalidate();//使窗口重繪
}
void CSearchPathView::OnShowPath()
{
// TODO: Add your command handler code here
m_showMode = 0;
Invalidate();//使窗口重繪
}
void CSearchPathView::OnReadMap()
{
// TODO: Add your command handler code here
CFile IndexFile;
/*
if(FoundData.Open("d:\\result.txt", CFile::modeCreate | CFile::modeWrite))
{}
else{
AfxMessageBox("cant open result.txt!");
return;
}
*/
if(IndexFile.Open("result.txt",CFile::modeRead))
{}
else
{
AfxMessageBox("cant open d:\\result.txt!");
return;
}
IndexFile.SeekToBegin();
char character[1];
character[1] = NULL;
IndexFile.SeekToBegin();
/*
while (IndexFile.Read(character,1))
{
character[0];
if(character[0] == '$')
{
AfxMessageBox(character);
}
}
*/
for(int i = 0;i < Height;i++)
{
for(int j = 0;j < Width;j++)
{
IndexFile.Read(character,1);
IndexFile.Read(character,1);
map[i][j] = -((int)character[0] - 48);
IndexFile.Read(character,1);
}
IndexFile.Read(character,1);
IndexFile.Read(character,1);
}
m_SearchSort = 0;//which alg are you use.
m_ifOpen = 0;//等于一的時候就可以輸入起點和終點
m_ifDouble = 0;//表示沒有雙擊
m_ifMakemap = 0;//表示不能編輯地圖
m_showMode = 0;//不顯示搜索過的節點
IndexFile.Close();
Invalidate();
}
void CSearchPathView::OnInitialUpdate()
{
CFile IndexFile;
if(IndexFile.Open("SaveMap.txt",CFile::modeRead))
{}
else
{
return;
}
IndexFile.SeekToBegin();
char character[1];
character[1] = NULL;
IndexFile.SeekToBegin();
while (IndexFile.Read(character,1))
{
if(character[0] == '/')
{
m_numSaveMap++;
CMenu *mainmenu;
mainmenu=AfxGetMainWnd()->GetMenu(); //得到主菜單
CString name;
CString temp(m_numSaveMap + 48);
name = " save_map" + temp;
(mainmenu->GetSubMenu (7))->AppendMenu(MF_STRING,IDM_SaveMap1 + m_numSaveMap - 1,_T(name)); //添加新的菜單項
DrawMenuBar(); //重畫菜單
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
IndexFile.Read(character,1);
}
}
IndexFile.Close();
}
void CSearchPathView::OnDemoWave()
{
// TODO: Add your command handler code here
m_ifOpen=0;
m_ifMakemap = 0;
m_SearchSort = 3;
m_showMode = 3;
Wave = new CWave;
Wave->prepareForStepByStep();
CDC *pDC = GetDC();
int temp;
while(1)
{
temp = Wave->searchThePathStepByStep();
OnDraw(pDC);
if(temp == 1)
{
MessageBox("路徑已經找到!");
break;
}
else if(temp == 0)
{
MessageBox("兩點之間沒有可行的路徑!");
break;
}
}
m_SearchSort = 0;
}
void CSearchPathView::OnDemoAStar()
{
// TODO: Add your command handler code here
m_ifOpen=0;
m_ifMakemap = 0;
m_SearchSort = 1;
m_showMode = 3;
AStar = new CAStar;
AStar->prepareForStepByStep();
CDC *pDC = GetDC();
int temp;
while(1)
{
temp = AStar->searchThePathStepByStep();
OnDraw(pDC);
if(temp == 1)
{
MessageBox("路徑已經找到!");
break;
}
else if(temp == 0)
{
MessageBox("兩點之間沒有可行的路徑!");
break;
}
}
m_SearchSort = 0;
}
void CSearchPathView::OnDemoBothWave()
{
// TODO: Add your command handler code here
m_ifOpen=0;
m_ifMakemap = 0;
m_SearchSort = 5;
m_showMode = 3;
BothWave = new CBothWave;
BothWave->prepareForStepByStep();
CDC *pDC = GetDC();
int temp;
while(1)
{
temp = BothWave->searchThePathStepByStep();
OnDraw(pDC);
if(temp == 1)
{
MessageBox("路徑已經找到!");
break;
}
else if(temp == 0)
{
MessageBox("兩點之間沒有可行的路徑!");
break;
}
}
m_SearchSort = 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -