用C++实现打砖块游戏

本文介绍如何在课堂上利用C++语言开发一款简单的打砖块游戏,通过一节课的时间,实现了游戏的基本功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

上课摸鱼摸了一整节课的程序…
可以粗糙实现打砖块游戏

/*
Maker:XerDazzle
新版改良:
1,砖块不穿模
2,边界限制
3,五行砖块
4,生命限制
5,不报错
-----------
1,加入主界面
2,速度随砖块数变化
*/
#include <iostream>
#include <windows.h>
#include <conio.h>
#include <math.h>
#define Framelen 80
#define Framedep 25
#define Pi 3.14
double xx = 5,yy = 15;
int x,y,bx = 2,drct = 20,bnum = 40,hp = 8;
bool end = 0;
int brick[5][8] = {
  
  {1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1}};
void setpos(int x,int y){
    COORD pos = {x,y};
    HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleCursorPosition(hOut, pos);
}
void drctmove(int speed,int drct){
	//setpos(0,0);
	//printf("%d,%d",xx,yy);
	xx += (cos((Pi/180)*drct))*speed;
	yy -= (sin((Pi/180)*drct))*speed;
	x = int(xx);y = int(yy);
	
}
void drawsq(int x1,int y1,int x2,int y2,char f){
	for(int i = x1;i <= x2;i ++){
		setpos(i,y1);printf("%c",f);
	}
	for(int i = x1;i <= x2;i ++){
	
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值