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

📄 bug.h

📁 一个同学用C++写的小游戏
💻 H
字号:
// bug.h: interface of class Bug,FastBug and SlowBug

//**********************************************************************************//
// Athors: Wang Qianrong and He Linbo                                               //
// Data:   2008/06/01                                                               //
//**********************************************************************************//


#ifndef BUG_H
#define BUG_H

#include <vector>
#include "randint.h"
#include "bitmap.h"

//------------------------------------------------------------
// Define four direction for the bugs
//------------------------------------------------------------
enum Direction
{
	East, West, South, North,

	NUMBER     // Number of bug directions
};

//--------------------------------------------------------------
// class for a simple bug
//--------------------------------------------------------------
class Bug
{
public:
	Bug( SimpleWindow &W, int ChanceOfDirectionChange = 50 );
	bool IsHit( const Position &MousePosition );                //  Judge if the bug is hit
	void Kill();                                                //  Bug is removed from the window
	void Create();                                              //  Bug is created and drawn in the window
	virtual void Move() = 0;                                    //  Bug moves to next location in the window

protected:
	//-----------------------------------------------------
	// Bug inspectors
	//-----------------------------------------------------
	SimpleWindow& GetWindow() const;   // Get the window
	
	const BitMap& GetBmp( const Direction &D) const;
    BitMap& GetBmp( const Direction &D );

	Position GetPosition() const;
	Direction GetDirection() const;
	float GetXMovement() const;
	float GetYMovement() const;
	int GetChanceOfDirectionChange() const;

	//-----------------------------------------------------
	// Bug mutators
	//-----------------------------------------------------
	void SetPosition( const Position& p );
	void SetDirection( const Direction& D );
	void SetXMovement( float X );
	void SetYMovement( float Y );
	void ChangeDirection();                                    // Random change bug direction
    void Draw();
	void Erase();
	Position NewPosition() const;
	RandomInt PercentageNumber;

	//---------------------------------------------------------
	// Judge whether the bug is at the Edge 
	//---------------------------------------------------------
	bool AtUpEdge() const;
	bool AtDownEdge() const;
	bool AtLeftEdge() const;
	bool AtRightEdge() const;

private:
	SimpleWindow& Window;
	vector<BitMap> Bmp;
	float XMovement;
	float YMovement;
	int ChanceOfDirectionChange;
	Direction BugDirection;
	Position BugPosition;
};

//------------------------------------------------------------------------
// SlowBug derive from class of Bug
//------------------------------------------------------------------------
class SlowBug : public Bug
{
public:
	SlowBug( SimpleWindow &W, int DirectionChange = 10 );
	void Move();
};

//------------------------------------------------------
// FastBug derive from class of Bug
//------------------------------------------------------
class FastBug : public Bug
{
public:
	FastBug(  SimpleWindow &W, int DirectionChange = 50 );
	void Move();
};


#endif

// end

⌨️ 快捷键说明

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