1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 自学三个月编写简单走迷宫游戏

自学三个月编写简单走迷宫游戏

时间:2020-01-25 16:40:08

相关推荐

自学三个月编写简单走迷宫游戏

代码如下:

#include<stdio.h>#include<conio.h>#include<stdlib.h>#include<Windows.h>int main(){int i = 0;char a[50][50] = {"######","#o # ","# ## #","# # #", "## #", "######", };printf("w:上\n");printf("s:下\n");printf("a:左\n");printf("d:右\n");printf("点击空格开启游戏\n");int x=1, y=1, l=1, p=5;//x,y记录小球初始的行列数;l,p记录出口位置char ch;ch = _getche();printf("\n");while (ch == ' '){for (i = 0; i <= 5; i++){system("color 1b");puts(a[i]);}break;//防止无限打印}char m;while (x!=l||y!=p){m = _getch();if (m == 's')//读入操作{if (a[x + 1][y] != '#'){a[x][y] = ' ';//将原来的点初始化为空格x++;a[x][y] = 'o';//将移动后的点转换为物体,注意要用‘’system("cls");//清屏for (i = 0; i <= 5; i++){puts(a[i]);system("color 1b");}//清屏之后再次打印}}if (m == 'w')//读入操作{if (a[x-1][y] != '#'){a[x][y] = ' ';//将原来的点初始化为空格x--;a[x][y] = 'o';//将移动后的点转换为物体,注意要用‘’system("cls");//清屏for (i = 0; i <= 5; i++){puts(a[i]);system("color 1b");}//清屏之后再次打印}}if (m == 'a')//读入操作{if (a[x][y-1] != '#'){a[x][y] = ' ';//将原来的点初始化为空格y--;a[x][y] = 'o';//将移动后的点转换为物体,注意要用‘’system("cls");//清屏for (i = 0; i <= 5; i++){puts(a[i]);system("color 1b");}//清屏之后再次打印}}if (m == 'd')//读入操作{if (a[x ][y+1] != '#'){a[x][y] = ' ';//将原来的点初始化为空格y++;a[x][y] = 'o';//将移动后的点转换为物体,注意要用‘’system("cls");//清屏for (i = 0; i <= 5; i++){puts(a[i]);system("color 1b");}//清屏之后再次打印}}}system("color 2f");printf("游戏成功\n");Sleep(5000);return 0;}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。