Greedy Snake Game

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.