1 #include "stdio.h"
 2 #include "time.h"
 3 #include <windows.h>
 4 
 5 //===================================================
 6 //
 7 //  Title:  C语言实现小人移动 V1.0 
 8 //  Author: 邹阳
 9 //  Date : 2020/05/28
10 // 
11 //=================================================== 
12 
13 
14 
15 void main(){
16     int i,j;
17     
18     int P_X = 2; //身体位置X坐标 
19     int P_Y = 7; //身体位置Y坐标,以脚为准 
20     int HEIGHT = 12; //高度 
21     int WEIGHT = 12; //宽度 
22     int P_SPEED = 1; //移动速度
23     char WARNING[10] = " "; //警告内容 
24 
25     char people_head = '0'; //胳臂 
26     char people_arm = 'L'; //胳臂 
27     char people_leg = 'X'; //
28     
29     char graph[HEIGHT][WEIGHT]; //地图数组 
30     
31     while(1){
32     for(i=0;i<HEIGHT;i++){ //生成地图 
33         for(j=0;j<WEIGHT;j++){
34             if(i==8){
35                 graph[i][j] = '='; //陆地 
36             }
37             else{
38                 graph[i][j] = ' '; //空气    
39             }    
40         }
41     }
42         
43     if(GetAsyncKeyState(VK_SPACE)){ //跳跃 
44         
45     }
46     else if(GetAsyncKeyState(VK_LEFT)){ //向左
47         if(P_X>0 && P_X<=11){
48             P_X-=P_SPEED;
49             strcpy(WARNING," ");
50         }
51         else{
52             strcpy(WARNING,"不能移动!");
53             P_X+=1;
54         }
55     }
56     else if(GetAsyncKeyState(VK_RIGHT)){ //向右 
57         if(P_X>0 && P_X<=11){
58             P_X+=P_SPEED;
59             strcpy(WARNING," ");
60         }
61         else{
62             strcpy(WARNING,"不能移动!");
63             P_X-=1;
64         }
65     }
66 
67     graph[P_Y-2][P_X] = people_head; //放置人 
68     graph[P_Y-1][P_X] = people_arm;
69     graph[P_Y][P_X] = people_leg;
70     
71     for(i=0;i<HEIGHT;i++){ //显示图像 
72         for(j=0;j<WEIGHT;j++){
73             printf("%c ",graph[i][j]);
74         }
75         printf("n");
76     }
77     printf("n人的 X 坐标:%d",P_X);
78     printf("n人的 Y 坐标:%d",P_Y);
79     printf("n信息:%s",WARNING);
80     sleep(1); //刷屏延时 
81     system("cls"); //刷新屏幕 
82     }
83 
84 }

 

展示效果:

内容来源于网络如有侵权请私信删除

文章来源: 博客园

原文链接: https://www.cnblogs.com/moegarn/p/12982187.html

你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!