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

📄 mainfrm.cpp

📁 小蜜蜂射击游戏,画面精彩,声音也不错
💻 CPP
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "bee.h"
#include <mmsystem.h>
#include <vfw.h>
#include "MainFrm.h"
#include "beeDoc.h"
#include "beeView.h"
#include "InputPlayerName.h"
#include "LookStore.h"
#include <stdlib.h>


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

extern CBeeApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CMainFrame

IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
	//{{AFX_MSG_MAP(CMainFrame)
	ON_WM_CREATE()
	ON_COMMAND(ID_FILE_NEW, OnFileNew)
	ON_WM_TIMER()
	ON_COMMAND(ID_FILE_RESTART, OnFileRestart)
	ON_COMMAND(ID_FILE_SCORE, OnFileScore)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

static UINT indicators[] =
{
	ID_SEPARATOR,           // status line indicator
	//ID_INDICATOR_CAPS,
	//ID_INDICATOR_NUM,
	//ID_INDICATOR_SCRL,
};

/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction

CMainFrame::CMainFrame()
{
	// TODO: add member initialization code here
    queuemap=0;
	start=0;
}

CMainFrame::~CMainFrame()
{
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
//	if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
//		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
//		!m_wndToolBar.LoadToolBar(IDR_TOOLBAR1))
//	{
//		TRACE0("Failed to create toolbar\n");
//		return -1;      // fail to create
//	}
	if (!m_wndStatusBar.Create(this) ||
		!m_wndStatusBar.SetIndicators(indicators,
		  sizeof(indicators)/sizeof(UINT)))
	{
		TRACE0("Failed to create status bar\n");
		return -1;      // fail to create
	}

	return 0;
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	if( !CFrameWnd::PreCreateWindow(cs) )
		return FALSE;
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs
    cs.cx=315;
	cs.cy=400;
	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics

#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
	CFrameWnd::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
	CFrameWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers


void CMainFrame::OnFileNew() 
{
	// TODO: Add your command handler code here
	start=1;
    SetTimer(2004,100,NULL);
    AfxBeginThread(PlayBgSound,this);
	m_dropthread=AfxBeginThread(DoDropbowb,this);
}



void CMainFrame::OnTimer(UINT nIDEvent) 
{
    POSITION  i;
	// TODO: Add your message handler code here and/or call default
    CBeeDoc* pDoc=(CBeeDoc*)GetActiveDocument();
	CBeeView *pview=(CBeeView*)GetActiveView();
	pDoc->m_beequeue.move(&(pview->m_screen));


	i=pDoc->m_bomblist.GetHeadPosition();
	while(i!=NULL){
		   pDoc->m_bomblist.GetNext(i).move(&(pview->m_screen));
		     
	}
	i=pDoc->m_dropbomblist.GetHeadPosition();
	while(i!=NULL){
		   pDoc->m_dropbomblist.GetNext(i).move(&(pview->m_screen));
	     
	}


    pDoc->UpdateAllViews(NULL);
	ruleImple(this);
	CFrameWnd::OnTimer(nIDEvent);

}

UINT CMainFrame::ruleImple(LPVOID pParam)
{        
	    POSITION  i;
        CMainFrame * pMainFrm = (CMainFrame *) pParam;
        CBeeDoc* pDoc=(CBeeDoc*)pMainFrm->GetActiveDocument();
	    CBeeView *pview=(CBeeView*)pMainFrm->GetActiveView();
		//while(1){
		i=pDoc->m_bomblist.GetHeadPosition();
    	while(i!=NULL){
			int j,tx,ty;
			bomb &tempb=pDoc->m_bomblist.GetNext(i);
			if(tempb.status==0) continue;
			tx=tempb.x1;
			ty=tempb.y1;
			pview->testx=tx;
			pview->testy=ty;
			for(j=0;j<pDoc->m_beequeue.m_beenumber;j++){
				if(pDoc->m_beequeue.m_abee[j].status==1)
				   if(pDoc->m_beequeue.m_abee[j].isInMe(tx,ty))
				   {
				    	pDoc->m_beequeue.m_abee[j].status=0;
						pDoc->m_beequeue.m_status++;
				    	tempb.setlived(0);
				    	pDoc->m_score+=10;
				    	PlaySound(MAKEINTRESOURCE(IDR_WAVE5),AfxGetResourceHandle(), SND_ASYNC|SND_RESOURCE|SND_NODEFAULT);
				   }

			}
		}

		if(pDoc->m_beequeue.m_beenumber==pDoc->m_beequeue.m_status )
			{
				if(queuemap<5)queuemap++;
				else queuemap=0;
				pDoc->m_gatenum++;
	            OnFileRestart();
                return true;
			}
		i=pDoc->m_dropbomblist.GetHeadPosition();
    	while(i!=NULL){
			int j,tx,ty;
			bomb &tempb=pDoc->m_dropbomblist.GetNext(i);
			if(tempb.status==0) continue;
			tx=tempb.x1;
			ty=tempb.y1;
			if(pDoc->m_gun.status>0)
			if(pDoc->m_gun.isInMe(tx,ty)){
					pDoc->m_gun.status-=1;
					tempb.setlived(0);
					PlaySound(MAKEINTRESOURCE(IDR_WAVE2),AfxGetResourceHandle(), SND_ASYNC|SND_RESOURCE|SND_NODEFAULT);
			         if(pDoc->m_gun.status==0)
						{	 
						InputPlayerName dlginputname(this);
                        dlginputname.m_playername="player1";
						if(pDoc->m_score>pDoc->m_recordlist.m_lowscore)
						if(dlginputname.DoModal()==IDOK){
						pDoc->m_recordlist.AddRecord(dlginputname.m_playername,
							   pDoc->m_score);
						pDoc->m_recordlist.WriteRecord();
						}
						start=0;
						GameOver();
						break;
						}
			}
		}  
			return false;
		//}
		

}

UINT CMainFrame::PlayBgSound(LPVOID pParam)
{
    HWND hMCIWnd;
	HINSTANCE hInst;
    CMainFrame * pMainFrm = (CMainFrame *) pParam;
//	if(start==1) {
//	hMCIWnd = MCIWndCreate(pMainFrm->m_hWnd, theApp.m_hInstance, 0, "D:\\Program Files\\Microsoft Visual Studio\\MyProjects\\bee\\res\\town.mid");
//	while(1){
//		MCIWndPlay(hMCIWnd);	
//		PlaySound(MAKEINTRESOURCE(IDR_WAVE3),AfxGetResourceHandle(), SND_ASYNC|SND_RESOURCE|SND_NODEFAULT);
        //Sleep(1000);
//	}
//	}
	return TRUE;
}

UINT CMainFrame::DoDropbowb(LPVOID pParam)
{
		int x,y,i;
        CBeeDoc* pDoc=(CBeeDoc*)(((CMainFrame*)pParam)->GetActiveDocument());
		while(1){
			if(((CMainFrame*)pParam)->start==0)break;
			Sleep(500);
			i=rand()%pDoc->m_beequeue.m_beenumber;
			while(pDoc->m_beequeue.m_abee[i].status==0&&i<pDoc->m_beequeue.m_beenumber)
				i++;
			pDoc->m_beequeue.m_abee[i].getpos(&x,&y);
			dropbomb *newdropbomb=new dropbomb(x,y);
			//PlaySound(MAKEINTRESOURCE(IDR_WAVE2),AfxGetResourceHandle(), SND_ASYNC|SND_RESOURCE|SND_NODEFAULT);
			pDoc->m_dropbomblist.AddTail(*newdropbomb);
		}
		return true;
}

void CMainFrame::OnFileRestart() 
{
	// TODO: Add your command handler code here
	int i;
	CBeeDoc* pDoc=(CBeeDoc*)GetActiveDocument();
	CBeeView *pview=(CBeeView*)GetActiveView();
	KillTimer(2004);
	start=0;
	while(!pDoc->m_bomblist.IsEmpty())
	pDoc->m_bomblist.RemoveTail();
	while(!pDoc->m_dropbomblist.IsEmpty())
	pDoc->m_dropbomblist.RemoveTail();
	pDoc->m_beequeue.initqueue(queuemap);
	pDoc->m_gun.init();
    pDoc->UpdateAllViews(NULL);
    AfxBeginThread(PlayBgSound,this);
	m_dropthread=AfxBeginThread(DoDropbowb,this);
    SetTimer(2454,100,NULL);
}

void CMainFrame::OnFileScore() 
{
	// TODO: Add your command handler code here
	CBeeDoc* pDoc=(CBeeDoc*)GetActiveDocument();
	LookStore dlglookstore(this);
	dlglookstore.m_name1=pDoc->m_recordlist.m_recordlist[0].name;
	dlglookstore.m_score1=pDoc->m_recordlist.m_recordlist[0].score;
	dlglookstore.m_name2=pDoc->m_recordlist.m_recordlist[1].name;
	dlglookstore.m_score2=pDoc->m_recordlist.m_recordlist[1].score;
	dlglookstore.m_name3=pDoc->m_recordlist.m_recordlist[2].name;
	dlglookstore.m_score3=pDoc->m_recordlist.m_recordlist[2].score;
	dlglookstore.m_name4=pDoc->m_recordlist.m_recordlist[3].name;
	dlglookstore.m_score4=pDoc->m_recordlist.m_recordlist[3].score;
	dlglookstore.m_name5=pDoc->m_recordlist.m_recordlist[4].name;
	dlglookstore.m_score5=pDoc->m_recordlist.m_recordlist[4].score;
	dlglookstore.m_name6=pDoc->m_recordlist.m_recordlist[5].name;
	dlglookstore.m_score6=pDoc->m_recordlist.m_recordlist[5].score;
	dlglookstore.m_name7=pDoc->m_recordlist.m_recordlist[6].name;
	dlglookstore.m_score7=pDoc->m_recordlist.m_recordlist[6].score;
	dlglookstore.m_name8=pDoc->m_recordlist.m_recordlist[7].name;
	dlglookstore.m_score8=pDoc->m_recordlist.m_recordlist[7].score;
	dlglookstore.m_name9=pDoc->m_recordlist.m_recordlist[8].name;
	dlglookstore.m_score9=pDoc->m_recordlist.m_recordlist[8].score;
	dlglookstore.m_name10=pDoc->m_recordlist.m_recordlist[9].name;
	dlglookstore.m_score10=pDoc->m_recordlist.m_recordlist[9].score;

	//	dlglookstore.
	if(dlglookstore.DoModal()==IDOK){
		}
	
}

void CMainFrame::GameOver()
{
	RECT *prc,rc={0,0,300,400};
	CBeeView *pview=(CBeeView*)GetActiveView();
	CDC *pdc=pview->GetDC()	;
	KillTimer(2004);
	prc=&rc;
    pdc->DrawText("Game Over",9,prc,DT_CENTER);
}

⌨️ 快捷键说明

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