贪吃蛇游戏

王朝vc·作者佚名  2006-01-17
窄屏简体版  字體: |||超大  

贪吃蛇游戏

作者:我心飞翔

下载源代码

这又是一个贪吃蛇游戏,只不过算法有一点特别。运行得还是很好的。每个结点都有自己的颜色,是动态生成的。不同的颜色有不同的分数.每个结点是一个类,而蛇又是一个类。这样程序的独立和可移植性很强。每个对结点是一个类,也就是一个结构。包含自身的信息,有颜色,转角坐标列表。

class CSnake;

typedef enum{UP=1,DOWN,LEFT,RIGHT,Error} Direction;

typedef struct tagData{

Direction dirt;

CPoint pot;

} Data;

typedef CList DirectionList;

class CNode : public CObject

{

private:

CPoint m_Point;

Direction m_CurrentDirection;//当前的运动方向

DirectionList m_List;

COLORREF m_Color;

int m_nColorIndex;

friend CSnake;

public:

CNode();

virtual ~CNode();

void SetDirection(int nx, int ny);

void SetDirection(CPoint point);

COLORREF GetColor(void);

void SetColor(COLORREF color);

void AddDirection(Data* eValue);

Data* RemoveHead(void);

void SetColor(int index);

int GetColorIndex(void);

void SetCurrentDirection(Direction dirt);

Direction GetCurrentDirection(void);

void Change(CPoint& point);

Data* GetHead(void);

};

在CSnake类派生于CWnd是为了建立一个不可见的窗口,用来完成计时器的功能。这里还有一个dll,用来生成一个钩子。来完成得到键盘的操作。如果不这样作的话。游戏区(CEdit)会有光标闪动。当然钩子也不一定要用dll,因为这是一个自己程序的钩子。用它只是用来练手的。就这么多吧。很简单的。

图一

希望大家指点。

E-mail:Error_110@163.com

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航