当前位置:网站首页>C语言推箱子
C语言推箱子
2022-07-28 05:18:00 【c7473168】
推箱子:数据分析:
1.确定数值与字符的对应关系
0 ' '
1 '@'
2 '$'
3 '#'
4 'o'
5 '@'
7 '$'
2.定义8*8整数地图并初始化
3.定义记录角色位置的变量x y
4.定义记录步数的变量
逻辑分析:进入死循环
1.清理屏幕,显示地图
if(0 == map[i][j]) printf(" ");
2.获取方向键并处理
3.判断是否游戏胜利
前方是路,参考走迷宫
前方+1
原位置-1
更新坐标
2.前方是箱子
箱子的前方是路\目标点
人前方的前方 +3
人前方 -3+1
人原位置 -1
'更新左边
#include <stdio.h>
#include <stdlib.h>
#include <getch.h>
int main(int argc,const char* argv[])
{
char map[8][8] = {
{' ',' ','*','*','*','*',' ',' '},
{' ',' ','*','x','x','*',' ',' '},
{' ','*','*',' ','x','*','*',' '},
{' ','*',' ',' ','o','x','*',' '},
{'*','*',' ','o',' ',' ','*','*'},
{'*',' ',' ','*','o','o',' ','*'},
{'*',' ',' ','w',' ',' ',' ','*'},
{'*','*','*','*','*','*','*','*'},
};
int i,j,cnt=0;
char x=6,y=3;
for(;;)
{
if(' '==map[1][3])
map[1][3]='x';
if(' '==map[1][4])
map[1][4]='x';
if(' '==map[2][4])
map[2][4]='x';
if(' '==map[3][5])
map[3][5]='x';
system("clear");
for(i=0;i<8;i++)
{
for(j=0;j<8;j++)
{
printf("%c ",map[i][j]);
}
printf("\n");
}
if('o'==map[1][3]&&'o'==map[1][4]&&'o'==map[2][4]&&'o'==map[3][5])
{
printf("你赢啦!共用%d步\n",cnt);
break;
}
int key = getch();
if(183 == key && '*'!=map[x-1][y] && 'o'!=map[x-1][y])
{
map[x][y]=' ';
map[x-1][y]='w';
x-=1;cnt++;
}
else if(183==key&&'*'!=map[x-2][y]&&'o'==map[x-1][y]&&'o'!=map[x-2][y])
{
map[x][y]=' ';
map[x-2][y]='o';
map[x-1][y]='w';
x-=1;cnt++;
}
if(184 == key && '*'!=map[x+1][y] && 'o'!=map[x+1][y])
{
map[x][y]=' ';
map[x+1][y]='w';
x+=1;cnt++;
}
else if(184==key&&'*'!=map[x+2][y]&&'o'==map[x+1][y]&&'o'!=map[x+2][y])
{
map[x][y]=' ';
map[x+2][y]='o';
map[x+1][y]='w';
x+=1;cnt++;
}
if(185 == key && '*'!=map[x][y+1] && 'o'!=map[x][y+1])
{
map[x][y]=' ';
map[x][y+1]='w';
y+=1;cnt++;
}
else if(185==key&&'*'!=map[x][y+2]&&'o'==map[x][y+1]&&'o'!=map[x][y+2])
{
map[x][y]=' ';
map[x][y+2]='o';
map[x][y+1]='w';
y+=1;cnt++;
}
if(186 == key && '*'!=map[x][y-1] && 'o'!=map[x][y-1])
{
map[x][y]=' ';
map[x][y-1]='w';
y-=1;cnt++;
}
else if(186==key&&'*'!=map[x][y-2]&&'o'==map[x][y-1]&&'o'!=map[x][y-2])
{
map[x][y]=' ';
map[x][y-2]='o';
map[x][y-1]='w';
y-=1;cnt++;
}
}
return 0;
}
边栏推荐
- pytorch使用hook获得特征图
- repackag failed: Unable to find main class
- Learning of image enhancement evaluation index -- structural similarity SSIM
- openjudge:大小写字母互换
- C语言回顾(字节对齐篇)
- Image enhancement - msrcr
- 日期类及其基本功能的实现
- 顺序表oj之删除特定的元素
- Thesis writing function words
- Video twins: the starting point of informatization upgrading of smart Parks
猜你喜欢
随机推荐
latex使用\hl进行高亮时遇到引用总是报错,显示少了括号或者多了括号
Mabtis(一)框架的基本使用
openjudge:病人排队
Using Navicat or PLSQL to export CSV format, more than 15 digits will become 000 (e+19) later
MySQL adds sequence number to query results
Openjudge: matrix multiplication
Docker deploy mysql5.7.35
Deep learning medical image model reproduction
(dark horse) MySQL beginner advanced notes (blogger lazy dog)
openjudge:矩阵乘法
框架一步一步方便使用的流程
c语言:通过一个例子来认识函数栈帧的创建和销毁讲解
There is no crossover in the time period within 24 hours
IO流的使用
Simpledateformat thread unsafe and datetimeformatter thread safe
When using deep learning training image, the image is too large for segmentation training prediction
蒸馏模型图
visio如何精确控制图形的大小和位置及角度
Delete specific elements in order table OJ
Image enhancement - msrcr









