⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 a.cpp

📁 此程序是一个按键打气球的小游戏
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include "windows.h"
#include "time.h"
#include "stdio.h"
#include "MyButton.h"
#include "TimeWindow.h"


#define ID_TIMER0		0
#define ID_TIMER1		1
#define ID_TIMER2		2 
#define ID_TIMER3		3
#define ID_TIMER4		4
#define ID_TIMER5		5
#define ID_TIMER6		6
#define ID_TIMER7		7
#define ID_TIMER8		8
#define ID_TIMER9		9
#define ID_TIMER10		10
#define ID_TIMER11		11
#define ID_TIMER12		12
#define ID_TIMER13		13

int							BigSmallWriteFlag;
void GetRandNumber(int Timer[10],int RandNum,int ArrayNo);
int GetIDTimer(int IDTimer);
void BalloonBurst(HWND hwnd,HDC hdc,HDC hMem,HBITMAP hBitmap[63],RECT ClientRect,RECT *rect,int ButtonHeight,HDC hMemory2,HDC hMemory4,HDC hMemory5,int cxSource,int cySource,HDC hMemBitmap[57],int IDTIMER,RECT *Furect,int Timer,int *rectflag);
int  GetRand(int Number,int Super);
void OnPaint(HDC hdc,int flag,RECT *Furect,RECT ClientRect,RECT rect,int rectnumber,int ButtonHeight,int cxSource,int cySource,HDC hMemBitmap,HBITMAP hBitmap[63],HDC hMemory1,HDC hMemory3,HDC hMem);
void InitBalloon(HDC hMemBitmap[57],HBITMAP hBitmap[63]);
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);

