当前位置:网站首页>C language push box
C language push box
2022-07-28 07:07:00 【c7473168】
tuixiangzi : Data analysis :
1. Determine the correspondence between numeric values and characters
0 ' '
1 '@'
2 '$'
3 '#'
4 'o'
5 '@'
7 '$'
2. Definition 8*8 Integer map and initialize
3. Define variables that record the position of the role x y
4. Variables that define the number of recording steps
logic analysis : Into the dead cycle
1. Clean the screen , Show map
if(0 == map[i][j]) printf(" ");
2. Get the direction key and process it
3. Determine whether the game wins
The road ahead , Refer to maze
In front of the +1
Original location -1
Update coordinates
2. In front is the box
In front of the box is the road \ The target point
In front of people +3
In front of people -3+1
Man's original position -1
' Update left
#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(" You won ! share %d Step \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;
}
边栏推荐
- Applet creation component
- Starting point Chinese website font anti crawling technology web page can display numbers and letters, and the web page code is garbled or blank
- RAID disk array
- The.Joernindex database has no content after Joern runs
- shell脚本——“三剑客”之awk命令
- 根据excel生成create建表SQL语句
- Es6--- > arrow function, class, modularization
- Applet custom components - data, methods, and properties
- JSON notes
- 关于正则的教程
猜你喜欢

VNC Timed out waiting for a response from the computer

组管理和权限管理

Servlet

MOOC翁恺C语言第七周:数组运算:1.数组运算2.搜索3.排序初步

freemarker合并单元格,if、else标签的使用,null、空字符串处理

Shell script - "three swordsmen" awk command

1、 PXE overview and installation
![[learning records of erudite Valley] Super summary, attentive sharing | collection](/img/a3/4183a074a7cdc41fe7624624492280.png)
[learning records of erudite Valley] Super summary, attentive sharing | collection

Applet creation component

Remotely access the local website of services such as neo4j on the ECS
随机推荐
bond模式配置
Esxi community network card driver updated again
Es6--- > arrow function, class, modularization
Applet custom components - data, methods, and properties
anaconda3无法打开navigator的解决办法
Neo4j运行报错Error occurred during initialization of VM Incompatible minimum and maximum heap sizes spec
Uniapp monitor whether the app has a network connection
MOOC Weng Kai C language week 3: judgment and cycle: 1. Judgment
DOM - Events
Applets: WSX scripts
easypoi一对多,合并单元格,并且根据内容自适应行高
Implementation method of Bert
Animation animation realizes the crossing (click) pause
Canvas drawing 1
Forward and backward slash notes
MOOC翁恺C语言 第四周:进一步的判断与循环:3.多路分支4.循环的例子5.判断和循环常见的错误
Operation document tree
Use powercli to create a custom esxi ISO image
Shell script -- program conditional statements (conditional tests, if statements, case branch statements, echo usage, for loops, while loops)
The.Joernindex database has no content after Joern runs