首页 > 移动平台 > 详细

控制台字符移动

时间:2016-03-07 10:19:01      阅读:159      评论:0      收藏:0      [点我收藏+]

刚才有网友问能否实现控制台内字符的移动,以前也未曾接触过,不过百度之后发现原理很简单,就是清空之后再重新绘制即可,简单记录之,方便以后使用。

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <conio.h>
 4 #include <time.h>
 5 #include <windows.h>
 6 
 7 void Move(int position)
 8 {
 9     int i = 0;
10     system( "cls" );//清空屏幕
11     while(i++<position)
12     {
13         putchar( );
14     }
15     putchar(A);
16 }
17 
18 void main()
19 {
20     int lastTime = GetTickCount();
21     int position = 0;
22     while(1)
23     {
24         while(GetTickCount() - lastTime < 500)
25         {
26             Sleep(1);
27         }
28         lastTime = GetTickCount();
29         Move(position++);
30     }
31 }

以上代码实现了A字符的从左向右移动,涉及到定时等操作,如果想整屏移动只需控制横竖的显示位置即可。

控制台字符移动

原文:http://www.cnblogs.com/shoufengwei/p/5249506.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!