#include<string>
#include<iostream>
using namespace std;
#include<windows.h>
#include<stdlib.h>
#define COUNT_1_LINE 31
#define COUNT_2_LINE 20
struct Station
{
int ID1;
int ID2;
string name;
COORD pt;
};
/*
ID1:从一号线的迈皋桥到奥体中心依次为1,。。。,16
从天隆寺到药科大学依次为17,。。。。,31
ID2:从二号线的油坊桥到马群站依次为1,。。。。,20.
*/
Station St1[COUNT_1_LINE],St2[COUNT_2_LINE];
string Names1[COUNT_1_LINE]= {"迈皋桥站","红山动物园","南京站站","新模范马路","玄武门站","鼓楼站","珠江路站","新街口站", /*换乘2号线*/
"张府园站","三山街站","中华门站","安德门站",/*由此去往南延线*/ /**/
"小行站","中胜路站","元通站",/*换乘2号线*/"奥体中心站",/*原来的底站*/
"天隆寺站","软件大道站","花神庙站","南京南站","双龙大道站","河定桥站","胜太路站","百家湖站","小龙湾站",
"竹山路站","天印大道站","龙眠大道站","江苏经贸学院","南京交院站","中国药科大学"/*1号线底站*/
};
string Names2[COUNT_2_LINE]= {"油坊桥站","雨润大街站","元通站", /*换乘1号线*/
"奥体东站","兴隆大街站","集庆门大街","云锦路站","莫愁湖站","汉中门站","上海路站","新街口站",/*换乘1号线*/
"大行宫站","西安门站","明故宫站","苜蓿园站","下马坊站","孝陵卫站","钟灵街站","五棵松站","马群站"/*2号线底站*/
};
int ptX1[COUNT_1_LINE]=
{
10,20,30,40,50,60,10,20,30,40,50,60,10,20,30,40,50,60,10,20,30,40,50,60,10,20,30,40,50,60,10
};
int ptY1[COUNT_1_LINE]=
{
3,3,3,3,3,3,4,4,4,4,4,4,5,5,5,5,5,5,6,6,6,6,6,6,7,7,7,7,7,7,8
};
int ptX2[COUNT_2_LINE]=
{
10,20,30,40,50,60,10,20,30,40,50,60,10,20,30,40,50,60,10,20
};
int ptY2[COUNT_2_LINE]=
{
10,10,10,10,10,10,11,11,11,11,11,11,12,12,12,12,12,12,13,13
};
COORD ptclick;
bool is_clicked=false;
int Count2Xinjiekou(Station *pSt);
int Count2Yuantong(Station *pSt);
int Count2Andemen(Station *pSt);
void ConsoleProc(HANDLE,INPUT_RECORD*);
void GetMousePosition();
void init()
{
int i=0;
for(i=0; i<COUNT_1_LINE; i++)
{
St1[i].ID1=i+1;
St1[i].ID2=0;
St1[i].name=Names1[i];
St1[i].pt.X=ptX1[i];
St1[i].pt.Y=ptY1[i];
}
for(i=0; i<COUNT_2_LINE; i++)
{
St2[i].ID1=0;
St2[i].ID2=i+1;
St2[i].name=Names2[i];
St2[i].pt.X=ptX2[i];
St2[i].pt.Y=ptY2[i];
}
St1[7].ID2=11;
St1[14].ID2=3;
St2[10].ID1=8;
St2[2].ID1=15;
}
int Count2Xinjiekou(Station *pSt)
{
int count=0;
if(pSt->ID1>=17)
{
count=Count2Andemen(pSt)+4;
return count;
}
else if(pSt->ID1<=16&&pSt->ID1>=1)
{
count=pSt->ID1-8;
if(count<0)count=-count;
return count;
}
else
{
count=pSt->ID2-11;
if(count<0)count=-count;
return count;
}
return count;
}
int Count2Yuantong(Station *pSt)
{
int count=0;
if(pSt->ID1>=17)
{
count=Count2Andemen(pSt)+3;
return count;
}
else if(pSt->ID1<=16&&pSt->ID1>=1)
{
count=pSt->ID1-15;
if(count<0)count=-count;
return count;
}
else
{
count=pSt->ID2-3;
if(count<0)count=-count;
return count;
}
return count;
}
int Count2Andemen(Station *pSt)
{
int count=0;
if(pSt->ID1>=17)
{
return pSt->ID1-16;
}
else if(pSt->ID1<=17&&pSt->ID1>=1)
{
count=pSt->ID1-12;
if(count<0)count=-count;
return count;
}
else
{
if(pSt->ID2<=7)
{
count=Count2Yuantong(pSt)+3;
return count;
}
else
{
count=Count2Xinjiekou(pSt)+4;
return count;
}
}
return count;
}
int CountStation(Station *pStart,Station *pEnd)
{
int count=0;
if(pStart->ID1>=17&&pEnd->ID1>=17)//起始站和终点站都在1号难延线
{
count=pStart->ID1-pEnd->ID1;
if(count<0)count=-count;
return count;
}
else if(pStart->ID1<=16&&pEnd->ID1<=16&&pStart->ID1>=1&&pEnd->ID1>=1)//起始站和终点站都在1号线
{
count=pStart->ID1-pEnd->ID1;
if(count<0)count=-count;
return count;
}
else if(pStart->ID2>=1&&pEnd->ID2>=1)//起始站和终点站都在2号线
{
count=pStart->ID2-pEnd->ID2;
if(count<0)count=-count;
return count;
}
else if(pStart->ID1>=17&&pEnd->ID1<=16)//起始站和终点站分别在1号线南延线和非南延线
{
count=Count2Andemen(pStart)+Count2Andemen(pEnd);
return count;
}
else if(pStart->ID1<=16&&pEnd->ID1>=17)//起始站和终点站分别在1号线南延线和非南延线
{
count=Count2Andemen(pStart)+Count2Andemen(pEnd);
return count;
}
else if(pStart->ID1<=16&&pStart->ID1>=1&&pEnd->ID1==0)//起始站和终点站分别在1号线和2号线
{
int count1=Count2Xinjiekou(pStart)+Count2Xinjiekou(pEnd);
int count2=Count2Yuantong(pStart)+Count2Yuantong(pEnd);
count=count1<count2?count1:count2;
return count;
}
else if(pStart->ID1==0&&pEnd->ID1<=16&&pEnd->ID1>=1)//起始站和终点站分别在1号线和2号线
{
int count1=Count2Xinjiekou(pStart)+Count2Xinjiekou(pEnd);
int count2=Count2Yuantong(pStart)+Count2Yuantong(pEnd);
count=count1<count2?count1:count2;
return count;
}
return count;
}
int main()
{
Station stStart,stEnd;
int nPrizeforOne=0;
int nMoneyNeed=0;
int nMoneyPaid=0;
int i=0,nInput=0;
SetConsoleTitle("南京地铁");
HANDLE hStdOut=GetStdHandle(STD_OUTPUT_HANDLE);
init();
string strInput;
cout<<" 您好!欢迎光临,南京地铁!\n";
cout<<"\n请您选择您的起始站点:\n";
while(true)
{
for(i=0; i<COUNT_1_LINE; i++)
{
SetConsoleTextAttribute(hStdOut,FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
SetConsoleCursorPosition(hStdOut,St1[i].pt);
cout<<St1[i].ID1<<":"<<St1[i].name<<" ";
}
for(i=0; i<COUNT_2_LINE; i++)
{
SetConsoleCursorPosition(hStdOut,St2[i].pt);
cout<<i+COUNT_1_LINE+1<<":"<<St2[i].name<<" ";
}
GetMousePosition();
for(i=0; i<COUNT_1_LINE; i++)
{
if(ptclick.X>=ptX1[i]&&ptclick.X<ptX1[i]+10&&ptclick.Y>=ptY1[i])
{
stStart=St1[1];
break;
}
}
for(i=0; i<COUNT_2_LINE; i++)
{
if(ptclick.X>=ptX2[i]&&ptclick.X<ptX2[i]+10&&ptclick.Y>=ptY2[i])
{
stStart=St2[1];
break;
}
}
cout<<"\n对不起,您的选择有误!\n";
}
cout<<"您的起始站是:"<<stStart.name<<"\n\n";
cout<<" 下面请选择您的目的站:\n";
while(true)
{
for(i=0; i<COUNT_1_LINE; i++)
{
SetConsoleTextAttribute(hStdOut,FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
SetConsoleCursorPosition(hStdOut,St1[i].pt);
cout<<St1[i].ID1<<":"<<St1[i].name<<" ";
}
for(i=0; i<COUNT_2_LINE; i++)
{
SetConsoleCursorPosition(hStdOut,St2[i].pt);
cout<<i+COUNT_1_LINE+1<<":"<<St2[i].name<<" ";
}
GetMousePosition();
for(i=0; i<COUNT_1_LINE; i++)
{
if(ptclick.X>=ptX1[i]&&ptclick.X<ptX1[i]+10&&ptclick.Y>=ptY1[i])
{
stEnd=St1[1];
break;
}
}
for(i=0; i<COUNT_2_LINE; i++)
{
if(ptclick.X>=ptX2[i]&&ptclick.X<ptX2[i]+10&&ptclick.Y>=ptY2[i])
{
stEnd=St2[1];
break;