C语言学习笔记之实现小游戏——飞机大战1.0

这篇博客记录了使用C语言实现飞机大战小游戏的过程,包括游戏框架的简化、特殊函数如gotoxy()和HideCursor()的使用,以及随机数生成和键盘检测功能。博主通过实践体会到,看似复杂的问题可以通过分解为小模块来简化,虽然当前代码存在繁琐的问题,但这是学习过程中的宝贵经验。
摘要由CSDN通过智能技术生成

代码参考童晶老师
详见https://zhuanlan.zhihu.com/p/24697687

完整代码

#include <stdio.h>
#include <conio.h>
#include <windows.h>
//函数外全局变量定义
int high, width;   //画布尺寸
int plane_x, plane_y,plane_l,plane_r;  //飞机位置
int bullet_x, bullet_y; //子弹位置
int target_x, target_y; //目标位置
int score;


void HideCursor() // 用于隐藏光标
{
   
	CONSOLE_CURSOR_INFO cursor_info = {
    1, 0 };  // 第二个值为0表示隐藏光标
	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}

void startup()   //数据初始化
{
   
	high = 25;
	width = 50;
	plane_x = width / 2;
	plane_y = high / 2;
	plane_l = plane_x - 2;
	plane_r = plane_x + 2;
	bullet_x = -1;
	bullet_y = plane_y-1;
	score = 0;
	HideCursor();
}
void gotoxy(int x, int y)//类似于清屏函数,光标移动到原点位置进行重画
{
   
	HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
	COORD pos;
	pos.X = x;
	pos.Y = y;
	SetConsoleCursorPosition(handle, pos);
}

void show()     //显示画面
{
   
	int i, j;
	gotoxy(0, 0);
	f
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值