#include <iostream>
#include <conio.h>
using namespace std;
void SelectSort(int * iArray,int iSize);
//record the Position
typedef struct _tagPoint
{
int x;
int y;
}Point;
//reloaded the != operator
bool operator !=(const Point & pt0,const Point & pt1)
{
return !((pt0.x == pt1.x) && pt0.y == pt1.y);
}
//define the Direction
enum enumDirect{dirUp = 8,dirDown = 2,dirLeft = 4,dirRight = 6};
//Show your Position
void ShowPosition(const Point & ptPos)
{
cout << “your position is row:”
<< ptPos.x + 1
<< ” col:”
<< ptPos.y + 1
<< endl;
}
//check the Road can move
bool CanMove(Point ptTmp,char * cMap,int iRow,int iCol)
{
return *(cMap + ptTmp.x * iCol + ptTmp.y) == 0;
}
//display the Map
void ShowMap(Point ptTmp,char * cMap,int iRow,int iCol)
{
for(int i = 0;i < iRow;i++)
{
for(int j = 0;j < iCol;j++)
{
if((i == ptTmp.x) && (j == ptTmp.y))
cout << “^-^”;
else
cout << ” ” << *(cMap + i * iCol + j) << ” “;
}
cout << endl;
}
}
void main(void)
{
char cMap[9][10] = {{1,1,1,1,1,1,1,1,1,1},
{1,0,0,0,0,0,0,0,0,1},
{1,0,1,1,1,1,1,1,0,1},
{1,0,1,0,1,1,0,1,0,1},
{1,0,0,0,0,1,0,0,0,1},
{1,0,1,1,1,1,0,1,1,1},
{1,0,1,0,0,0,0,1,0,1},
{1,0,1,0,0,1,0,0,0,1},
{1,0,1,1,1,1,0,1,1,1}};
Point ptStart = {8,1};
Point ptEnd = {8,6};
Point ptPos = {-1,-1};
int iDirect = dirDown;
bool bStart = true;
while(ptPos != ptEnd && ptPos != ptStart)
{
//clear the screen
system(“cls”);
//show the map
ShowMap(ptPos,(char *)cMap,9,10);
//give the tip
cout << “Are you Move to?” << endl;
cout << “8– UP, 2– Down, 4– Left, 6– Right!” << endl;
//show the current position
ShowPosition(ptPos);
//get user input for direction
iDirect = getch() – ’0′;
if(bStart)
{//when start the motion set position in start
if(iDirect == dirDown)
{
cout << “\07″;
cout << “Can’t Move!” << endl;
continue;
}
//set position at entry
ptPos = ptStart;
bStart = false;
}
Point ptTmp = ptPos;
switch(iDirect)
{//process the direction
case dirUp:
ptTmp.x–;
break;
case dirDown:
ptTmp.x++;
break;
case dirLeft:
ptTmp.y–;
break;
case dirRight:
ptTmp.y++;
break;
}
if(CanMove(ptTmp,(char *)cMap,9,10))
{//the direction can move
ptPos = ptTmp;
ShowPosition(ptPos);
cout << “\07″;
}
else
{
cout << “\07\07\07\07\07″;
cout << “Can’t Move!” << endl;
}
}
cout << “Greeting! you out!” << endl;
}
-
近期文章
近期评论
- coolker 发表在《打造最快的Hash表》
- struggle 发表在《提供C语言教学课件(适用于初学者)》
- zhanghaibo 发表在《提供C语言教学课件(适用于初学者)》
- zhanghaibo 发表在《提供C语言教学课件(适用于初学者)》
- diys 发表在《C语言编程宝典(王大刚) 1.1 C 语言的产生与发展》
文章归档
- 2022 年十月
- 2014 年一月
- 2013 年十二月
- 2012 年十一月
- 2012 年七月
- 2012 年六月
- 2012 年五月
- 2012 年四月
- 2012 年三月
- 2012 年二月
- 2011 年十二月
- 2011 年十月
- 2011 年九月
- 2011 年八月
- 2011 年七月
- 2011 年六月
- 2011 年五月
- 2011 年四月
- 2011 年三月
- 2011 年二月
- 2011 年一月
- 2010 年十二月
- 2010 年十一月
- 2010 年十月
- 2010 年九月
- 2010 年八月
- 2010 年七月
- 2010 年六月
- 2010 年五月
- 2010 年四月
- 2010 年三月
- 2010 年二月
- 2010 年一月
- 2009 年十二月
- 2009 年十一月
- 2009 年十月
- 2009 年九月
- 2009 年八月
- 2009 年七月
- 2009 年六月
- 2009 年五月
- 2009 年四月
- 2009 年三月
- 2009 年二月
- 2009 年一月
- 2008 年十二月
- 2008 年十一月
- 2008 年十月
- 2008 年九月
- 2008 年八月
- 2008 年七月
- 2008 年六月
- 2008 年五月
- 2008 年四月
- 2008 年三月
- 2008 年二月
- 2008 年一月
- 2007 年十二月
- 2007 年十一月
- 2007 年十月
- 2007 年九月
- 2007 年八月
- 2007 年七月
- 2007 年六月
- 2007 年三月
- 2007 年二月
- 2007 年一月
- 2006 年十二月
- 2006 年十一月
- 2006 年十月
- 2006 年九月
- 2006 年八月
- 2006 年七月
- 2006 年六月
- 2006 年五月
- 2006 年四月
- 2006 年三月
- 2006 年二月
- 2006 年一月
- 2005 年十二月
- 2005 年十一月
分类目录
功能
一直都没有可以直接运行的程序
希望你的可以
哎!我去试试
要行 我好好顶!!!
怒 !!
怎么还是不能运行啊
我不过是想研究代码
学习一下 然后自己就多懂一些
为什么啊?!
楼主能告诉我一下你的邮箱吗?
我的 可以运行的 啊
都是高手啊!!!
高手,学习中“`挺长的啊.
可以运行的
写的太垃圾了
如果用回溯递归,比这个简单不知道多少倍了.
基本的算法。
是可以运行的
为毛没注释,看着好费劲!!!加注释啊,楼主。。。