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

📄 marsdoc.h

📁 MARS加密解密
💻 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 + -