将代码过程中比较重要的内容做个珍藏,下边代码是关于C++编写的在控制台界面操作的吃豆子游戏的代码,希望能对各朋友有所用处。
#include "lib.h"
#pragma once
extern int level;
int main()
{
FOOD food;
WALL wall;
BODY CurPos;
HALL hall;
int iExit = 0;
while(1)
{
if(iExit)
break;
Init(&food,&wall,&CurPos,&hall);
MakeWall(&wall);
while(1)
{
Sleep(200);
int res = Move(&food,&wall,&CurPos);
break;
{
iExit = 1;
break;
}
ShowScore(&CurPos,&food);
}
}
return 0;
}
lib.h
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <time.h>
#define KEY_UP WM_USER + 1
#define KEY_DOWN WM_USER + 2
#define KEY_LEFT WM_USER + 3
#define KEY_RIGHT WM_USER + 4
#define DIRECTION_UP WM_USER + 5
#define DIRECTION_DOWN WM_USER + 6
#define DIRECTION_LEFT WM_USER + 7
#define DIRECTION_RIGHT WM_USER + 8
#define PRINT_WALL WM_USER + 9
#define PRINT_FOOD WM_USER + 10
#define PRINT_BODY WM_USER + 11
#define PRINT_CLEAN WM_USER + 12
#define KNOCK_WALL WM_USER