当前位置:网站首页>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;
}
边栏推荐
- MOOC Weng Kai C language week 3: judgment and cycle: 1. Judgment
- Method of designing test cases
- Applets: WSX scripts
- DNS domain name resolution
- [learning notes] process creation
- MOOC Weng Kai C language fourth week: further judgment and circulation: 3. Multiple branches 4. Examples of circulation 5. Common errors in judgment and circulation
- [learning notes] tool
- Custom components -- styles
- Shell script - sort, uniq, TR, array sort, cut, Eval command configuration
- Event_ Loop event loop mechanism
猜你喜欢

LNMP搭建过程详解

Monotonic queue, Luogu p1886 sliding window

MySQL build database Series (I) -- download MySQL

Esxi community nvme driver update v1.1

Applets: lifecycle

easypoi导出表格带echars图表

Codesensor: convert the code into AST and then into text vector

Custom component -- pure data field & component life cycle

Reptile learning summary

三层交换和VRRP
随机推荐
Ubuntu MySQL setting remote access permissions
登录进oracle10g的oem,想管理监听程序却总是弹出帐号密码输入页面
DNS域名解析
codesensor:将代码转化为ast后再转化为文本向量
Esxi arm edition version 1.10 update
Esxi community network card driver updated in March 2022
Understanding of C language EOF
Remotely access the local website of services such as neo4j on the ECS
小甲鱼C(第六章数组1、2)
NAT network address translation
easypoi导出表格带echars图表
一个定时任务提醒工具
freemarker导出word,带表格和多张图片,解决图片重复和变形
Applet creation component
About gcc:multiple definition of
静态和浮动路由
metasploit渗透ms7_010练习
Operation document tree
Group management and permission management
Shell script - "three swordsmen" awk command