当前位置:网站首页>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;
}
边栏推荐
- ByteBuffer.position 抛出异常 IllegalArgumentException
- Database interview
- Thesis writing function words
- Idea uses dev tool to realize hot deployment
- Solve the problem that Oracle cannot use more than 1000 in statements
- 动态卷积的本质
- 顺序表的增删查改
- Openjudge: judge whether the string is palindrome
- 深度学习医学图像模型复现
- Mysql database index (InnoDB engine)
猜你喜欢

ByteBuffer. Position throws exception illegalargumentexception

Centos7 install MySQL 5.7

链表中关于快慢指针的oj题

Digital twin technology creates visual application of smart mine

Redis' bloom filter

Writing methods of scientific research papers: add analysis and discussion in the method part to explain their contributions and differences

Using Navicat or PLSQL to export CSV format, more than 15 digits will become 000 (e+19) later

Delete specific elements in order table OJ

Multi module packaging: package: XXX does not exist

ECCV22 最新54篇论文主图整理
随机推荐
Advanced multithreading: the role and implementation principle of volatile
How Visio accurately controls the size, position and angle of graphics
Openjudge: filter extra spaces
Response<T>类
openjudge:找第一个只出现一次的字符
(黑马)MYSQL初级-高级笔记(博主懒狗)
How to compare long and integer and why to report errors
Localdatetime removes T, and jsonfield is invalid
Response < t > class
24小时内的时间段无交叉
动态卷积的本质
排序之插入排序
Image enhancement - msrcr
蒸馏模型图
Mutual conversion between latex and word
Advanced multi threading: the underlying principle of synchronized, the process of lock optimization and lock upgrade
记录某某小卢的第一篇文章
Use of IO streams
When SQL queries the list, the data is inconsistent twice, and limit is automatically added
对极大似然估计、梯度下降、线性回归、逻辑回归的理解