?? marsdoc.h
字號:
// MarsDoc.h : interface of the CMarsDoc class
//
// 本程序是《瘋狂的火星蟲—面向對象狀態機實踐指南》的演示程序
//
// 版權所有 (C) 2004 王詠武
// http://www.contextfree.net/wangyw/
//
/////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_MARSDOC_H__C5F4C1BA_5738_430C_8C05_FC603B19AF0E__INCLUDED_)
#define AFX_MARSDOC_H__C5F4C1BA_5738_430C_8C05_FC603B19AF0E__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <vector>
#include "MarsBug.h"
using namespace std;
class CMarsDoc : public CDocument
{
private:
struct SBugInfo
{
SBugInfo(CMarsBug * pBug) : m_pBug(pBug)
{
m_pEnemy = NULL;
m_Event = CMarsBug::EVENT_IDLE;
m_iDistance = CMarsBug::MAX_DISTANCE;
m_bRemove = FALSE;
}
void Init()
{
m_pEnemy = NULL;
m_Event = CMarsBug::EVENT_IDLE;
m_iDistance = CMarsBug::MAX_DISTANCE;
}
void Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
m_pBug->Serialize(ar);
BYTE temp = m_bRemove;
ar << temp;
}
else
{
// TODO: add loading code here
m_pBug->Serialize(ar);
Init();
BYTE temp;
ar >> temp;
if (temp)
m_bRemove = true;
else
m_bRemove = false;
}
}
CMarsBug * m_pBug;
CMarsBug * m_pEnemy;
CMarsBug::ENUM_EVENT m_Event;
int m_iDistance;
bool m_bRemove;
};
protected: // create from serialization only
CMarsDoc();
virtual ~CMarsDoc();
DECLARE_DYNCREATE(CMarsDoc)
// Attributes
public:
void OnDraw(CDC* pDC);
void OnTimer();
void SetWidth(int width) { m_iWidth = width; }
void SetHeight(int height) { m_iHeight = height; }
void Escape(CMarsBug * pBug, CMarsBug * pBugFrom);
void Chase(CMarsBug * pBug, CMarsBug * pBugFrom);
void Walk(CMarsBug * pBug);
void Remove(CMarsBug * pBug);
void Spawn(int x, int y);
static int GetDistance(CMarsBug * pBug1, CMarsBug * pBug2);
private:
void BorderCheck(int & x, int & y);
void AddNewBug();
protected:
int m_iWidth; // 窗口寬度
int m_iHeight; // 窗口高度
vector<SBugInfo> m_Bugs; // 所有的火星蟲
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMarsDoc)
public:
virtual BOOL OnNewDocument();
virtual void Serialize(CArchive& ar);
//}}AFX_VIRTUAL
// Implementation
public:
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// Generated message map functions
protected:
//{{AFX_MSG(CMarsDoc)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_MARSDOC_H__C5F4C1BA_5738_430C_8C05_FC603B19AF0E__INCLUDED_)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -