几天重写了贪吃蛇代码,没成功,怎么比以前还不如,以前还能写出来。
谁能改就改一下。
自制力差
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <malloc.h>
#define RED RGB(255,0,0)
#define GREEN RGB(0,255,0)
#define BLUE RGB(0,0,255)
#define ROWS 50 //行
#define COLUMS 50 //列
int table[ROWS][COLUMS] = {0,0};//桌面
//得分
int SCORE = 0;
clock_t start = 0;
clock_t finish = 0;
HWND CLIENTHWND; //客户区句柄
RECT CLIENTRECT; //客户区
HDC CLIENTRECTHDC;
HBITMAP CLIENTRECTBMP;
HBITMAP HDCBMP;
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam , LPARAM lParam);
void clearSnake();
bool Is_Touch_Self(int x,int y);
bool Is_out_table(int x,int y);
void MOUVE(int x, int y);
void EATE_FOOD(int x, int y);
void CREATE_FOOD();
void PRESS_DOWN(WPARAM wParam);
void PRESS_CHAR(WPARAM wParam);
void NEW_GAME();
void RUN_GAME();
void DRAW_TABLE();
//蛇的身体
typedef struct snake_body
{
int x; //横坐标
int y; //纵坐标
struct snake_body* next;
}SNAKE;
//游戏状态
enum GAME_STA
{
GAME_OVER,
GAME_RUN,
GAME_PAUSE,
GAME_START
}STATE = GAME_START;
//蛇移动的方向
typedef enum _direction
{LEFT=0,
UP,
DOWN,
RIGHT
}DIR;
SNAKE* head = NULL;
DIR direction;
//清除贪吃蛇链表
void clearSnake()
{
SNAKE* p;
p = head;
while(p != NULL)
{
p=p->next;
free(head);
head = p;
}
}
//判断蛇是否碰到自己的身体
bool Is_Touch_Self(int x, int y)
{
int nX, nY;
nX = head->x;
nY = head->y;
if(x == nX && y == nY)
{
return true;
}
return false;
}
//判断蛇头是否出界
bool Is_out_table(int x, int y)
{
if(x<0 ||y<0 ||x>=ROWS ||y>=COLUMS)
{
return true;
}
return false;
}
//蛇没有碰到食物,向前移动
void MOUVE(int x, int y)
{
int nx, ny;
SNAKE* p;
p = head;
while(p!=NULL)
{
nx = p->x;
ny = p->y;
p->x = x;
p->y = y;
x = nx;
y = ny;
p = p->next;
}
}
//蛇碰到食物
void EATE_FOOD(int x, int y)
{
SCORE += table[x][y] ;
SNAKE* p;
p = head;
head = (SNAKE*)malloc(sizeof(SNAKE));
head->x = x;
head->y = y;
head->next = p;
CREATE_FOOD();
}
//创建食物
谁能改就改一下。
自制力差
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <malloc.h>
#define RED RGB(255,0,0)
#define GREEN RGB(0,255,0)
#define BLUE RGB(0,0,255)
#define ROWS 50 //行
#define COLUMS 50 //列
int table[ROWS][COLUMS] = {0,0};//桌面
//得分
int SCORE = 0;
clock_t start = 0;
clock_t finish = 0;
HWND CLIENTHWND; //客户区句柄
RECT CLIENTRECT; //客户区
HDC CLIENTRECTHDC;
HBITMAP CLIENTRECTBMP;
HBITMAP HDCBMP;
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam , LPARAM lParam);
void clearSnake();
bool Is_Touch_Self(int x,int y);
bool Is_out_table(int x,int y);
void MOUVE(int x, int y);
void EATE_FOOD(int x, int y);
void CREATE_FOOD();
void PRESS_DOWN(WPARAM wParam);
void PRESS_CHAR(WPARAM wParam);
void NEW_GAME();
void RUN_GAME();
void DRAW_TABLE();
//蛇的身体
typedef struct snake_body
{
int x; //横坐标
int y; //纵坐标
struct snake_body* next;
}SNAKE;
//游戏状态
enum GAME_STA
{
GAME_OVER,
GAME_RUN,
GAME_PAUSE,
GAME_START
}STATE = GAME_START;
//蛇移动的方向
typedef enum _direction
{LEFT=0,
UP,
DOWN,
RIGHT
}DIR;
SNAKE* head = NULL;
DIR direction;
//清除贪吃蛇链表
void clearSnake()
{
SNAKE* p;
p = head;
while(p != NULL)
{
p=p->next;
free(head);
head = p;
}
}
//判断蛇是否碰到自己的身体
bool Is_Touch_Self(int x, int y)
{
int nX, nY;
nX = head->x;
nY = head->y;
if(x == nX && y == nY)
{
return true;
}
return false;
}
//判断蛇头是否出界
bool Is_out_table(int x, int y)
{
if(x<0 ||y<0 ||x>=ROWS ||y>=COLUMS)
{
return true;
}
return false;
}
//蛇没有碰到食物,向前移动
void MOUVE(int x, int y)
{
int nx, ny;
SNAKE* p;
p = head;
while(p!=NULL)
{
nx = p->x;
ny = p->y;
p->x = x;
p->y = y;
x = nx;
y = ny;
p = p->next;
}
}
//蛇碰到食物
void EATE_FOOD(int x, int y)
{
SCORE += table[x][y] ;
SNAKE* p;
p = head;
head = (SNAKE*)malloc(sizeof(SNAKE));
head->x = x;
head->y = y;
head->next = p;
CREATE_FOOD();
}
//创建食物