HINSTANCE		hInstance;
HWND     		FuTimeWindow;

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR
				   szCmdLine,int iCmdShow)
{
	static TCHAR szAppName[]=TEXT("BurstBalloon");
	HWND	hwnd;
	MSG		msg;
	WNDCLASS	wndclass;


	wndclass.style			=CS_HREDRAW|CS_VREDRAW;
	wndclass.lpfnWndProc	=WndProc;
	wndclass.cbClsExtra		=0;
	wndclass.cbWndExtra		=0;
	wndclass.hInstance		=hInstance;
	wndclass.hIcon			=LoadIcon(hInstance,MAKEINTRESOURCE(167)); 
	wndclass.hCursor		=LoadCursor(NULL,IDC_ARROW);
	wndclass.hbrBackground	=CreateSolidBrush(RGB(0xff,0xff,0xff));
	wndclass.lpszMenuName	=NULL;
	wndclass.lpszClassName	=szAppName;

	if(!RegisterClass(&wndclass))
	{
		MessageBox(NULL,TEXT("This program requires Windows NT!"),
			szAppName,MB_ICONERROR);
		return 0;
	}
	hwnd	= CreateWindow(szAppName,
							szAppName,
							WS_POPUPWINDOW,
							0,
							0,
							0,
							0,
							NULL,
							NULL,
							hInstance,
							NULL);

	ShowWindow(hwnd,iCmdShow);
	UpdateWindow(hwnd);


	while(GetMessage(&msg,NULL,0,0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return msg.wParam;
}




LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{

	static HWND					hwndDesk;
	static int					cxSource;
	static int					cySource;
	static int					cxBurst;
	static int					cyBurst;
	static int					cx;
	static int					cy;

    static HDC					hdc;
	static HDC					hMemory1;
	static HDC					hMemory2;
	static HDC					hMemory3;
	static HDC					hMemory4;
	static HDC					hMemory5;
	static HDC					hMem;
	static HDC					hMemBitmap[57];



	static PAINTSTRUCT			ps;
    static HBITMAP				hBitmap[63];
	static BITMAP				bitmap;
	static RECT					rect[10];
	static RECT					Furect[10];
	static RECT					recttemp;




	
 
	static int					rectflag[10];
	

	static int 					BitmapValue[10];


	static long					Paint[10];
	


	
	static int					time;
	static int					time1[10];
	static int					fast[10];	
	static int					Timer[10];

	int							key;
	int							i;
	int							temp;
	int							CapsLockState;
	int							ShiftState;
	int							TimeValue;
	
	TCHAR                       ButtonClassName[]=TEXT("MyButton");


	MyButton					EnterButton1;
	static HWND					Buttonhwnd1;
	static int					ButtonHeight;

	MyButton					EnterButton2;
	static HWND					Buttonhwnd2;
	static int					Timer13Flag;

	TimeWindow					Timewindow;
	static HWND					Timewindowhwnd;
	TCHAR						TimeWindowClassName[]=TEXT("TimeWindow");
	TimeWindow					BurstBalloon;
	static HWND					Burstballoonhwnd;
	static long					BurstBalloonNumber;


	switch(message)
	{
	case WM_CREATE:

        hInstance=((LPCREATESTRUCT)lParam)->hInstance;
		MoveWindow(hwnd,0,40,800,580,TRUE);
		for(i=0;i<63;i++)
			hBitmap[i]=LoadBitmap(hInstance,MAKEINTRESOURCE(100+i));

		InitBalloon(hMemBitmap,hBitmap);

		GetObject(hBitmap[61],sizeof(BITMAP),&bitmap);
		cxSource =bitmap.bmWidth;
		cySource =bitmap.bmHeight;

		GetObject(hBitmap[62],sizeof(BITMAP),&bitmap);
		cxBurst=bitmap.bmWidth;
		cyBurst=bitmap.bmHeight;

		hMem=CreateCompatibleDC(NULL);
		SelectObject(hMem,hBitmap[59]);
		GetObject(hBitmap[59],sizeof(BITMAP),&bitmap);
		cx=bitmap.bmWidth;
		cy=bitmap.bmHeight;

		for(i=0;i<10;i++)
		{
			if(i==0)
			{
				rect[i].left+=15;
				rect[i].top=recttemp.bottom;	
				rect[i].right=rect[i].left+cxSource;
				rect[i].bottom=rect[i].top+cySource;
			}
			else
			{	
				rect[i].left =rect[i-1].left+80;
				rect[i].top=recttemp.bottom;
				rect[i].right=rect[i].left+cxSource;
				rect[i].bottom=rect[i].top+cySource;
			}
		}
		

		

		
		GetRandNumber(Timer,35,11);

			
		for(i=0;i<10;i++)
			rectflag[i] =0;

		SetTimer(hwnd,ID_TIMER10,10,NULL);

		ButtonHeight=120;

		if(EnterButton1.RegisterMyButton(ButtonClassName,hInstance))
		{
			EnterButton1.CreateMyButton(hInstance,hwnd,&Buttonhwnd1,ButtonClassName,ButtonClassName,WS_CHILD|WS_VISIBLE,recttemp.right-ButtonHeight,recttemp.bottom-ButtonHeight,ButtonHeight-40,ButtonHeight-40);
			EnterButton2.CreateMyButton(hInstance,hwnd,&Buttonhwnd2,ButtonClassName,ButtonClassName,WS_CHILD|WS_VISIBLE,recttemp.right-2*ButtonHeight,recttemp.bottom-ButtonHeight,ButtonHeight-40,ButtonHeight-40);
		}
	
		if(Timewindow.RegisterTimeWindow(TimeWindowClassName,hInstance))
		{
			Timewindow.CreateTimeWindow(hInstance,hwnd,&Timewindowhwnd,TimeWindowClassName,TimeWindowClassName,WS_CHILD|WS_VISIBLE,recttemp.right-150,recttemp.top+10,140,30);
			BurstBalloon.CreateTimeWindow(hInstance,hwnd,&Burstballoonhwnd,TimeWindowClassName,TimeWindowClassName,WS_CHILD|WS_VISIBLE,recttemp.left+10,recttemp.top+10,200,30);
			FuTimeWindow=Timewindowhwnd;
		}
		
//		PlaySound(TEXT("F:\\Balloon\\rgqwl.wav"),NULL,SND_FILENAME|SND_ASYNC|SND_LOOP);

		return 0;

	case WM_SIZE:

		hwndDesk=GetDesktopWindow();
		GetClientRect(hwndDesk,&recttemp);
		MoveWindow(hwnd,0,0,recttemp.right,recttemp.bottom,TRUE);
		ShowWindow(Buttonhwnd1,TRUE);
		ShowWindow(Buttonhwnd2,TRUE);
		ShowWindow(Timewindowhwnd,TRUE);
		ShowWindow(Burstballoonhwnd,TRUE);
	
	
		return 0;

	case WM_TIMER:

		hdc=GetDC(hwnd);

		switch((int)wParam)
		{

		case 0:
		case 1:
		case 2:
		case 3:
		case 4:
		case 5:
		case 6:
		case 7:
		case 8:
		case 9:

	
			for(i=0;i<10;i++)
			{
				if(rectflag[i]!=0&&(int)wParam==i)
				{
					BalloonBurst(hwnd,hdc,hMem,hBitmap,recttemp,&rect[i],ButtonHeight,hMemory2,hMemory4,hMemory5,cxBurst,cyBurst,hMemBitmap,i,&Furect[i],Timer[i],&(rectflag[i]));		
					ReleaseDC(hwnd,hdc);
					return 0;
				}
			}
			TimeValue=(int)wParam;
			Paint[TimeValue]++;
		 	temp=fast[TimeValue]+time1[TimeValue];
			rect[TimeValue].top-=temp;
		

			if(rect[TimeValue].top<-cySource) 
			{			
				rect[TimeValue].top=recttemp.bottom;
				rectflag[TimeValue]=0;
				time1[TimeValue]=time;
				GetRandNumber(fast,3,TimeValue);
				BitmapValue[TimeValue]=GetRand(26,time);
				for(i=0;i<10;i++)
				{
					if(TimeValue==i) i++;
					if(BitmapValue[TimeValue]==BitmapValue[i])
					{
						BitmapValue[TimeValue]=GetRand(26,time);
						i=0;
					}
				}
			}
			else if(rect[TimeValue].top>=recttemp.bottom-temp)
			{
				BitmapValue[TimeValue]=GetRand(26,time);
				for(i=0;i<10;i++)
				{
					if(TimeValue==i) i++;
					if(BitmapValue[TimeValue]==BitmapValue[i])
					{
						BitmapValue[TimeValue]=GetRand(26,time);
						i=0;
					}
				}
			}
			
			OnPaint(hdc,Paint[TimeValue],&Furect[TimeValue],recttemp,rect[TimeValue],TimeValue,ButtonHeight,cxSource,cySource,hMemBitmap[BitmapValue[TimeValue]],hBitmap,hMemory1,hMemory3,hMem);
			
			ReleaseDC(hwnd,hdc);
			return 0;


		case 10:

	
		    GetClientRect(hwnd,&recttemp);
			

			hMemory1=CreateCompatibleDC(NULL);
			hMemory2=CreateCompatibleDC(NULL);
			hMemory3=CreateCompatibleDC(NULL);
			hMemory4=CreateCompatibleDC(NULL);
			hMemory5=CreateCompatibleDC(NULL);
			SelectObject(hMemory1,hBitmap[60]);
			SelectObject(hMemory2,hBitmap[53]);
			SelectObject(hMemory3,hBitmap[61]);
			SelectObject(hMemory4,hBitmap[62]);
			SelectObject(hMemory5,hBitmap[55]);

	
				
			GetRandNumber(fast,3,11);
			

			for(i=0;i<10;i++)
				time1[i]=0;

			KillTimer(hwnd,ID_TIMER10);

		
		

			return 0;


		case 11:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -