当前位置:网站首页>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 fourth week: further judgment and circulation: 3. Multiple branches 4. Examples of circulation 5. Common errors in judgment and circulation
- 小甲鱼C(第六章数组1、2)
- JSON notes
- Event_ Loop event loop mechanism
- 一、PXE概述和安装
- Canvas drawing 1
- Blue Bridge Cup square filling number
- 360 compatibility issues
- DOM Foundation
- Archery database audit platform deployment
猜你喜欢

easypoi导出隔行样式设置

DOM -- event chain, event bubble and capture, event proxy

Esxi arm edition version 1.10 update

Shell script -- program conditional statements (conditional tests, if statements, case branch statements, echo usage, for loops, while loops)

爬虫学习总结

easypoi导出表格带echars图表

Shell--第一天作业

Applets: WSX scripts

主动扫描技术nmap详解

metasploit渗透ms7_010练习
随机推荐
Multiprocessing (multiprocessing)
[learning notes] process creation
起点中文网 字体反爬技术 网页可以显示数字字母 网页代码是乱码或空格
分解路径为目录名和文件名的方法
视频格式基础知识:让你了解MKV、MP4、H.265、码率、色深等等
[learning notes] tool
DOM Foundation
Results fill in the blank shopping list (teach you to solve it with Excel)
DNS domain name resolution
NAT-网络地址转换
Sysevr environment configuration: joern-0.3.1, neo4j-2.1.5, py2neo2.0
[learning records of erudite Valley] Super summary, attentive sharing | collection
Three cache technologies -- localstorage, sessionstorage, cookies
MOOC翁恺 C语言 第三周:判断与循环:2.循环
1、 PXE overview and installation
Erudite Valley Learning Records] Super summary, attentive sharing | common APIs
多进程(多核运算)Multiprocessing
DOM -- event chain, event bubble and capture, event proxy
Monotonic queue, Luogu p1886 sliding window
Upload and download files from Ubuntu server