⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 migong.cpp

📁 Turbo C++2.0下的迷宫程序,这是我的课程设计,里面有自己用乐谱演奏的音乐哦,音乐与游戏是并行的,可以一般听音乐
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	case 1:outtext(33+x,22+y,10+edge*128,5,"1.START NEW.");  break;
	case 2:outtext(33+x,24+y,10+edge*128,5,"2.CONTINUE. "); break;
	case 3:outtext(33+x,26+y,10+edge*128,5,"3.OPTION.   ");   break;
	case 4:outtext(33+x,28+y,10+edge*128,5,"4.EXIT GAME.");     break;
    }
}
void Cmigong::changewindow()
{
		if(selband==2||selband==1)
		{
		    bkground(1);
		    drawmap();
		    if(selband==2)
		    {
			if(firstplay==1)
			{
			    lastmani=manfirsti;
			    lastmanj=manfirstj;
			    firstplay=0;
			}
			moveto(lastmani,lastmanj);
		    }
		    else music.reward();
		    if(music.getstop()==1)music.change();
		    gameplay();
		    bkground(0);
		    firstplay=0;
		    showselboard(10,0,1,selband); //?
		    for(int n=10;n>=0;n--)                            //?
		    {
			showselboard(n,0,0,selband);clrselboard(n,0);
		    }

		    showselboard(0,0,1,selband);
		}

		if(selband==3)
		{
		    //bkground(0);
		    clrselboard(0,0);//?
		    showoption(0,band,!music.musicclose(),level);
		    /*outtext(30,20,4,0,"MUSIC OPTION.");        //?
		    outtext(32,21,4,0,"BackMusic.");
		    outtext(43,21,4,0,"ON");
		    outtext(47,21,4,0,"OFF");
		    outtext(32,22,4,0,"Loop.");
		    outtext(43,22,4,0,"ON");
		    outtext(47,22,4,0,"OFF");
		    outtext(30,23,4,0,"LEVEL.");
		    outtext(43,23,4,0,"1.");
		    outtext(47,23,4,0,"2.");*/
		    outtext(30,35,4,0,"Enter(Esc):Done");
		    while(1)
		    {
			if(kbhit())
			{
			    int ch1=getch();
			    if(ch1==13||ch1==27){break;}
			    if(ch1==0)
			    {
				int ch2=getch();
				if(ch2==80||ch2==72)
				{
				    if(band==1){band=0;}
				    else{band=1;}
				    showoption(0,band,!music.musicclose(),level);
				}
				if(ch2==75||ch2==77)
				{
				    if(band==1)
					if(music.musicclose()==0)
					 {music.closemusic();}
					 else{ music.openmusic();}
				    if(band==0){if(level==1){level=2;} else {level=1;}}
				    showoption(0,band,!music.musicclose(),level);
				}
			    }
			}
		    }
		    bkground(0);
		    showselboard(10,0,1,selband); //?
		    for(int n=10;n>=0;n--)                            //?
		    {
			showselboard(n,0,0,selband);clrselboard(n,0);
		    }
		    showselboard(0,0,1,selband);
		}
		if(selband==4){firstplay=1;abort();}
}
void Cmigong::showmainboard()
{
    nosound();
    _setcursortype(0);
    beginy=9;
    selband=1;
    delay(2000);
    int i,j;
    drawmap();
    beginy=5;
    for(i=1;i<=75;i++){cout<<" "<<endl;delay(1.0*(76-i)/6);}
    delay(200);
    bkground(0);
    for(j=1;j<=25;j++)
    {outtext(1,j-z,1,bkcolor,"*");delay(6*firstbegin);}     //?
    for(i=1 ;i<80;i++)
    {outtext(i,25-z,1,bkcolor,"*");delay(4*firstbegin);}
    for(j=25;j>0;j--)
    {outtext(79,j-z,1,bkcolor,"*");delay(6*firstbegin);}
    for(i=79 ;i>0;i--)
    {outtext(i,1-z,1,bkcolor,"*");delay(4*firstbegin);}
    firstbegin=0;
    for(int n=-20;n<=0;n++)
    {
	showselboard(n,0,0,selband);clrselboard(n,0);
    }
    showselboard(0,0,1,selband);
    union REGS inreg,outreg;
    int intnum=0x33;
    inreg.x.ax=8;
    inreg.x.cx=0;
    inreg.x.dx=400;
    int86(intnum,&inreg,&outreg);
    inreg.x.ax=1;
    int86(intnum,&inreg,&outreg);
//    Cmouse mou;
    while(1)
    {
	    inreg.x.ax=3;
	    int86(intnum,&inreg,&outreg);
	    int x=outreg.x.cx,y=outreg.x.dx;
	    if(outreg.x.bx==1)
	    {
		inreg.x.ax=2;
		int86(intnum,&inreg,&outreg);
		//cout<<"       "<<x<<" "<<y<<" ";

		if(x>255&&x<345&&y>=72&&y<80){selband=1; changewindow();}
		if(x>255&&x<345&&y>=88&&y<100){selband=2; changewindow();}
		if(x>255&&x<345&&y>=104&&y<110){selband=3; changewindow();}
		if(x>255&&x<345&&y>118&&y<130){selband=4; abort();changewindow();}

		inreg.x.ax=1;
		int86(intnum,&inreg,&outreg);

	    }
	if(kbhit())
	{
	    int ch1=getch();
	    if(ch1==27)break;
	    if(ch1==0)
	    {
		int ch2=getch();
		if(ch2==72)
		{
		    if(selband==1){selband=4;}
		    else{selband--;}
		    showselboard(0,0,1,selband);
		}
		if(ch2==80)
		{
		    if(selband==4){selband=1;}
		    else {selband++;}
		    showselboard(0,0,1,selband);
		}
	    }
	    if(ch1==13)
	    {
		changewindow();
	    }
	}
    }
}
void Cmigong::outputchar(int i,int j,int color,int ascii)  //draw the wall or the gold
{
    textcolor(color);
    gotoxy(beginx+j,beginy+i);
    putch(char(ascii));
}
    void Cmigong::drawgold()  {outputchar(goldi,goldj,14+128,15);}
    void Cmigong::drawman()  {outputchar(mani,manj,mancolor,manascii);}
    void Cmigong::clrman()   {outputchar(mani,manj,mancolor,32);}
    void Cmigong::moveleft() {clrman();manj--;drawman();}
    void Cmigong::moveright(){clrman();manj++;drawman();}
    void Cmigong::moveup()   {clrman();mani--;drawman();}
    void Cmigong::movedown() {clrman();mani++;drawman();}
    void Cmigong::moveto(int i,int j){clrman();mani=i;manj=j;drawman();}
