This article supporting source code
This is another snake game, but the algorithm is a little special. The operation is still very good. Each node has its own color and is dynamically generated. Different colors have different fractions. Each node is a class, and the snake is a class. This program is highly independent and portable. Each pair of nodes is a class, which is a struct. Contains its own information, a list of color, corner coordinates.
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;//the current direction of motion
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);
};
The Csnake class derives from CWnd in order to create an invisible window that completes the timer's function. There is also a DLL to generate a hook. To complete the operation of the keyboard. If not, then. The game area (CEdit) will have a blinking cursor. Of course the hook does not have to use a DLL, because this is a hook of its own program. It is used only for practicing. That's it. It's simple.
Figure I
I hope you will advise. E-mail:error_110@163.com