c语言使用gotoxy函数清屏,system(“cls”)与gotoxy(0,0)清屏作用的问题
#include
#include
#include
#include
//全局变量
int add_x,add_y; //飞机位置
int high,width; //游戏画面尺寸
int bullet_x,bullet_y; //子弹位置
int enemy_x,enemy_y; //敌军位置
int score;
void gotoxy(int x,int y) //光标移动到(x,y)位置
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
COORD pos;
pos.X = x;
pos.Y = y;
SetConsoleCursorPosition(handle,pos);
}
void HideCursor() // 用于隐藏光标
{
CONSOLE_CURSOR_INFO cursor_info = {1, 0}; // 第二个值为0表示隐藏光标
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
void startup()
{
high = 20;
width = 30;
add_x = high/2;
add_y = width/2;
bullet_x = 0;
bullet_y = add_y+1;
enemy_x = 0;
enemy_y = add_y;
score = 0;
HideCursor() ;//隐藏光标
}
void show()
{
system("cls");//gotoxy(0,0); //清屏函数{:10_249:}
int i,j,k,l;
for( i = 0 ; i < high ; i ++ )
{
for( j = 0 ; j < width ; j ++ )
{
if((i==add_x)&&(j==add_y)) //输出飞机
{
printf("lYl");
printf("\n");
for( k = 0 ; k < j-1 ; k ++ )
printf(" ");
printf("/ l \");
printf("\n");
for( k = 0 ; k< j ; k ++ )
printf(" ");
printf("/ \");
printf("\n");
}
else if((i==bullet_x)&&(j==bullet_y))
printf("|"); //输出子弹
else if((i==enemy_x)&&(j==enemy_y))
printf("*");
else
printf(" "); //输出空格
}
printf("\n");
}
printf("得分: %d\n",score);
}
void updateWithoutInput()
{
if( add_x >= high )
add_x--;
if( add_y >= width )
add_y--;
if( add_x<1 )
add_x++;
if( add_y<1 )
add_y++;
if( bullet_x>-1 )
bullet_x -- ;
if( bullet_x == enemy_x&&bullet_y == enemy_y )
{
score ++; //得分+1
enemy_x = -1; //产生新的敌机
enemy_y = rand()%width;
bullet_x = -2; //子弹无效
}
if( enemy_x > high )
{
enemy_x = -1 ;
enemy_y = rand()%width ;
}
//敌机移动
static int speed=0;
if( speed < 20 )
speed++;
if( speed == 20 )
{
speed = 0;
enemy_x++;
}
}
void updateWithInput()
{
char input;
if( kbhit() ) //判断是否有输入
{
input = getch();
switch(input){
case 'w':add_x--;break;
case 'a':add_y--;break;
case 's':add_x++;break;
case 'd':add_y++;break;
case 'W':add_x--;break;
case 'A':add_y--;break;
case 'S':add_x++;break;
case 'D':add_y++;break;
case ' ':bullet_x = add_x-1,bullet_y = add_y+1;
}
}
}
int main()
{
startup(); //数据的初始化
while(1) //游戏循环执行
{
show(); //显示画面
updateWithoutInput(); //与输入无关的更新
updateWithInput(); //与输入有关的更新
}
return 0;
}
c语言使用gotoxy函数清屏,system(“cls”)与gotoxy(0,0)清屏作用的问题相关推荐
- c语言打印使用gotoxy函数,写了个小程序,一直会闪屏,用的gotoxy函数,求大神教...
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 #include #include #include #include // 全局变量 int position_x,position_y; // 飞机位 ...
- C语言中的函数返回值、return用法、return 0详解
1.函数返回值 定义:函数的返回值是指函数被调用之后,执行函数体中的代码所得到的结果,这个结果通过return语句返回. 没有返回值的函数为空类型,用void表示.一旦函数的返回值类型被定义为 voi ...
- c语言重画清屏函数,写了个小程序,一直会闪屏,用的gotoxy函数,求大神教
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 #include #include #include #include // 全局变量 int position_x,position_y; // 飞机位 ...
- c语言清屏小程序,写了个小程序,一直会闪屏,用的gotoxy函数,求大神教
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 #include #include #include #include // 全局变量 int position_x,position_y; // 飞机位 ...
- c语言gotoxy函数dev,写了个小程序,一直会闪屏,用的gotoxy函数,求大神教
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 #include #include #include #include // 全局变量 int position_x,position_y; // 飞机位 ...
- c语言gotoxy函数是什么意思,写了个小程序,一直会闪屏,用的gotoxy函数,求大神教...
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 #include #include #include #include // 全局变量 int position_x,position_y; // 飞机位 ...
- C语言 时钟模拟(gotoxy函数的运用)
时钟模拟,运用gotoxy()函数和Sleep()函数. 效果: #include <stdio.h> #include <windows.h> #include <ti ...
- 【C语言】打印出一箭穿心图案(简单版)----gotoxy函数
在C语言贴吧看到一个人要用dos打印一个爱心,我试了一下. 贴出样图: #define _CRT_SECURE_NO_WARNINGS 1 #include <stdio.h> #incl ...
- C语言程序设计(常用函数说明)
C语言程序设计(常用函数说明) C 语言是1972年由美国的Dennis Ritchie设计发明的,并首次在UNIX操作系统的 DEC PDP-11计算机上使用.它由早期的编程语言 BCPL(Basi ...
- c语言文件操作函数(未完待续)
while(!feof(fp1)),使用feof()的时候会比你期望的多执行一次.因为它检测到结尾的'\0',时仍然不是文件的结尾,所以会继续执行一次.为解决这个问题,可以先读,在判断,然后打印 fr ...
最新文章
- 一位老哥写文怒刚 Redis 作者
- C++中四种 cast 转换
- 计算机网络-基本概念(6)【网络层】-某PN和NAT
- Windows平台下 vscode清理Java工程项目的缓存、相关快捷键设置
- 数字图像处理--3.图像增强
- 三星电子总算找到“备胎”:从比利时采购半导体材料
- 【网络】几种常见的协议
- [k8s]debug模式启动集群k8s常见报错集合(on the fly)
- python 新建一列_python – 如何在迭代pandas数据框时创建新列并插入行值
- 纪念概率学界最后一位集大成者——钟开莱
- Python实现CRAPS赌博游戏
- meta的http-equiv属性
- termite:从零开始的go语言学习生活
- 大学生电子设计竞赛电源资料
- 洛谷P3237 [HNOI2014]米特运输
- 推荐10个关键时刻能派上大用场的神级软件,帮你解决80%的问题
- FFmpeg再学习 -- 将 jpeg 转成 mp4
- vnpy2.0与simnow搭建简单的量化策略开发环境
- tag untag pvid 理解
- Java 17 VS Java 8: 新旧对决,这些Java 17新特性你不容错过