void Cmigong::drawmap()
{
    _setcursortype(0);
    clrscr();
    if(selband!=0)
    {
	outtext(28,14,5,1,"WELCOME TO HERE!");
	outtext(30,35,5,1,"   F1 :HELP");          //?
	outtext(30,36,5,1,"SPACE:MUSIC ON ");
    }
    if(music.musicclose()==1){outtext(31,37,5,bkcolor,"Music Closed!");}
    for(int i=0;i<mapi;i++)
	for(int j=0;j<mapj;j++)
	{
	    switch(map[i][j])
	    {
		case 1:outputchar(i,j,(i+j)%5+3,3);break;   //wall
		case 5:outputchar(i,j,10,177);break;
		case 3:mani=manfirsti=i;manj=manfirstj=j;if(selband!=2)drawman();break; //man
		case 4:goldj=j;goldi=i;drawgold();break;//gold
	    }
	}
}
void Cmigong::automove()
{
    time_t lastt,nowt;
    lastt=nowt=clock();
    int status=0,arrived=0,delaytime=1;
    int i=manfirsti,j=manfirstj;
    mancolor=2;
    while(1)
    {
	if(music.musicclose()!=1)music.musicplay();
	if(win==1)music2.musicplay();
	if(kbhit())
	{
	    int ch1=getch();
	    if(ch1==27){mani=i;manj=j;clrman();moveto(lastmani,lastmanj);break;}
	    if(ch1==32){music.change();nosound();}
	}
	nowt=clock();
	if(nowt-lastt==delaytime)
	{
	    if(arrived==1){moveto(lastmani,lastmanj);drawgold();break;}
	    if(i-1>=0)if((map[i-1][j]==2||map[i-1][j]==4)&&status!=2){moveup();status=1;i--;}//if(map[mani][manj]==4)break;}
	    if(i+1<mapi)if((map[i+1][j]==2||map[i+1][j]==4)&&status!=1){movedown();status=2;i++;}//if(map[mani][manj]==4)break;}
	    if(j-1>=0)if((map[i][j-1]==2||map[i][j-1]==4)&&status!=4){moveleft();status=3;j--;}//if(map[mani][manj]==4)break;;}
	    if(j+1<mapj)if((map[i][j+1]==2||map[i][j+1]==4)&&status!=3){moveright();status=4;j++;}//if(map[mani][manj]==4)break;}
	    lastt=nowt;
	    //cout<<(map[mani][manj]);
	    if(map[mani][manj]==4){mancolor=2+128;drawman();arrived=1;delaytime=20;}
	}
    }
}
void Cmigong::gameplay()
{

    while(1)
    {
	if(music.musicclose()!=1)music.musicplay();
	if(kbhit())
	{ if(win!=1)
	  {  int ch1=getch();
	    if(ch1=='q'||ch1=='Q'||ch1==27)
	    {
		lastmani=mani,lastmanj=manj;
		music.change();nosound();selband=2;
		break;
	    }
	    if(ch1==32)
	    {                                      //?
		music.change();nosound();
		if(music.getstop()!=1){outtext(30,36,5,1,"SPACE:MUSIC ON ");}
		else {outtext(30,36,5,1,"SPACE:MUSIC OFF ");}
	    }
	    if(ch1==0)
	    {
		char ch2=getch();
		switch(ch2)
		{
		    case 75:if((map[mani][manj-1]!=1)&&(manj-1>0))  moveleft(); break;
		    case 77:if((map[mani][manj+1]!=1)&&(manj+1<mapj-1))moveright();break;
		    case 72:if((map[mani-1][manj]!=1)&&(mani-1>0))  moveup();   break;
		    case 80:if((map[mani+1][manj]!=1)&&(mani+1<mapi-1))movedown(); break;
		}
		if(map[mani][manj]==4){win=1;;music.reward();music.change();lastmani=manfirsti;lastmanj=manfirstj;nosound();selband=1;bkground(0);outtext(33,20,4,bkcolor,"Congratulations!");delay(2000);break;}
		if(ch2==59){lastmani=mani;lastmanj=manj;moveto(manfirsti,manfirstj);automove();}
	    }
	  }
	}
	//if(win==1)music2.musicplay();
	//if(music2.musicend()==1)break;
    }
}
void main()
{
//    music.addcode("hgo3a4.>c3<a4.>c2de4.a3g3e2de3.g2e5.p3");
 //   music.addcode("a4.a3g3e2ge3dc3.p2d3eg3e2gage3d3c2<a>c3dc<a4a3a5.p3");
  //  music.addcode(">c2ddc<a3>c<a4.p2>c2de4.a3g3e2de3.g2e5.");
   // music.addcode("a4.a3g3e2ge3dc3p3c2d3eg3e2gage3d3c2<a>c3dc<a4a3a5.");

    //music.addcode("o3hg
    //e4<ab>c3de4a3ge5e4<ab>c3dedc<ba5");
    //music.addcode(">e3d4.c3d4.c3dee5.e3d4.c3d4.g3a4.g3e5");
    //music.addcode("a3.a2a3.b2b>c5<a3.a2a3.b2>d4c<b3.b2b4a3g4.ga4g3e3e5");
    music.addcode("o2hga3aa>ed4c3<ba4a3ga5a3aa>e");
    music.addcode("d4g3de5e3a4b3ag4.e3a4b3ae5e3d4c3<b4a3ga5.");
    music.addcode(">a3b>c4.<b2>c<b4a3ga4a3ga5");
    music.addcode("a3b>c4.<b2>c<b4a3ge5.");
    music.addcode("e3d4.e3f4ac3c4.d3e4.a2b>c4.<b2>c<bab5.");
    music.addcode("o3a3b>c4.<b2>c<b4a3ga4a3ga5");
    music.addcode("a3b>c4.<b2>c<b4a3ge5.");
    music.addcode("e3d4.e3f4a>c<ba4a3g4.e3g3a2ge3ga5.");
//music.addcode("o4/c3de|fgab");
    int d=DETECT,m;
    initgraph(&d,&m,"");
    closegraph();
    Cmigong mg;
    mg.showmainboard();
    //mg.recordpath();
    //mg.drawmap();
    //mg.gameplay();
    union REGS inreg,outreg;
    int intnum=0x33;
    inreg.x.ax=2;
    int86(intnum,&inreg,&outreg);
    nosound();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -