C++控制台贪吃蛇

大二下的游戏程序设计第一个小作业,以此篇记录一下,感谢李仕老师的循循善诱和同学们的热情讨论。

#include <iostream>
#include <windows.h>
#include <conio.h>

using namespace std;

#define LeftBorder 3;
#define TopBorder 3;

bool gameOver,Died;					//游戏结束否
bool gamePause,fruitFlash;					//游戏暂停否
const int width = 50;			//游戏窗口宽度
const int height = 20;			//游戏窗口高度
int x, y, fruitX, fruitY;		//蛇头坐标;果子坐标
int score;						//得分
int level;
int tailX[100], tailY[100], nTail;//


enum eDirection {
    STOP = 0, LEFT, RIGHT, UP, DOWN };	//方向枚举
eDirection dir;					//方向变量


HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);

//游戏初始化
void Initial()
{
   
	gameOver = false;			//游戏未结束
	dir = STOP;					//初始方向为停止
	x = width / 2;
	y = height / 2;				//当前蛇头初始位置:区域中心
	tailX[0] = x;
	tailY[0] = y;
	fruitX = (rand() % width) + 1;
	fruitY = (rand() % height) + 1;	//花的位置:随机产生
	score = 0;					//初始得分为0
	nTail = 1;					//
	level = 1;
	gamePause = false;
	fruitFlash = false;
	Died = false;
	CONSOLE_CURSOR_INFO cci;
	cci.bVisible = 0;
	cci.dwSize = 1;
	SetConsoleCursorInfo(h, &cci);
}

void setPos(int cursorX, int cursorY)
{
   
	COORD pos;
	pos.X = cursorX + LeftBorder;
	pos.Y = cursorY + TopBorder;
	SetConsoleCursorPosition(h, pos);
}

void DrawMap()
{
   
	system("CLS")<
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值