当前位置:网站首页>C language maze
C language maze
2022-07-28 07:07:00 【c7473168】
Labyrinth :
Data analysis :
1. Define a two-dimensional character array as a maze map
2. Define the location of the variable record role x y
3. Time :time(NULL) obtain 1970-1-1 The total number of seconds passed by the runtime
logic analysis :
Into the dead cycle :
1. Show map
2. Get the direction key and process it
Judge whether the road ahead ' '
If it is :
1. Turn the old location into ' '
2. Turn the new location into '@'
3. Update character position coordinates x y
3. Determine whether to reach the exit
If it is : Program end
#include <stdio.h>
#include <getch.h>
#include <stdlib.h>
#include <time.h>
int main(int argc,const char* argv[])
{
char maze[10][10] = {
{'*','*','*','*','*','*','*','*','*','*'},
{'*','@','*',' ',' ',' ','*','*','*','*'},
{'*',' ','*',' ','*',' ','*',' ',' ','*'},
{'*',' ','*',' ','*',' ','*',' ','*','*'},
{'*',' ','*',' ','*',' ',' ',' ','*','*'},
{'*',' ','*',' ','*','*','*','*','*','*'},
{'*',' ',' ',' ','*',' ',' ',' ',' ','*'},
{'*','*',' ','*','*',' ','*','*',' ','*'},
{'*','*',' ',' ',' ',' ','*','*',' ','*'},
{'*','*','*','*','*','*','*','*',' ','*'},
};
char row = 1,col = 1; // Record role location
time_t start_time=time(NULL);
int i,j;
for(;;)
{
system("clear"); // Clean the screen
for(i=0;i<10;i++) // Show map
{
for(j=0;j<10;j++)
{
printf("%c ",maze[i][j]);
}
printf("\n");
}
// Determine whether to reach the exit
if(9 == row && 8 == col)
{
printf(" Game wins ! After that %lu second \n",time(NULL)-start_time);
break;
}
switch(getch()) // Get direction keys
{
case 183: // On
if(' ' == maze[row-1][col])
{
maze[row][col]=' ';
maze[--row][col]='@';
}
break;
case 184: // Next
if(' ' == maze[row+1][col])
{
maze[row][col]=' ';
maze[++row][col]='@';
}
break;
case 185: // Right
if(' ' == maze[row][col+1])
{
maze[row][col]=' ';
maze[row][++col]='@';
}
break;
case 186: // Left
if(' ' == maze[row][col-1])
{
maze[row][col]=' ';
maze[row][--col]='@';
}
break;
}
}
return 0;
}
边栏推荐
- shell---循环语句练习
- 防火墙——iptables防火墙(四表五链、防火墙配置方法、匹配规则详解)
- Forward and backward slash notes
- [learning records of erudite Valley] Super summary, attentive sharing | collection
- shell---sed语句练习
- Implementation method of converting ast into word vector before converting word vector
- Custom component -- data listener
- NAT network address translation
- Starting point Chinese website font anti crawling technology web page can display numbers and letters, and the web page code is garbled or blank
- Custom components -- slots
猜你喜欢

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

远程访问云服务器上Neo4j等服务的本地网址

MySQL查询父节点下面的所有子孙节点,查询用户列表时多级(公司)部门处理,根据反射,递归树形结构工具类

Starting point Chinese website font anti crawling technology web page can display numbers and letters, and the web page code is garbled or blank
![[learning records of erudite Valley] Super summary, attentive sharing | collection](/img/a3/4183a074a7cdc41fe7624624492280.png)
[learning records of erudite Valley] Super summary, attentive sharing | collection

freemarker导出word,带表格和多张图片,解决图片重复和变形

Use powercli to create a custom esxi ISO image

Custom component -- pure data field & component life cycle

PXE无人值守安装管理

DHCP principle and configuration
随机推荐
Asynchronous programming promise
Repair the faulty sector
Applet custom components - data, methods, and properties
MOOC翁恺 C语言 第三周:判断与循环:2.循环
[learning notes] coding ability
Blue Bridge Cup square filling number
Shell script - regular expression
360 compatibility issues
Applets: WSX scripts
远程访问云服务器上Neo4j等服务的本地网址
JS data type detection and modification detection
232(母)转422(公)
Esxi community network card driver updated again
Result fill in the blank (dfs*c language)
在转化词向量之前先转化为AST再转化为词向量的实现方法
shell脚本——sort、uniq、tr、数组排序、cut、eval命令配置
LNMP搭建过程详解
Es6--- > arrow function, class, modularization
PXE unattended installation management
Results fill in the blank. How many days of national day are Sundays (solved by pure Excel)