輸入對應數字可以進入對應的模塊:
將各個模塊寫成分函數 進行調用
首界面代碼:
#include
#include
#include
#pragma comment(lib,"winmm.lib")
void ui()
{
char a[100][100]={" ? ? ? ? ? ? ? ? ##################################################################",
" ? ? ? ? ? ? ? ? # ? ? ? ? ? ? ? ? ? ? ? ?暢玩無限 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#",
" ? ? ? ? ? ? ? ? # ? ? ? ? ? ?0 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 0 ? ? ? ? ? ? ? ? ? #",
" ? ? ? ? ? ? ? ? # ? ? ? ? ? ?* ? ? ? ? ? ?1.走迷宮 ? ? ? ? ? * ? ? ? ? ? ? ? ? ? #",
" ? ? ? ? ? ? ? ? # ? ? ? ? ? ?* ? ? ? ? ? ?2.推箱子 ? ? ? ? ? * ? ? ? ? ? ? ? ? ? #",
" ? ? ? ? ? ? ? ? # ? ? ? ? ? ?* ? ? ? ? ? ?3.貪吃蛇 ? ? ? ? ? * ? ? ? ? ? ? ? ? ? #",
" ? ? ? ? ? ? ? ? # ? ? ? ? ? ?5.遠程控燈 ? 4.五子棋 ? ? ? ? ? 6.聯系我們 ? ? ? ? ?#",
" ? ? ? ? ? ? ? ? # ? ? ? ? ? ? ? ? ? ? ? ? 7.在線聊天 ? ? ? ? ? ? ? ? ? ? ? ? ? ? #",
" ? ? ? ? ? ? ? ? # ? ? ? ? ? ? ? ? ? ? ? ? 8.音樂盒子 ? ? ? ? ? ? ? ? ? ? ? ? ? ? #",
" ? ? ? ? ? ? ? ? # ? ? ? ? ? ? ? ? ? ? ? ? 9.美末原畫 ? ? ? ? ? ? ? ? ? ? ? ? ? ? #",
" ? ? ? ? ? ? ? ? ##################################################################"};
int i;
char ch;
printf(" ? ? ? ? ? ? ----------------------------------請輸入數字選擇------------------------------------------------");
printf("\n");
for(i=0;i<=12;i++)
puts(a[i]);//刷新層 不斷刷新
while(1)
{
ch=getch();
if(ch=='2')
{
tuixiangzi();
}
if(ch=='1')
{
zoumigong();//寫好在其他文件的分函數 對應數字
}
if(ch=='3')
{
tangchishe();
}
if(ch=='6')
{
wangye();
}
if(ch=='7')
{
zaixianliaotian();
}
if(ch=='4')
{
system("start file:///D:/QIN/c/changyouwuxian/五子棋.exe");//這是我借用別人的代碼的游戲 用這個方法可以打開文件
}
if(ch=='5')
{
yuanchengkongdeng();
}
if(ch=='8')
{
system("start file:///D:/QIN/c/changyouwuxian/Playsound/bin/Debug/Playsound.exe");
}
if (ch=='9')
{
PlaySound("D:\\QIN\\c\\changyouwuxian\\Linkin Park - Roads Untraveled.wav",NULL,SND_FILENAME|SND_ASYNC);
system("start file:///D:/QIN/c/changshi_sdl/bin/Debug/changshi_sdl.exe");
MessageBox(NULL,TEXT("Donghua "),TEXT("song"),MB_OK);
PlaySound(NULL,NULL,SND_FILENAME|SND_ASYNC|SND_LOOP);
}//一些音樂函數
}
return 0;
}
今天先完成走迷宮
貼出代碼
#include
#include
#include
void zoumigong()
{
//system("color 0a");
char a[50][50]={"###############################",
"#O ? ? ? # ? ? ? ? ? ? ? ?# ?##",
"# ## # ? # ?# ?######## ? # ?##",
"# ?# ### ? ? # ? ? ? ?# ? ? ?##",
"## ? # ? # ? ##### ?### ?## ?##",
"### ## ? # ? ? # ? ? ?# ? # ?##",
"# # ## ? # ? ?# ? ? ? # ?# # ##",
"# # # ? ? ?# ## ? ## ?# ?# ? ##",
"# # # ? ## # ? ? ? ? ?# ? ?# ##",
"# ? ? ?## ? ? ? ?# ? # ? ? # ?#",
"# ?# ? ? ? ? ?#### ? # ? # ? ##",
"# ?# ? # ?# ?# ? ? # # ? # # ? ",
"# ?# ? # ?# ?# ### ## ## ? ####",
"# ? ?# ? ?# ? ? ? ? ? ? ? ? ?##",
"###############################"};
int i,x,y,p,q;
char ch;
x=1;y=1;p=11;q=30;
for(i=0;i<=20;i++)
puts(a[i]);
while(x!=p || y!=q)
{ch=getch();
if(ch=='s')
{
if(a[x+1][y]!='#')
{
a[x][y]=' ';
x++;
a[x][y]='O';
}
}
if(ch=='w')
{
if(a[x-1][y]!='#')
{
a[x][y]=' ';
x--;
a[x][y]='O';
}
}
if(ch=='d')
{
if(a[x][y+1]!='#')
{
a[x][y]=' ';
y++;
a[x][y]='O';
}
}
if(ch=='a')
{
if(a[x][y-1]!='#')
{
a[x][y]=' ';
y--;
a[x][y]='O';
}
}
if(ch=='o')
{
system("cls");
printf("BYE!\n");
Sleep(3000);
system("cls");
ui();
}
system("cls");
printf("----------------------------w s a d 上下左右 ?o離開--------------------------------------\n");
for(i=0;i<=20;i++)
puts(a[i]);
}
system("cls");
printf("YOU WIN!!\n");
printf("輸入o離開\n");
ch=getch();
if(ch=='o')
{
system("cls");
printf("BYE!\n");
system("cls");
ui();
}
return 0;
}
//二維數組記錄地圖位置 x殖属,y記錄點的位置
??c?
明天更新推箱子。
轉載注明出處