c/c++vc++6.0 打砖块小游戏案例

本文介绍了如何使用C/C++及VC++6.0开发一款打砖块小游戏。通过多线程处理键盘事件,结合第三方库easyx进行图形显示,实现游戏的动态效果。
摘要由CSDN通过智能技术生成

在这里插入图片描述移动的同时 需要随时获取键盘事件 可以多线程
效果显示 如:正方形 使用了easyx第三方库 可直接百度 很好搭建
上代码

#include <graphics.h>
#include <iostream>
#include <conio.h>
#include <Windows.h>
#include <stdlib.h>

// #include <afx.h>
class Game
{
   
private:
	//初始化
	int screenWidth;   //屏幕宽
	int screenHeight;  //屏幕高
	int blockWidth;	   //砖块宽
	int blockHeight;   //砖块高
	int boardwidth;    //板子宽
	int boardHeight;   //板子高
	int radis;		   //球半径
	
public:
	//实际位置
	int ball_x;        //球圆心x
	int ball_y;        //球圆心y
	int board_x;       //板子横向位置

	bool flag;         //判断标志位
	int v_x;		   //x轴状态
	int v_y;           //y轴状态
	
	Game();
	void get(char ch);
	void ball_move();  //小球的动态移动
//	friend DWORD WINAPI Game_getch(); //按键获取
	bool judge();          //判断(砖块)
	bool judge_1();		   //判断 (墙壁)
	void Init()
	{
   
		initgraph(screenWidth,screenHeight); //640行480列页面
		for(int i=0;i<screenWidth;i+=blockWidth)
			rectangle(i,0,i+blockWidth,blockWidth);
	}
};
using namespace std;
DWORD WINAPI Game_getch(LPVOID lpParamter);
char CH;
int n = 0;
int main()
{
   	
//	cout << endl<<endl<<endl <<endl<<"                    -> 键向左移动" <<endl<<"                    -> 键向右移动" <<endl ;
//	cout <<"     任意键开始"<<endl<<endl<<endl;
//	getch();
	Game Gam;
	Sleep(1000*3);
	HANDLE hThread = CreateThread(NULL, 0, Game_getch, NULL, 0, NULL);
    CloseHandle(hThread);
	while(1)
	{
   	
		Gam.ball_move();
		Gam.get(CH);
		//CH=1;
	}
	getchar();
	closegraph();           //关闭页面
	return 0;
}
void Game::ball_move()
{
   
	static int IC=0;
	static int IB=0;
	IC++;
	if(IC==5)
	{
      //防止每次趋近板子都弹起 形成死循环(然而并无卵用)
		IB=0;
		IC=0;
	}
	rectangle(board_x,screenHeight-boardHeight\
				,board_x+boardwidth,screenHeight);
	clearcircle( ball_x,ball_y,radis+1); //清除
	/*
	if(v_x==-1)   //判断是上方
	{
		if(judge())     //判断是砖块
		{
  • 2
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值