关键词:
这是一个贪吃蛇大作战类游戏,修改特性为 AI 不互杀;
该程序有四个类:蛇基类 SnakeBase,玩家类 Player,AI 类,Game 类;
SnakeBase 和 AI 均继承自 SnakeBase,SnakeBase 提供基础接口,Game 提供数据初始化以及游戏主循环。
程序设计之初,采用“实运行”方式,即所有动画均在地图 imgMap 上真实绘制,
这样却有一些严重的问题,需要不断地记录节点背景以恢复节点经过的地方等。
后修改为“虚运行”方式,判断位置是否可视后直接绘至窗口内,这样大大降低时间开销,同时不会因为蛇靠近而产生不可擦除的颜色。
至于蛇运行,采用位置继承,即节点下一个位置为上一个节点的位置,但是会发现跨度太大。
解决办法是在这个跨度中插入适当帧数。
执行效果如下:
还准备了许多项目源码和素材以及学习资源!
需要的可以戳一戳文末下方的链接申请下载哦~
源代码
// 头文件 //
#include <easyx.h>
#include <conio.h>
#include <cstdio>
#include <ctime>
#include <cmath>
#pragma comment( lib, "MSIMG32.LIB")
// 窗口大小 //
const short ScreenWidth = 640;
const short ScreenHeight = 480;
// 全局变量 //
long ret = 0;
MOUSEMSG msg;
const short gap = 20;
const short xSide = ScreenWidth / 2 + gap;
const short ySide = ScreenHeight / 2 + gap;
IMAGE* imgMap = new IMAGE(ScreenWidth * 4, ScreenHeight * 4);
const double PI = 3.1415926;
const short nodeSize = 17;
const short nodeGap = 16;
const short stepLen = 4;
const short frame = 4;
const short snakeSpecies = 20;
int killCount = 0;
int mapX = 0;
int mapY = 0;
typedef struct _FOOD
int x;
int y;
int r;
COLORREF c;
Food;
Food* food;
short nFood = 520;
IMAGE imgFood(nodeSize, nodeSize);
const COLORREF mapMainColor = WHITE;
const COLORREF playerColor0 = RGB(120, 0, 0);
const COLORREF playerColor1 = RGB(200, 0, 0);
const COLORREF playerColor2 = RGB(255, 255, 0);
const COLORREF mapLineColor = RGB(225, 225, 225);
// 透明贴图函数:(更多内容请参考官网)
// 参数:
// x, y: 目标贴图位置
// srcimg: 源 IMAGE 对象指针。NULL 表示默认窗体
// dstimg: 目标 IMAGE 对象指针。NULL 表示默认窗体
// transparentcolor: 透明色。srcimg 的该颜色并不会复制到 dstimg 上,从而实现透明贴图
void putTimage(int x, int y, IMAGE* srcimg, IMAGE* dstimg = NULL, UINT transparentcolor = 0)
HDC dstDC = GetImageHDC(dstimg);
HDC srcDC = GetImageHDC(srcimg);
int w = srcimg->getwidth();
int h = srcimg->getheight();
// 使用 Windows GDI 函数实现透明位图
TransparentBlt(dstDC, x, y, w, h, srcDC, 0, 0, w, h, transparentcolor);
// 蛇基类 //
class SnakeBase
public:
// 构造函数
SnakeBase()
Count++;
isDead = false;
length = 50 + rand() % 50;
nNode = length / 5;
maxNode = 9999;
imgHead = imgNode = imgTail = nullptr;
headNode = tailNode = nullptr;
nodeMsg = nullptr;
// 析构函数
virtual ~SnakeBase()
Count--;
Node* temp = headNode;
while (temp != nullptr)
headNode = headNode->nextNode;
delete temp;
temp = headNode;
delete imgHead, imgNode, imgTail;
if (nodeMsg != nullptr)
delete[] nodeMsg;
// 设置image
void SetImage(COLORREF headColor, COLORREF nodeColor, COLORREF tailColor)
imgHead = new IMAGE(nodeSize, nodeSize);
imgNode = new IMAGE(nodeSize, nodeSize);
imgTail = new IMAGE(nodeSize, nodeSize);
SetWorkingImage(imgHead);
setfillcolor(headColor);
solidcircle(nodeSize / 2, nodeSize / 2, nodeSize / 2);
setfillcolor(tailColor);
solidcircle(nodeSize / 2, nodeSize / 2, 2);
SetWorkingImage(imgNode);
setfillcolor(nodeColor);
solidcircle(nodeSize / 2, nodeSize / 2, nodeSize / 2);
SetWorkingImage(imgTail);
setfillcolor(tailColor);
solidcircle(nodeSize / 2, nodeSize / 2, nodeSize / 2);
SetWorkingImage();
// 创建各节点
void Creat(int headX, int headY)
headNode = new Node;
headNode->lastNode = nullptr;
headNode->nextNode = nullptr;
headNode->x = headX;
headNode->y = headY;
Node* temp = headNode;
for (int i = 0; i < nNode - 1; i++)
Node* newNode = new Node;
newNode->lastNode = temp;
newNode->x = temp->x;
newNode->y = temp->y;
temp->nextNode = newNode;
temp = newNode;
temp->nextNode = nullptr;
tailNode = temp;
temp = nullptr;
// 绘制蛇身
void ShowBody()
int n = nNode % 2;
Node* temp = tailNode;
while (temp != headNode)
if (temp->x - nodeSize / 2 + mapX >= nodeSize * -1 && temp->x - nodeSize / 2 + mapX <= ScreenWidth
&& temp->y - nodeSize / 2 + mapY >= nodeSize / -2 && temp->y - nodeSize / 2 + mapY <= ScreenHeight)
putTimage(temp->x - nodeSize / 2 + mapX, temp->y - nodeSize / 2 + mapY, n % 2 == 0 ? imgNode : imgTail);
temp = temp->lastNode;
n++;
if (temp->x - nodeSize / 2 + mapX >= nodeSize * -1 && temp->x - nodeSize / 2 + mapX <= ScreenWidth
&& temp->y - nodeSize / 2 + mapY >= nodeSize / -2 && temp->y - nodeSize / 2 + mapY <= ScreenHeight)
putTimage(temp->x - nodeSize / 2 + mapX, temp->y - nodeSize / 2 + mapY, imgHead);
temp = nullptr;
// 刷新数据
void FlushData(short& n, int& dx, int& dy)
if (n == frame)
nodeMsg = new POINT[nNode];
Node* temp = headNode;
int i = 0;
while (temp != nullptr)
nodeMsg[i].x = temp->x;
nodeMsg[i].y = temp->y;
temp = temp->nextNode;
i++;
Node* temp = tailNode;
int i = nNode - 2;
while (temp != headNode)
if (n == 1)
temp->x = nodeMsg[i].x;
temp->y = nodeMsg[i].y;
else
temp->x += int(stepLen * cos(atan2(nodeMsg[i].y - temp->y, nodeMsg[i].x - temp->x)));
temp->y += int(stepLen * sin(atan2(nodeMsg[i].y - temp->y, nodeMsg[i].x - temp->x)));
temp = temp->lastNode;
i--;
temp = nullptr;
headNode->x += dx;
headNode->y += dy;
if (n == 1)
delete[] nodeMsg;
nodeMsg = nullptr;
// 据长度添加节点
void SetNode(int ex = 0)
int n = nNode;
length += ex;
n = length / 5 - n;
if (n > 0)
while (nNode < maxNode && n != 0)
n--;
nNode++;
Node* newNode = new Node;
newNode->lastNode = tailNode;
newNode->nextNode = nullptr;
newNode->x = tailNode->x;
newNode->y = tailNode->y;
tailNode->nextNode = newNode;
tailNode = newNode;
newNode = nullptr;
else if (n < 0)
while (nNode > 10 && n != 0)
n++;
nNode--;
Node* temp = tailNode;
tailNode = tailNode->lastNode;
tailNode->nextNode = nullptr;
delete temp;
temp = nullptr;
if (nNode == 10)
length = 50;
// 吃到食物
bool GetFood(int k, int x, int y)
int len = nodeGap + 5;
if (x - headNode->x < len && headNode->x - x < len && y - headNode->y < len && headNode->y - y < len)
food[k].x = rand() % (imgMap->getwidth() - xSide * 2) + xSide;
food[k].y = rand() % (imgMap->getheight() - ySide * 2) + ySide;
food[k].r = rand() % 2 + 3;
food[k].c = HSVtoRGB(float(rand() % 360), rand() % 1000 / 2000.0f + 0.5f, rand() % 1000 / 2000.0f + 0.5f);
return true;
return false;
protected:
long length;
int nNode;
int maxNode;
IMAGE* imgHead, * imgNode, * imgTail;
POINT* nodeMsg;
public:
// 蛇节点
typedef struct _NODE
int x;
int y;
struct _NODE* lastNode;
struct _NODE* nextNode;
Node;
bool isDead;
static int Count;
Node* headNode, * tailNode;
;
int SnakeBase::Count = 0;
// Player 类 //
class Player :public SnakeBase
public:
// 构造函数
Player() :SnakeBase()
SetImage(playerColor0, playerColor1, playerColor2);
int headX = rand() % (imgMap->getwidth() - xSide * 2 - nodeSize * 10) + xSide + nodeSize;
int headY = rand() % (imgMap->getheight() - ySide * 2 - nodeSize * 12) + ySide + nodeSize;
Creat(headX, headY);
nt = frame;
// 是否死亡
void IsDead()
if (headNode->x <= xSide || headNode->x >= imgMap->getwidth() - 1 - xSide || headNode->y <= ySide || headNode->y >= imgMap->getheight() - 1 - ySide)
isDead = true;
else
double radian = atan2(headNode->y - headNode->nextNode->y, headNode->x - headNode->nextNode->x);
int x = ScreenWidth / 2 + int(nodeSize / 2 * cos(radian));
int y = ScreenHeight / 2 + int(nodeSize / 2 * sin(radian));
COLORREF c = getpixel(x, y);
if (!(c == mapLineColor || c == mapMainColor))
isDead = true;
else
for (int i = 1; i < 8; i++)
x = ScreenWidth / 2 + int(nodeSize / 2 * cos(radian));
y = ScreenHeight / 2 + int(nodeSize / 2 * sin(radian));
c = getpixel(x, y);
if (!(c == mapLineColor || c == mapMainColor))
isDead = true;
break;
x = ScreenWidth / 2 + int(nodeSize / 2 * cos(radian));
y = ScreenHeight / 2 + int(nodeSize / 2 * sin(radian));
c = getpixel(x, y);
if (!(c == mapLineColor || c == mapMainColor))
isDead = true;
break;
// 移动
void Move(int& ex, int& mapX, int& mapY, short& ddx, short& ddy)
int dx = int(stepLen * cos(atan2(ddy, ddx)));
int dy = int(stepLen * sin(atan2(ddy, ddx)));
mapX -= dx;
mapY -= dy;
FlushData(nt, dx, dy);
for (int k = 0; k < nFood; k++)
if (GetFood(k, food[k].x, food[k].y))
ex += food[k].r / 2;
nt--;
if (nt <= 0)
nt = frame;
while (MouseHit())
msg = GetMouseMsg();
ddx = msg.x - ScreenWidth / 2;
ddy = msg.y - ScreenHeight / 2;
SetNode(ex);
ex = 0;
// 打印成绩
void Print()
settextcolor(BLACK);
settextstyle(20, 0, _T("微软雅黑"));
TCHAR str[32] = 0 ;
_stprintf_s(str, _T("长度:%d"), length);
outtextxy(5, 5, str);
_stprintf_s(str, _T("节点:%d"), nNode);
outtextxy(5, 25, str);
_stprintf_s(str, _T("击杀:%d"), killCount);
outtextxy(5, 45, str);
public:
short nt;
;
// AI 类 //
class AI :public SnakeBase
public:
// 构造函数
AI(Player* player)
p = player;
COLORREF c0 = HSVtoRGB(float(rand() % 360), 1.0f, 0.4f);
COLORREF c1 = HSVtoRGB(float(rand() % 360), 1.0f, 0.8f);
COLORREF c2 = HSVtoRGB(float(rand() % 360), 1.0f, 1.0f);
SetImage(c0, c1, c2);
int headX = 0;
int headY = 0;
do
headX = rand() % (imgMap->getwidth() - xSide * 2 - nodeSize * 3) + xSide + nodeSize;
headY = rand() % (imgMap->getheight() - ySide * 2 - nodeSize * 5) + ySide + nodeSize;
while (IsInPlayer(headX, headY));
Creat(headX, headY);
nt = frame;
minLine = 3 * frame;
curLine = minLine + (rand() % 12) * frame;
ddx = (rand() % ScreenWidth) * (rand() % 1000 < 500 ? 1 : -1);
ddy = (rand() % ScreenHeight) * (rand() % 1000 < 500 ? 1 : -1);
dx = int(stepLen * cos(atan2(ddy, ddx)));
dy = int(stepLen * sin(atan2(ddy, ddx)));
isFast = false;
ct = 0;
exp = 0;
// 是否死亡
bool IsDead(int& ex)
if (headNode->x <= xSide || headNode->x >= imgMap->getwidth() - 1 - xSide || headNode->y <= ySide || headNode->y >= imgMap->getheight() - 1 - ySide)
return true;
else
bool is_dead = IsInPlayer(headNode->x, headNode->y);
if (is_dead)
killCount++;
ex += nNode;
return is_dead;
// 位置是否接触 player
bool IsInPlayer(int headX, int headY)
Node* temp = p->headNode;
while (temp != nullptr)
if (headX - temp->x < nodeSize && temp->x - headX < nodeSize && headY - temp->y < nodeSize && temp->y - headY < nodeSize)
return true;
temp = temp->nextNode;
return false;
// 移动
void Move(int& ex)
if (curLine <= 0)
double rad = atan2(ddy, ddx);
isFast = rand() % 1200 < 100 ? true : false;
curLine = minLine + (rand() % 21) * frame;
do
ddx = (rand() % ScreenWidth + 40) * (rand() % 1000 < 500 ? 1 : -1);
ddy = (rand() % ScreenHeight + 30) * (rand() % 1000 < 500 ? 1 : -1);
while (fabs(atan2(ddy, ddx) - rad) > PI / 6 * 5);
dx = int(stepLen * cos(atan2(ddy, ddx)));
dy = int(stepLen * sin(atan2(ddy, ddx)));
FlushData(nt, dx, dy);
for (int k = 0; k < nFood; k++)
if (GetFood(k, food[k].x, food[k].y))
exp += food[k].r / 2;
nt--;
curLine--;
if (nt <= 0)
nt = frame;
if (rand() % 1000 < 120)
SetNode(rand() % 5 + exp);
exp = 0;
if (rand() % 1000 < 80)
curLine = 0;
if (rand() % 1000 < 900 && curLine > 0) // 90% 概率避免出界
int deadX = headNode->x + int((rand() % 50 + nodeGap) * cos(atan2(ddy, ddx)));
int deadY = headNode->y + int((rand() % 50 + nodeGap) * sin(atan2(ddy, ddx)));
if (deadX <= xSide || deadX >= imgMap->getwidth() - 1 - xSide)
ddx *= -1;
ddy += rand() % 30 + 30;
if (deadY <= ySide || deadY >= imgMap->getheight() - 1 - ySide)
ddy *= -1;
ddx += rand() % 40 + 40;
dx = int(stepLen * cos(atan2(ddy, ddx)));
dy = int(stepLen * sin(atan2(ddy, ddx)));
if (rand() % 1000 < rand() % 400 + 400 && curLine > 0) // 40%-80%(也可以理解为60%) 概率躲避 player
int deadX = headNode->x + int((nodeGap + 5) * cos(atan2(ddy, ddx)));
int deadY = headNode->y + int((nodeGap + 5) * sin(atan2(ddy, ddx)));
if (IsInPlayer(deadX, deadY))
ddx = -1 * ddx + rand() % 40 + 40;
ddy = -1 * ddy + rand() % 30 + 30;
dx = int(stepLen * cos(atan2(ddy, ddx)));
dy = int(stepLen * sin(atan2(ddy, ddx)));
isDead = IsDead(ex);
if (isDead)
int n = nNode / 2;
Node* temp = headNode->nextNode->nextNode;
while (n--)
for (int k = 0; k < nFood; k++)
if (food[k].x < -1 * mapX - nodeSize * 2 || food[k].x > -1 * mapX + nodeSize * 2 + ScreenWidth
|| food[k].y < -1 * mapY - nodeSize * 2 || food[k].y > -1 * mapY + nodeSize * 2 + ScreenHeight)
food[k].x = temp->x + (rand() % 5 + 3) * (rand() % 100 < 50 ? 1 : -1);
food[k].y = temp->y + (rand() % 5 + 3) * (rand() % 100 < 50 ? 1 : -1);
food[k].r = nodeSize / 2;
food[k].c = HSVtoRGB(float(rand() % 360), rand() % 1000 / 2000.0f + 0.5f, rand() % 1000 / 2000.0f + 0.5f);
break;
else if (k == nFood - 1)
n = 0;
break;
temp = temp->nextNode;
temp = nullptr;
private:
short nt;
int minLine;
int curLine;
int ddx, ddy;
int dx, dy;
Player* p;
public:
bool isFast;
clock_t ct;
int exp;
;
// 游戏主体类 //
class Game
public:
// 构造函数
Game()
flushTime = 32;
setbkmode(TRANSPARENT);
BeginBatchDraw();
SetWorkingImage(imgMap);
setlinecolor(mapLineColor);
setfillcolor(mapMainColor);
setbkcolor(BROWN);
cleardevice();
solidrectangle(xSide, ySide, imgMap->getwidth() - 1 - xSide, imgMap->getheight() - 1 - ySide);
for (int i = gap + xSide; i < imgMap->getwidth() - xSide; i += gap)
line(i, ySide, i, imgMap->getheight() - 1 - ySide);
for (int j = gap + ySide; j < imgMap->getheight() - ySide; j += gap)
line(xSide, j, imgMap->getwidth() - 1 - xSide, j);
SetWorkingImage();
player = new Player;
mapX = -1 * (player->headNode->x - ScreenWidth / 2);
mapY = -1 * (player->headNode->y - ScreenHeight / 2);
ai = new Ai;
ai->ais = new AI(player);
Ai* temp = ai;
for (int i = 1; i < 15; i++)
temp->next = new Ai;
temp = temp->next;
temp->ais = new AI(player);
temp->next = ai;
temp = nullptr;
food = new Food[nFood];
for (int k = 0; k < nFood; k++)
food[k].x = rand() % (imgMap->getwidth() - xSide * 2) + xSide;
food[k].y = rand() % (imgMap->getheight() - ySide * 2) + ySide;
food[k].r = rand() % 2 + 3;
food[k].c = HSVtoRGB(float(rand() % 360), rand() % 1000 / 2000.0f + 0.5f, rand() % 1000 / 2000.0f + 0.5f);
Draw();
outtextxy((ScreenWidth - textwidth(_T("左键或右键加速"))) / 2, ScreenHeight / 4 * 3 + 25, _T("左键或右键加速"));
outtextxy((ScreenWidth - textwidth(_T("按任意键继续"))) / 2, ScreenHeight / 4 * 3 + 50, _T("按任意键继续"));
FlushBatchDraw();
ret = _getwch();
// 析构函数
~Game()
EndBatchDraw();
delete imgMap;
delete player;
if (ai != nullptr)
Ai* temp = ai->next;
while (temp != ai)
delete temp->ais;
temp = temp->next;
delete ai->ais;
delete ai;
// 绘制食物
void DrawFood()
for (int k = 0; k < nFood; k++)
if (food[k].x - 9 + mapX >= 0 && food[k].x - 9 + mapX <= ScreenWidth && food[k].y - 9 + mapY >= 0 && food[k].y - 9 + mapY <= ScreenHeight)
if (food[k].r < 6)
setfillcolor(food[k].c);
solidcircle(food[k].x + mapX, food[k].y + mapY, food[k].r);
else
SetWorkingImage(&imgFood);
cleardevice();
setfillcolor(food[k].c);
solidcircle(nodeSize / 2, nodeSize / 2, nodeSize / 2);
setfillcolor(BLACK);
solidcircle(nodeSize / 2, nodeSize / 2, nodeSize / 5);
SetWorkingImage();
putTimage(food[k].x - nodeSize / 2 + mapX, food[k].y - nodeSize / 2 + mapY, &imgFood);
// 绘制界面
void Draw()
putimage(mapX, mapY, imgMap);
DrawFood();
Ai* temp = ai->next;
while (temp != ai)
temp->ais->ShowBody();
temp = temp->next;
temp->ais->ShowBody();
player->IsDead();
player->ShowBody();
player->Print();
FlushBatchDraw();
// 运行
void Running()
short ddx = 0;
short ddy = 0;
time_t ct = clock() - time_t(100);
Ai* temp = ai->next;
while (temp != ai)
temp->ais->ct = clock();
temp = temp->next;
temp->ais->ct = clock();
temp = temp->next;
int ex = 0;
bool isFast = false;
while (!(GetAsyncKeyState(VK_ESCAPE) & 0x8000) && !player->isDead)
if (GetAsyncKeyState('P') & 0x8000)
ret = _getwch();
if (clock() - ct > flushTime)
ct = clock();
isFast = (msg.mkLButton || msg.mkRButton) ? true : false;
player->Move(ex, mapX, mapY, ddx, ddy);
if (isFast)
player->Move(ex, mapX, mapY, ddx, ddy);
if (rand() % 1000 < 100)
ex -= 2;
Draw();
if (clock() - temp->ais->ct > flushTime && !player->isDead)
temp->ais->ct = clock();
temp->ais->Move(ex);
if (temp->ais->isDead)
delete temp->ais;
temp->ais = new AI(player);
temp->ais->ct = clock();
else if (temp->ais->isFast)
temp->ais->Move(ex);
if (temp->ais->isDead)
delete temp->ais;
temp->ais = new AI(player);
temp->ais->ct = clock();
ai = ai->next;
temp = temp->next;
private:
int flushTime;
Player* player;
typedef struct _AI
AI* ais;
struct _AI* next;
Ai;
Ai* ai;
;
// 主函数 //
int main()
initgraph(ScreenWidth, ScreenHeight);
srand((unsigned)time(NULL));
Game game;
game.Running();
settextcolor(BLACK);
settextstyle(50, 0, _T("微软雅黑"));
outtextxy((ScreenWidth - textwidth(_T("游戏结束"))) / 2, ScreenHeight / 3, _T("游戏结束"));
settextstyle(20, 0, _T("微软雅黑"));
outtextxy((ScreenWidth - textwidth(_T("按任意键退出"))) / 2, ScreenHeight / 4 * 3 + 50, _T("按任意键退出"));
FlushBatchDraw();
while (_kbhit())
ret = _getwch();
ret = _getwch();
closegraph();
return 0;
需要编程大礼包的小伙伴可以戳一戳下方链接申请下载哦~
java课程设计---贪吃蛇大作战
目录一、团队课程设计博客链接二、个人负责模块和任务说明三、自己的代码提交记录截图四、自己负责模块或任务详细说明五、课程设计感想一、团队课程设计博客链接 二、个人负责模块和任务说明 1.负责实现闯... 查看详情
贪吃蛇大作战canvas实现(手机触屏操作)--地图逻辑
//html部分<!DOCTYPEhtml><html><headlang="en"> <metacharset="UTF-8"> <metaname="viewport"content="width=device-width,initial-scale=1,user-scalable=no"> <title>贪吃蛇大作战&l 查看详情
贪吃蛇大作战单人版完整代码以及详细解释
贪吃蛇总结:1. 创建WPF应用程序 2. 添加Canvas标签。Name=back; 3. 添加loaded事件 4. 在loaded事件中创建蛇(设置蛇的位置,大小,颜色) this.Left=0;   查看详情
贪吃蛇大作战的一点感悟
春节过罢,闲来无事,玩了两日贪吃蛇大作战,之前玩过球球大作战,感觉球球大作战玩法比较多,也比较难入门。而贪吃蛇大作战就简单多了,就两个原则:1不断地吃食物,让自己长大。2尽量避免撞到别人... 查看详情
贪吃蛇大作战双人版完整代码,不懂问博主。
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; usin 查看详情
c/c++实现球球大作战(高仿版),全源码分享带你轻松完成(代码片段)
每天一个C语言小项目,提升你的编程能力! 《球球大作战》虽然在玩法上类似于大球吃小球的模式看起来很单薄。但是在游戏过程中会出现无数种意外情况,这就需要玩家运用一系列策略来达到不被吃和吃掉别人... 查看详情
贪吃蛇大作战游戏攻略
1.不去人群密集的地方2.长大之后想要啥就有啥3.跑马圈地,长大之后,要让身体占据更大的空间4.不抢食物,头只在身体内运动,只有当外部空间比较大时再进行领土扩张5.不抢食物,而是要围住食物之后慢慢吃.6.对于进入身体内部的蛇... 查看详情
canvas贪吃蛇大作战斗实现及思考
一向比较后知后觉,上周才发现了贪吃蛇大作战这个游戏,玩了一下,居然很上瘾!应该讲是一种虐的快感和不小心死掉的遗憾和再来一盘的心态的集合!只是当时有个思考,就是游戏如何在我切换到其他应用后依然回来可... 查看详情
java小游戏贪吃蛇大作战:来一起回顾童年回忆!
Java小项目之贪吃蛇跪求关注,祝关注我的人都:身体健康,财源广进,福如东海,寿比南山,早上贵子,从不掉发!贪吃蛇,绝对是很多朋友的童年记忆。几乎没有人会说没玩过这款小游戏,因为不管在小灵通手机,直板手机... 查看详情
c语言实现《贪吃蛇》小游戏,代码分享+思路注释(代码片段)
...模式、赏金模式、挑战模式等多种玩法。本次我们将用C语言编写贪吃蛇游戏,效果如图所示:用游戏把子上下左右控制蛇的 查看详情
pygame实战这游戏有毒,刷爆朋友圈:小编已与病毒版贪吃蛇大战了三百回合,最高分339?(代码片段)
...给大家写过几款蛇蛇大作战,也就是类似手机游戏的贪吃蛇游戏,大家还记得嘛❗❗不记得也没关系等下给大家拉出来回忆一下啦~(*^▽^*)💨项目2.7贪吃蛇小游戏Pygame实战:用Python写个贪吃蛇大冒险,保姆级教... 查看详情
c语言零基础项目:贪吃蛇!详细思路+源码分享(代码片段)
每天一个C语言小项目,提升你的编程能力!贪吃蛇游戏大家应该都不陌生了,要说没玩过的话,可能你是15后吧?贪吃蛇游戏最初为单机模式,后续又陆续推出团战模式、赏金模式、挑战模式等多种玩法。... 查看详情
破解“贪吃蛇大作战”的签名信息服务端验证机制
...一些简单的逆向分析,内容比较简单,高手们莫见笑。“贪吃蛇大作战”这个游戏最近玩的人挺多,我也在玩。5分钟限时版,最好成绩也就3000多。我分析的版本是v2.0.1:经过修改,玩了一把5分钟限时赛:长度69224,击杀1456。将... 查看详情
贪吃蛇(c语言实现)(代码片段)
文章目录游戏说明游戏效果展示游戏代码游戏代码详解游戏框架构建隐藏光标光标跳转初始化界面颜色设置初始化蛇随机生成食物打印蛇与覆盖蛇移动蛇游戏主体逻辑函数执行按键判断得分与结束从文件读取最高分更新最高分到... 查看详情
c语言实现经典贪吃蛇游戏(代码片段)
原文链接:C语言贪吃蛇游戏文章目录一、说明二、效果2.1欢迎界面2.2游戏规则2.3得分排行2.4退出游戏2.5游戏界面2.6游戏结束三、源码3.1cmd.h3.2cmd.c3.3io.h3.4io.c3.5model.h3.6service.h3.7service.c3.8ui.h3.9ui.c3.10utils.h3.11utils.c3.12main.c一、说... 查看详情
贪吃蛇二代——穿墙版(c语言实现)(代码片段)
文章目录游戏说明游戏效果展示游戏代码游戏代码详解游戏框架构建初始化界面隐藏光标光标跳转颜色设置初始化蛇随机生成食物打印蛇与覆盖蛇移动蛇游戏主体逻辑函数执行按键判断得分与结束从文件读取最高分更新最高分到... 查看详情
c语言初学者项目200行代码用一个二维数组实现贪吃蛇游戏(代码片段)
s本文章面向c语言初学者,所以我尽可能用最基本的语法实现整个游戏,并且只用到一个二维数组实现,下面将详细讲解实现过程。一个二维数组可以直接打印成一个平面,就形成了整个游戏的背景,我们可以... 查看详情
c语言:如何在cmd命令窗口上玩贪吃蛇游戏
最近在重新学习C语言知识,还别说,在这个过程中,我还真的学到了过去很多没有学习到C语言知识,于是就做了这个游戏–贪吃蛇.运行结果如下:C语言:如何在cmd命令窗口上玩贪吃蛇游戏文章目录1.实现原理2.实现过程3.参考... 查看详情