游戏与编程结合的C语言网站,我用C编了个小游戏,欢迎喜欢C语言和编程的一起讨论,交流。...

这个博客介绍了一个名为'MAGIC BOX'的游戏,玩家可以通过键盘输入改变方块的转动方向。游戏界面由不同线条和填充色块构成,包括四个旋转区域。`drawmain()`函数用于绘制游戏界面,`turnbox()`函数处理根据用户输入的转向操作,`swapbox()`系列函数实现方块的交换。游戏提供四种转向选项,并支持整理方块的整洁排列。
摘要由CSDN通过智能技术生成

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

void drawdirect(int direct)

{setfillstyle(1,8);

floodfill(304,275,14);floodfill(364,275,14);

floodfill(344,265,14);floodfill(344,235,14);

setfillstyle(1,1);

switch (direct)

{case 1:

floodfill(364,275,14);break;

case 2:

floodfill(304,275,14);break;

case 3:

floodfill(344,265,14);break;

case 4:

floodfill(344,235,14);break;}

}

void breakbox(int a[6][9]) /*此函数会调用上面2,3级子函数*/

{int i;

time_t t;

srand((unsigned) time(&t)); /*把系统时间写入随机种子*/

for(i=0;i<=0;i++) /*注意!此处i<=0,只随机旋转一下,是为了方便测试*/

{switch(rand()%5)

{case 0:swapbox1(a);break;

case 1:swapbox2(a);break;

case 2:swapbox3(a);break;

case 3:swapbox4(a);break;

case 4:swapbox5(a);break;

case 5:swapbox6(a);break;}

}}

void tidybox(int a[6][9])

{int i,j;

for(i=0;i<=5;i++)

for(j=0;j<=8;j++)

a[i][j]=i+1;

}

int judgebox(int a[6][9])

{int i,j;

for(i=0;i<=5;i++)

for(j=0;j<=7;j++)

{if (a[i][j]!=a[i][j+1]) return 1;

}

return 0;

}

void drawmain(void)

{setbkcolor(8);

setcolor(14);

{rectangle(50,200,194,344);

line(50,200,98,152);

line(98,152,242,152);

line(242,152,242,296);

line(242,296,194,344);

line(242,152,194,200);}

{line(50,248,194,248);

line(50,296,194,296);

line(98,200,98,344);

line(146,200,146,344);}

{line(66,184,210,184);

line(82,168,226,168);

line(98,200,146,152);

line(146,200,194,152);}

{line(194,248,242,200);

line(194,296,242,248);

line(210,184,210,328);

line(226,168,226,312);}

settextstyle(0,0,4);

outtextxy(180,50,"MAGIC BOX");

settextstyle(0,0,1);

rectangle(300,260,390,290);

rectangle(330,290,360,230);

line(305,275,325,275);line(305,275,310,272);line(305,275,310,278);

line(365,275,385,275);line(385,275,380,272);line(385,275,380,278);

line(345,265,345,285);line(345,285,342,280);line(345,285,348,280);

line(345,235,345,255);line(345,235,342,240);line(345,235,348,240);

rectangle(410,200,500,290);

line(410,230,500,230);

line(410,260,500,260);

line(440,200,440,290);

line(470,200,470,290);

outtextxy(422,212,"7");outtextxy(452,212,"8");outtextxy(482,212,"9");

outtextxy(422,242,"4");outtextxy(452,242,"5");outtextxy(482,242,"6");

outtextxy(422,272,"1");outtextxy(452,272,"2");outtextxy(482,272,"3");

rectangle(520,240,550,290);

outtextxy(520,260,"E");outtextxy(526,260,"n");

outtextxy(532,260,"t");outtextxy(538,260,"e");

outtextxy(544,260,"r");

outtextxy(300,310,"with these keys ablove you can:");

outtextxy(300,330,"change turning direction;");

outtextxy(299,350,"turn one line of the box;");

outtextxy(299,370,"turn the whole box.");

outtextxy(20,440,"F1-new game F2-tidy box Esc-exit");

}

void turnbox(int direct,int ch,int a[6][9]) /*压轴函数,此函数调用2,3级子函数*/

{switch(direct)

{case 1:switch(ch)

{case NUM7:

case NUM8:

case NUM9:swapbox1(a);break;

case NUM4:

case NUM5:

case NUM6:swapbox2(a);break;

case NUM1:

case NUM2:

case NUM3:swapbox3(a);break;

case ENTER:swapbox1(a);swapbox2(a);swapbox3(a);break;}break;

case 2:switch(ch)

{case NUM7:

case NUM8:

case NUM9:swapbox1(a);swapbox1(a);swapbox1(a);break; /*向右转3下等于向左转一下*/

case NUM4:

case NUM5:

case NUM6:swapbox2(a);swapbox2(a);swapbox2(a);break;

case NUM1:

case NUM2:

case NUM3:swapbox3(a);swapbox3(a);swapbox3(a);break;

case ENTER:swapbox1(a);swapbox1(a);swapbox1(a);

swapbox2(a);swapbox2(a);swapbox2(a);

swapbox3(a);swapbox3(a);swapbox3(a);break;}break;

case 3:switch(ch)

{case NUM7:

case NUM4:

case NUM1:swapbox4(a);break;

case NUM8:

case NUM5:

case NUM2:swapbox5(a);break;

case NUM9:

case NUM6:

case NUM3:swapbox6(a);break;

case ENTER:swapbox4(a);swapbox5(a);swapbox6(a);break;}break;

case 4:switch(ch)

{case NUM7:

case NUM4:

case NUM1:swapbox4(a);swapbox4(a);swapbox4(a);break;

case NUM8:

case NUM5:

case NUM2:swapbox5(a);swapbox5(a);swapbox5(a);break;

case NUM9:

case NUM6:

case NUM3:swapbox6(a);swapbox6(a);swapbox6(a);break;

case ENTER:swapbox4(a);swapbox4(a);swapbox4(a);

swapbox5(a);swapbox5(a);swapbox5(a);

swapbox6(a);swapbox6(a);swapbox6(a);break;}break;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值