贪吃蛇智能版(高级)

说明:
在贪吃蛇智能版(中级)的基础之上,增加了判断小食物是否安全的方法,并且增加了在寻找食物路径失败和寻找尾巴失败之后,会进行一小段的随机溜达,直到重新找到路径为止,当然这段溜达会有一定风险,这个在后面会想办法改进,再改进的版本希望能更上一层楼,姑且叫做专家版吧。

参考代码:
easysnake.h:

#pragma once#include <stdio.h>
#include <graphics.h>
#include <windows.h>
#include <mmsystem.h>
#include <time.h>
#include <conio.h>
#include <queue>
#include "resource.h"
#pragma comment(lib, "winmm.lib")#define SNAKE_DRAW_SIZE     15#define WND_WIDTH           1000
#define WND_HEIGHT          600#define REGION_WIDTH        600
#define REGION_HEIGHT       600#define RIGHT_EDGE_WIDTH    10#define HEADLINE_POSX       265
#define HEADLINE_POSY       120#define TEXT_TIME_POSX      670
#define TEXT_TIME_POSY      100#define TEXT_LEVEL_POSX     670
#define TEXT_LEVEL_POSY     100#define TEXT_SCORE_POSX     670
#define TEXT_SCORE_POSY     200#define TEXT_LEN_POSX       670
#define TEXT_LEN_POSY       300#define TEXT_HIGHSCORE_POSX 670
#define TEXT_HIGHSCORE_POSY 400#define TEXT_HIGHLEVEL_POSX 670
#define TEXT_HIGHLEVEL_POSY 500#define SNAKE_INIT_PT_X     (REGION_WIDTH / SNAKE_DRAW_SIZE / 5)
#define SNAKE_INIT_PT_Y     (REGION_HEIGHT / SNAKE_DRAW_SIZE / 2)#define FIRST_ITEM_POSX     375
#define FIRST_ITEM_POSY     250
#define FIRST_ITEM_WIDTH    220
#define FIRST_ITEM_HEIGHT   30#define SECOND_ITEM_POSX    375
#define SECOND_ITEM_POSY    350
#define SECOND_ITEM_WIDTH   220
#define SECOND_ITEM_HEIGHT  30#define THIRD_ITEM_POSX     375
#define THIRD_ITEM_POSY     450
#define THIRD_ITEM_WIDTH    220
#define THIRD_ITEM_HEIGHT   30#define BIGFOOD_SHOWTIME    6000
#define BIGFOOD_STEPTIME    100#define FOOD_SCORE          1
#define BIG_FOOD_SCORE      5#define INIT_SPEED          110
#define MINUS_SPEED         10#define TOTAL_TIME          100#define SNAKE_MAX ((REGION_WIDTH / SNAKE_DRAW_SIZE) * (REGION_HEIGHT / SNAKE_DRAW_SIZE))
#define BREAKTHROUGHAPPNAME L"BreakThrough"
#define BREAKTHROUGHSCORE   L"HighScore"
#define BREAKTHROUGHLEVEL   L"HighLevel"#define TIMELIMITEDAPPNAME  L"TimeLimited"
#define TIMELIMITEDSCORE    L"HighScore"#define AIAPPNAME           L"Intelligence"
#define AISCORE             L"HighScore"
#define AILEVEL             L"HighLevel"int arrScore[] = { 0, 8, 16, 24, 32, 40, 48, 60, 72, 85, 95, 118, 130, 155, 170, 190, 210, 230, 250, 270, 300, 350, 400,
460, 500, 550, 600, 650, 700, 750, 810, 880, 950, 1000, 1100,
1250, 1400, 1600, 1850, 2100, 2400, 2700, 3000, 3400, 3800, 4200, 4600, 5000,
5500, 5900, 6300, 6800, 7500, 8000, 8500, 9000, 9500, 10000 };enum EmPattern
{emBreakThroughPattern = 1,emTimeLimitedPattern,emIntelligencePattern,
};enum EmStage
{emChooseStage = 1,emPlayStage,
};enum EmDir
{emDirUp = 72,emDirDown = 80,emDirLeft = 75,emDirRight = 77,
};struct Point
{int x;int y;
};struct Snake
{int nCount;Point pt[SNAKE_MAX];EmDir dir;
};struct Food
{Point fpt;char isEat;
};struct BigFood
{Point fpt;char isEat;
};bool mp[REGION_WIDTH / SNAKE_DRAW_SIZE + 1][REGION_HEIGHT / SNAKE_DRAW_SIZE + 1];//存放地图标记
bool isVisit[REGION_WIDTH / SNAKE_DRAW_SIZE + 1][REGION_HEIGHT / SNAKE_DRAW_SIZE + 1];//存放访问标记
Point parent[REGION_WIDTH / SNAKE_DRAW_SIZE + 1][REGION_HEIGHT / SNAKE_DRAW_SIZE + 1];//存放父节点指向
std::queue<Point>tempQ;//存放搜索过程中的节点
std::queue<Point>pathQ;//存放路径节点
int search_dir[4][2] = { { 0, 1 }, { 0, -1 }, { -1, 0 }, { 1, 0 } };
EmStage stage = EmStage::emChooseStage;
EmPattern pattern = EmPattern::emBreakThroughPattern;
Snake snake;
Food food;
BigFood bigFood;
bool bUserInput = false;
int nBigFoodTimer = 0;
int nCurLevel = 1;
int nCurScore = 0;
int nSnakeLen = 3;
int nHighLevel = 0;
int nHighScore = 0;
int nCurSpeed = INIT_SPEED;
int nRemainTime = TOTAL_TIME;
int nTimePast = 0;
int nCurChaseTailTimes = 0;//最大追尾长度void SetMouseNormal();
void SetMouseHand();
void SetLevelText();
void SetHoverStyle();
void SetNormalStyle();
void TackleMouseMove(int x, int y);
void TackleLeftButtonDown(int x, int y);
void TackleMouseAction();
void InitFirstScene();
void InitSecondBackGround();
void InitSecondScene();
bool SearchSnakePath(Point startPt, Point endPt);
void InitMap();
void GameInit();
void PlayGame();
int IsFoodPosOk(int x, int y, Point endPt);
void ProduceFood();
void DrawFood();
int ProduceBigFood();
void DrawBigFood();
int IsEatBigFood();
void EatFood();
void LevelUp();
void DrawSnake();
bool IsEatFoodSafe();
void AIChangeDir();
void AIRealChangeDirection();
bool AISearchBigFood();
bool AISearchSmallFood();
bool AISearchNearTail();
bool AIWanderSearch1(bool isTryAgain = false);
bool AIWanderSearch2(bool isTryAgain = false);
bool AIWanderSearch3(bool isTryAgain = false);
bool AIWanderSearch4(bool isTryAgain = false);
bool AISearchFourCorner(int x, int y);
void SnakeMove();
void ChangeDir();
void BreakSnake();
void WriteRecord();
void BigFoodDisappear();
void TimeEclipse();
void DecideHeadDirection();
void DrawSnakeHead(int nIndex);
void DecideCornerDirection(int idx);
void DrawCorner(int nIndex, int idx);
void DecideBodyDirection(int idx);
void DrawBody(int nIndex, int idx);
void DecideTailDirection(int idx);
void DrawTail(int nIndex, int idx);
void BreakThroughPattern();
void TimeLimitedPattern();

easysnake.cpp

#include "easysnake.h"BOOL KExpandEnvironmentString(IN LPCTSTR lpEnvironmentString, OUT LPTSTR lpExpandString, IN ULONG ulExpandStringLength)
{BOOL bResult = FALSE;LPTSTR lpBuffer = NULL;ULONG ulRetLength = 0;if (!lpEnvironmentString || !lpExpandString || 1 > ulExpandStringLength){goto _abort;}ulRetLength = ::ExpandEnvironmentStrings(lpEnvironmentString, NULL, 0);if (1 > ulRetLength || ulRetLength > ulExpandStringLength - 1){goto _abort;}__try{lpBuffer = new TCHAR[ulRetLength];if (!lpBuffer){goto _abort;}::RtlZeroMemory(lpBuffer, sizeof(TCHAR)* ulRetLength);ulRetLength = ::ExpandEnvironmentStrings(lpEnvironmentString, lpBuffer, ulRetLength);if (ulRetLength && ulRetLength <= ulExpandStringLength - 1){_tcsncpy_s(lpExpandString, ulExpandStringLength - 1, lpBuffer, ulRetLength);bResult = TRUE;}}__except (EXCEPTION_EXECUTE_HANDLER){bResult = FALSE;}_abort:if (lpBuffer){delete[] lpBuffer;lpBuffer = NULL;}return bResult;
}void SetMouseNormal()
{HCURSOR hcur = LoadCursor(NULL, IDC_ARROW);HWND hwnd = GetHWnd();SetClassLong(hwnd, GCL_HCURSOR, (long)hcur);
}void SetMouseHand()
{HCURSOR hcur = LoadCursor(NULL, MAKEINTRESOURCE(32649));HWND hwnd = GetHWnd();SetClassLong(hwnd, GCL_HCURSOR, (long)hcur);
}void SetLevelText()
{switch (pattern){case EmPattern::emBreakThroughPattern:outtextxy(FIRST_ITEM_POSX, FIRST_ITEM_POSY, L"闯关模式");break;case EmPattern::emTimeLimitedPattern:outtextxy(SECOND_ITEM_POSX, SECOND_ITEM_POSY, L"限时模式");break;case EmPattern::emIntelligencePattern:outtextxy(THIRD_ITEM_POSX, THIRD_ITEM_POSY, L"智能模式");break;default:break;}
}void SetHoverStyle()
{settextcolor(RGB(255, 0, 119));SetLevelText();SetMouseHand();
}void SetNormalStyle()
{settextcolor(BROWN);SetLevelText();SetMouseNormal();
}void TackleMouseMove(int x, int y)
{if (stage == EmStage::emPlayStage)return;if (x > FIRST_ITEM_POSX && x < FIRST_ITEM_POSX + FIRST_ITEM_WIDTH && y >FIRST_ITEM_POSY && y < FIRST_ITEM_POSY + FIRST_ITEM_HEIGHT){pattern = EmPattern::emBreakThroughPattern;SetHoverStyle();return;}else{pattern = EmPattern::emBreakThroughPattern;SetNormalStyle();}if (x > SECOND_ITEM_POSX && x < SECOND_ITEM_POSX + SECOND_ITEM_WIDTH && y > SECOND_ITEM_POSY && y < SECOND_ITEM_POSY + SECOND_ITEM_HEIGHT){pattern = EmPattern::emTimeLimitedPattern;SetHoverStyle();return;}else{pattern = EmPattern::emTimeLimitedPattern;SetNormalStyle();}if (x > THIRD_ITEM_POSX && x < THIRD_ITEM_POSX + THIRD_ITEM_WIDTH && y > THIRD_ITEM_POSY && y < THIRD_ITEM_POSY + THIRD_ITEM_HEIGHT){pattern = EmPattern::emIntelligencePattern;SetHoverStyle();}else{pattern = EmPattern::emIntelligencePattern;SetNormalStyle();}
}void TimeLimitedPattern()
{settextstyle(20, 20, L"楷体", 0, 0, 900, 0, 0, 0);setbkmode(TRANSPARENT);settextcolor(RGB(255, 0, 0));WCHAR szCurRemainTime[32];WCHAR szCurScore[32];WCHAR szSnakeLen[32];WCHAR szHighScore[32];swprintf_s(szCurRemainTime, L"剩余时间: %d", nRemainTime);swprintf_s(szCurScore, L"当前得分: %d", nCurScore);swprintf_s(szSnakeLen, L"蛇身长度: %d", snake.nCount);swprintf_s(szHighScore, L"最高分数: %d", nHighScore);outtextxy(TEXT_TIME_POSX, TEXT_TIME_POSY, szCurRemainTime);outtextxy(TEXT_SCORE_POSX, TEXT_SCORE_POSY, szCurScore);outtextxy(TEXT_LEN_POSX, TEXT_LEN_POSY, szSnakeLen);outtextxy(TEXT_HIGHSCORE_POSX, TEXT_HIGHSCORE_POSY, szHighScore);
}void BreakThroughPattern()
{settextstyle(20, 20, L"楷体", 0, 0, 900, 0, 0, 0);setbkmode(TRANSPARENT);settextcolor(RGB(255, 0, 0));WCHAR szCurLevel[32];WCHAR szCurScore[32];WCHAR szSnakeLen[32];WCHAR szHighLevel[32];WCHAR szHighScore[32];swprintf_s(szCurLevel, L"当前级别: %d", nCurLevel);swprintf_s(szCurScore, L"当前得分: %d", nCurScore);swprintf_s(szSnakeLen, L"蛇身长度: %d", snake.nCount);swprintf_s(szHighLevel, L"最高级别: %d", nHighLevel);swprintf_s(szHighScore, L"最高分数: %d", nHighScore);outtextxy(TEXT_LEVEL_POSX, TEXT_LEVEL_POSY, szCurLevel);outtextxy(TEXT_SCORE_POSX, TEXT_SCORE_POSY, szCurScore);outtextxy(TEXT_LEN_POSX, TEXT_LEN_POSY, szSnakeLen);outtextxy(TEXT_HIGHSCORE_POSX, TEXT_HIGHSCORE_POSY, szHighLevel);outtextxy(TEXT_HIGHLEVEL_POSX, TEXT_HIGHLEVEL_POSY, szHighScore);
}void TackleLeftButtonDown(int x, int y)
{if (x > FIRST_ITEM_POSX && x < FIRST_ITEM_POSX + FIRST_ITEM_WIDTH && y >FIRST_ITEM_POSY && y < FIRST_ITEM_POSY + FIRST_ITEM_HEIGHT){pattern = EmPattern::emBreakThroughPattern;InitSecondScene();}if (x > SECOND_ITEM_POSX && x < SECOND_ITEM_POSX + SECOND_ITEM_WIDTH && y > SECOND_ITEM_POSY && y < SECOND_ITEM_POSY + SECOND_ITEM_HEIGHT){pattern = EmPattern::emTimeLimitedPattern;InitSecondScene();}if (x > THIRD_ITEM_POSX && x < THIRD_ITEM_POSX + THIRD_ITEM_WIDTH && y > THIRD_ITEM_POSY && y < THIRD_ITEM_POSY + THIRD_ITEM_HEIGHT){pattern = EmPattern::emIntelligencePattern;InitSecondScene();}
}void TackleMouseAction()
{MOUSEMSG msg;while (1){msg = GetMouseMsg();//获取鼠标信息switch (msg.uMsg){case WM_LBUTTONDOWN://处理鼠标的左键点击消息TackleLeftButtonDown(msg.x, msg.y);break;case WM_MOUSEMOVE://处理鼠标的左键点击消息TackleMouseMove(msg.x, msg.y);break;default:break;}}
}void InitFirstScene()
{cleardevice();stage = EmStage::emChooseStage;IMAGE img;for (int i = 0; i < 22; i++){loadimage(&img, L"jpg", MAKEINTRESOURCE(IDR_JPG1), SNAKE_DRAW_SIZE * 3, SNAKE_DRAW_SIZE * 3);putimage(4 + SNAKE_DRAW_SIZE * 3 * i, 0, &img);}settextstyle(38, 38, L"楷体", 0, 0, 1000, 0, 0, 0);setbkmode(TRANSPARENT);settextcolor(RGB(255, 0, 0));outtextxy(HEADLINE_POSX, HEADLINE_POSY, L"贪吃蛇大作战");settextstyle(28, 28, L"楷体", 0, 0, 1000, 0, 0, 0);setbkmode(TRANSPARENT);pattern = EmPattern::emBreakThroughPattern;SetNormalStyle();pattern = EmPattern::emTimeLimitedPattern;SetNormalStyle();pattern = EmPattern::emIntelligencePattern;SetNormalStyle();pattern = EmPattern::emBreakThroughPattern;TackleMouseAction();
}void InitSecondBackGround()
{setlinecolor(RED);setlinestyle(PS_SOLID, RIGHT_EDGE_WIDTH);line(REGION_WIDTH + 4, 0, REGION_WIDTH + 4, REGION_HEIGHT);if (EmPattern::emBreakThroughPattern == pattern)BreakThroughPattern();else if (EmPattern::emTimeLimitedPattern == pattern)TimeLimitedPattern();else if (EmPattern::emIntelligencePattern == pattern)BreakThroughPattern();
}void InitSecondScene()
{cleardevice();stage = EmStage::emPlayStage;GameInit();InitSecondBackGround();PlayGame();
}bool IsSearchPointOk(int x, int y, Point endPt)
{if (x < 0 || x > REGION_WIDTH / SNAKE_DRAW_SIZE - 1 || y < 0 || y > REGION_HEIGHT / SNAKE_DRAW_SIZE - 1)return false;if (isVisit[x][y])return false;if (mp[x][y] && (x != endPt.x || y != endPt.y))return false;return true;
}void PushPath(Point startPt, Point endPt)
{if (endPt.x != startPt.x || endPt.y != startPt.y){PushPath(startPt, parent[endPt.x][endPt.y]);pathQ.push(endPt);}
}bool SearchSnakePath(Point startPt, Point endPt)
{while (!pathQ.empty())pathQ.pop();while (!tempQ.empty())tempQ.pop();tempQ.push(startPt);isVisit[startPt.x][startPt.y] = true;Point nextPoint;while (!tempQ.empty()){Point firstPoint = tempQ.front();tempQ.pop();if (firstPoint.x == endPt.x && firstPoint.y == endPt.y)return true;for (int i = 0; i < 4; i++){nextPoint.x = firstPoint.x + search_dir[i][0];nextPoint.y = firstPoint.y + search_dir[i][1];if (IsSearchPointOk(nextPoint.x, nextPoint.y, endPt)){isVisit[nextPoint.x][nextPoint.y] = true;tempQ.push(nextPoint);parent[nextPoint.x][nextPoint.y].x = firstPoint.x;parent[nextPoint.x][nextPoint.y].y = firstPoint.y;}}}return false;
}void InitMap()
{memset(mp, false, sizeof(mp)); //把地图标记还原memset(isVisit, false, sizeof(isVisit));for (int i = 0; i < snake.nCount; i++)mp[snake.pt[i].x][snake.pt[i].y] = true;for (int i = 0; i < REGION_WIDTH / SNAKE_DRAW_SIZE; i++){for (int j = 0; j < REGION_HEIGHT / SNAKE_DRAW_SIZE; j++){parent[i][j].x = -1;parent[i][j].y = -1;}}
}void GameInit()
{snake.dir = EmDir::emDirRight;snake.nCount = 3;for (int i = 0; i < snake.nCount; i++){snake.pt[i].x = SNAKE_INIT_PT_X - i;snake.pt[i].y = SNAKE_INIT_PT_Y;}food.isEat = 1;bigFood.isEat = 1;nBigFoodTimer = 0;InitMap();//初始化地图标记WCHAR szTempPath[MAX_PATH] = { 0 };WCHAR szIniPath[MAX_PATH] = { 0 };KExpandEnvironmentString(L"%TEMP%", szTempPath, MAX_PATH);swprintf_s(szIniPath, L"%s\\record.ini", szTempPath);nCurSpeed = INIT_SPEED;nCurLevel = 1;nCurScore = 0;nSnakeLen = 3;nRemainTime = TOTAL_TIME;nTimePast = 0;nCurChaseTailTimes = 0;if (pattern == EmPattern::emTimeLimitedPattern)nHighScore = ::GetPrivateProfileInt(TIMELIMITEDAPPNAME, TIMELIMITEDSCORE, 0, szIniPath);else if (pattern == EmPattern::emBreakThroughPattern){nHighScore = ::GetPrivateProfileInt(BREAKTHROUGHAPPNAME, BREAKTHROUGHSCORE, 0, szIniPath);nHighLevel = ::GetPrivateProfileInt(BREAKTHROUGHAPPNAME, BREAKTHROUGHLEVEL, 1, szIniPath);}else if (pattern == EmPattern::emIntelligencePattern){nHighScore = ::GetPrivateProfileInt(AIAPPNAME, AISCORE, 0, szIniPath);nHighLevel = ::GetPrivateProfileInt(AIAPPNAME, AILEVEL, 1, szIniPath);}
}void PlayGame()
{while (1){while (!_kbhit()){ProduceFood();BigFoodDisappear();TimeEclipse();BeginBatchDraw();cleardevice();InitSecondBackGround();DrawFood();DrawBigFood();EatFood();ProduceFood();SnakeMove();DrawSnake();Sleep(nCurSpeed);EndBatchDraw();BreakSnake();}ChangeDir();}
}void TimeEclipse()
{if (pattern != EmPattern::emTimeLimitedPattern)return;nTimePast += nCurSpeed;nRemainTime = TOTAL_TIME - nTimePast / 1000;nCurSpeed = INIT_SPEED - nTimePast / 1000;if (nRemainTime < 0){WCHAR szScore[32] = { 0 };swprintf_s(szScore, L"你的得分是: %d", nCurScore);::MessageBox(0, szScore, L"时间到", 0);WriteRecord();InitFirstScene();}
}void BigFoodDisappear()
{if (1 == bigFood.isEat)return;nBigFoodTimer += BIGFOOD_STEPTIME;//大食物定时消失if (nBigFoodTimer >= BIGFOOD_SHOWTIME){bigFood.isEat = 1;nBigFoodTimer = 0;}
}void WriteRecord()
{WCHAR szTempPath[MAX_PATH] = { 0 };WCHAR szIniPath[MAX_PATH] = { 0 };WCHAR szHighScore[8] = { 0 };WCHAR szHighLevel[8] = { 0 };KExpandEnvironmentString(L"%TEMP%", szTempPath, MAX_PATH);swprintf_s(szIniPath, L"%s\\record.ini", szTempPath);if (pattern == EmPattern::emBreakThroughPattern){nHighLevel = ::GetPrivateProfileInt(BREAKTHROUGHAPPNAME, BREAKTHROUGHLEVEL, 1, szIniPath);nHighScore = ::GetPrivateProfileInt(BREAKTHROUGHAPPNAME, BREAKTHROUGHSCORE, 0, szIniPath);if (nCurScore > nHighScore){swprintf_s(szHighScore, L"%d", nCurScore);WritePrivateProfileString(BREAKTHROUGHAPPNAME, BREAKTHROUGHSCORE, szHighScore, szIniPath);}if (nCurLevel > nHighLevel){swprintf_s(szHighLevel, L"%d", nCurLevel);WritePrivateProfileString(BREAKTHROUGHAPPNAME, BREAKTHROUGHLEVEL, szHighLevel, szIniPath);}}else if (pattern == EmPattern::emTimeLimitedPattern){nHighScore = ::GetPrivateProfileInt(TIMELIMITEDAPPNAME, TIMELIMITEDSCORE, 0, szIniPath);if (nCurScore > nHighScore){swprintf_s(szHighScore, L"%d", nCurScore);WritePrivateProfileString(TIMELIMITEDAPPNAME, TIMELIMITEDSCORE, szHighScore, szIniPath);}}else if (pattern == EmPattern::emIntelligencePattern){nHighLevel = ::GetPrivateProfileInt(AIAPPNAME, AILEVEL, 1, szIniPath);nHighScore = ::GetPrivateProfileInt(AIAPPNAME, AISCORE, 0, szIniPath);if (nCurScore > nHighScore){swprintf_s(szHighScore, L"%d", nCurScore);WritePrivateProfileString(AIAPPNAME, AISCORE, szHighScore, szIniPath);}if (nCurLevel > nHighLevel){swprintf_s(szHighLevel, L"%d", nCurLevel);WritePrivateProfileString(AIAPPNAME, AILEVEL, szHighLevel, szIniPath);}}
}void BreakSnake()
{if (snake.pt[0].x < 0 || snake.pt[0].x > REGION_WIDTH / SNAKE_DRAW_SIZE - 1 || snake.pt[0].y < 0 || snake.pt[0].y > REGION_HEIGHT / SNAKE_DRAW_SIZE - 1){::MessageBox(0, L"你撞墙了", L"游戏失败", 0);WriteRecord();InitFirstScene();}for (int i = snake.nCount - 2; i > 0; i--){if (snake.pt[i].x == snake.pt[0].x && snake.pt[i].y == snake.pt[0].y){::MessageBox(0, L"你咬到自己了", L"游戏失败", 0);WriteRecord();InitFirstScene();}}
}void ChangeDir()
{int dir = _getch();switch (dir){case EmDir::emDirUp:bUserInput = true;if (snake.dir != EmDir::emDirDown)snake.dir = EmDir::emDirUp;break;case EmDir::emDirDown:bUserInput = true;if (snake.dir != EmDir::emDirUp)snake.dir = EmDir::emDirDown;break;case EmDir::emDirLeft:bUserInput = true;if (snake.dir != EmDir::emDirRight)snake.dir = EmDir::emDirLeft;break;case EmDir::emDirRight:bUserInput = true;if (snake.dir != EmDir::emDirLeft)snake.dir = EmDir::emDirRight;break;default:break;}
}void AIRealChangeDirection()
{Point pt = pathQ.front();pathQ.pop();if (pt.x == snake.pt[0].x){if (pt.y - snake.pt[0].y == -1)snake.dir = EmDir::emDirUp;else if (pt.y - snake.pt[0].y == 1)snake.dir = EmDir::emDirDown;}else if (pt.y == snake.pt[0].y){if (pt.x - snake.pt[0].x == -1)snake.dir = EmDir::emDirLeft;else if (pt.x - snake.pt[0].x == 1)snake.dir = EmDir::emDirRight;}
}bool AISearchBigFood()
{if (bigFood.isEat)return false;InitMap();if (!SearchSnakePath(snake.pt[0], bigFood.fpt))return false;PushPath(snake.pt[0], bigFood.fpt);AIRealChangeDirection();return true;
}bool AISearchSmallFood()
{InitMap();if (!IsEatFoodSafe())return false;if (!SearchSnakePath(snake.pt[0], food.fpt))return false;PushPath(snake.pt[0], food.fpt);AIRealChangeDirection();return true;
}bool AISearchNearTail()
{InitMap();if (!SearchSnakePath(snake.pt[0], snake.pt[snake.nCount - 1]))return false;PushPath(snake.pt[0], snake.pt[snake.nCount -1]);AIRealChangeDirection();nCurChaseTailTimes++;return true;
}bool AIWanderSearch1(bool isTryAgain)
{InitMap();if (snake.pt[0].x < 2)return false;if (mp[snake.pt[0].x - 1][snake.pt[0].y] )return false;if (!isTryAgain && mp[snake.pt[0].x - 2][snake.pt[0].y])//第二次进来时可以靠着蛇身走return false;Point tempPoint;tempPoint.x = snake.pt[0].x - 1;tempPoint.y = snake.pt[0].y;if (!SearchSnakePath(snake.pt[0], tempPoint))return false;PushPath(snake.pt[0], tempPoint);AIRealChangeDirection();return true;
}bool AIWanderSearch2(bool isTryAgain)
{InitMap();if (snake.pt[0].x + 1 > REGION_WIDTH / SNAKE_DRAW_SIZE - 2)return false;if (mp[snake.pt[0].x + 1][snake.pt[0].y])return false;if (!isTryAgain && mp[snake.pt[0].x + 2][snake.pt[0].y])return false;Point tempPoint;tempPoint.x = snake.pt[0].x + 1;tempPoint.y = snake.pt[0].y;if (!SearchSnakePath(snake.pt[0], tempPoint))return false;PushPath(snake.pt[0], tempPoint);AIRealChangeDirection();return true;
}bool AIWanderSearch3(bool isTryAgain)
{InitMap();if (snake.pt[0].y < 2)return false;if (mp[snake.pt[0].x][snake.pt[0].y - 1])return false;if (!isTryAgain && mp[snake.pt[0].x][snake.pt[0].y - 2])return false;Point tempPoint;tempPoint.x = snake.pt[0].x;tempPoint.y = snake.pt[0].y - 1;if (!SearchSnakePath(snake.pt[0], tempPoint))return false;PushPath(snake.pt[0], tempPoint);AIRealChangeDirection();return true;
}bool AIWanderSearch4(bool isTryAgain)
{InitMap();if (snake.pt[0].y + 1 > REGION_HEIGHT / SNAKE_DRAW_SIZE - 2)return false;if (mp[snake.pt[0].x][snake.pt[0].y + 1])return false;if (!isTryAgain && mp[snake.pt[0].x][snake.pt[0].y + 2])return false;Point tempPoint;tempPoint.x = snake.pt[0].x;tempPoint.y = snake.pt[0].y + 1;if (!SearchSnakePath(snake.pt[0], tempPoint))return false;PushPath(snake.pt[0], tempPoint);AIRealChangeDirection();return true;
}bool AISearchFourCorner(int x, int y)
{InitMap();Point tempPoint;tempPoint.x = x;tempPoint.y = y;if (tempPoint.x == snake.pt[0].x && tempPoint.y == snake.pt[0].y)nCurChaseTailTimes = 0;if (mp[tempPoint.x][tempPoint.x])return false;if (!SearchSnakePath(snake.pt[0], tempPoint))return false;PushPath(snake.pt[0], tempPoint);AIRealChangeDirection();return true;
}bool IsEatFoodSafe()
{if (food.fpt.y == 0 && mp[food.fpt.x][food.fpt.y + 1]){for (int i = 0; i < REGION_WIDTH / SNAKE_DRAW_SIZE; i++)if (mp[i][food.fpt.y])return false;}if (food.fpt.y == REGION_HEIGHT / SNAKE_DRAW_SIZE - 1 && mp[food.fpt.x][REGION_HEIGHT / SNAKE_DRAW_SIZE - 2]){for (int i = 0; i < REGION_WIDTH / SNAKE_DRAW_SIZE; i++)if (mp[i][food.fpt.y])return false;}if (food.fpt.x == 0 && mp[food.fpt.x + 1][food.fpt.y]){for (int i = 0; i < REGION_HEIGHT / SNAKE_DRAW_SIZE; i++)if (mp[food.fpt.x][i])return false;}if (food.fpt.x == REGION_WIDTH / SNAKE_DRAW_SIZE - 1 && mp[REGION_WIDTH / SNAKE_DRAW_SIZE - 2][food.fpt.y]){for (int i = 0; i < REGION_HEIGHT / SNAKE_DRAW_SIZE; i++)if (mp[food.fpt.x][i])return false;}if (mp[food.fpt.x - 1][food.fpt.y] && mp[food.fpt.x + 1][food.fpt.y]){for (int i = 0; i < REGION_HEIGHT / SNAKE_DRAW_SIZE; i++)if (mp[food.fpt.x][i])return false;}if (mp[food.fpt.x][food.fpt.y - 1] && mp[food.fpt.x][food.fpt.y + 1]){for (int i = 0; i < REGION_WIDTH / SNAKE_DRAW_SIZE; i++)if (mp[i][food.fpt.y])return false;}return true;
}void AIChangeDir()
{if (pattern != EmPattern::emIntelligencePattern)return;if (bUserInput)return;if (AISearchBigFood())return;if (AISearchSmallFood())return;if (nCurChaseTailTimes > snake.nCount){int nRand = rand() % 4;if (nRand == 0 && AISearchFourCorner(1, 1)){nRand -= 100;return;}if (nRand == 1 && AISearchFourCorner(1, REGION_HEIGHT / SNAKE_DRAW_SIZE - 2)){nRand -= 100;return;}if (nRand == 2 && AISearchFourCorner(REGION_WIDTH / SNAKE_DRAW_SIZE - 2, REGION_HEIGHT / SNAKE_DRAW_SIZE - 2)){nRand -= 100;return;}if (nRand == 3 && AISearchFourCorner(REGION_WIDTH / SNAKE_DRAW_SIZE - 2, 1)){nRand -= 100;return;}}if (AISearchNearTail())return;if (AIWanderSearch1())return;if (AIWanderSearch2())return;if (AIWanderSearch3())return;if (AIWanderSearch4())return;if (AIWanderSearch1(true))return;if (AIWanderSearch2(true))return;if (AIWanderSearch3(true))return;if (AIWanderSearch4(true))return;
}void SnakeMove()
{for (int i = snake.nCount; i > 0; i--){snake.pt[i].x = snake.pt[i - 1].x;snake.pt[i].y = snake.pt[i - 1].y;}AIChangeDir();switch (snake.dir){case EmDir::emDirUp:snake.pt[0].y--;break;case EmDir::emDirDown:snake.pt[0].y++;break;case EmDir::emDirLeft:snake.pt[0].x--;break;case EmDir::emDirRight:snake.pt[0].x++;break;default:break;}bUserInput = false;
}void DecideHeadDirection()
{if (snake.pt[0].y == snake.pt[1].y && snake.pt[0].x > snake.pt[1].x)//头往右走DrawSnakeHead(0);else if (snake.pt[0].y == snake.pt[1].y && snake.pt[0].x < snake.pt[1].x)//头往左走DrawSnakeHead(1);else if (snake.pt[0].x == snake.pt[1].x && snake.pt[0].y < snake.pt[1].y)//头往上走DrawSnakeHead(2);else if (snake.pt[0].x == snake.pt[1].x && snake.pt[0].y > snake.pt[1].y)//头往下走DrawSnakeHead(3);
}void DrawSnakeHead(int nIndex)
{IMAGE img;loadimage(&img, L"jpg", MAKEINTRESOURCE(IDR_JPG2 + nIndex), SNAKE_DRAW_SIZE, SNAKE_DRAW_SIZE);putimage(snake.pt[0].x * SNAKE_DRAW_SIZE, snake.pt[0].y * SNAKE_DRAW_SIZE, &img);
}void DecideCornerDirection(int idx)
{if (snake.pt[idx].y > snake.pt[idx - 1].y && snake.pt[idx].x == snake.pt[idx - 1].x && snake.pt[idx].y == snake.pt[idx + 1].y && snake.pt[idx].x > snake.pt[idx + 1].x)DrawCorner(0, idx);//右->上else if (snake.pt[idx].y == snake.pt[idx - 1].y && snake.pt[idx].x > snake.pt[idx - 1].x && snake.pt[idx].y > snake.pt[idx + 1].y && snake.pt[idx].x == snake.pt[idx + 1].x)DrawCorner(0, idx);//下->左else if (snake.pt[idx].y > snake.pt[idx - 1].y && snake.pt[idx].x == snake.pt[idx - 1].x && snake.pt[idx].y == snake.pt[idx + 1].y && snake.pt[idx].x < snake.pt[idx + 1].x)DrawCorner(1, idx);//左->上else if (snake.pt[idx].y == snake.pt[idx - 1].y && snake.pt[idx].x < snake.pt[idx - 1].x && snake.pt[idx].y > snake.pt[idx + 1].y && snake.pt[idx].x == snake.pt[idx + 1].x)DrawCorner(1, idx);//下->右else if (snake.pt[idx].y < snake.pt[idx - 1].y && snake.pt[idx].x == snake.pt[idx - 1].x && snake.pt[idx].y == snake.pt[idx + 1].y && snake.pt[idx].x > snake.pt[idx + 1].x)DrawCorner(2, idx);//右->下else if (snake.pt[idx].y == snake.pt[idx - 1].y && snake.pt[idx].x > snake.pt[idx - 1].x && snake.pt[idx].y < snake.pt[idx + 1].y && snake.pt[idx].x == snake.pt[idx + 1].x)DrawCorner(2, idx);//上->左else if (snake.pt[idx].y < snake.pt[idx - 1].y && snake.pt[idx].x == snake.pt[idx - 1].x && snake.pt[idx].y == snake.pt[idx + 1].y && snake.pt[idx].x < snake.pt[idx + 1].x)DrawCorner(3, idx);//左->下else if (snake.pt[idx].y == snake.pt[idx - 1].y && snake.pt[idx].x < snake.pt[idx - 1].x && snake.pt[idx].y < snake.pt[idx + 1].y && snake.pt[idx].x == snake.pt[idx + 1].x)DrawCorner(3, idx);//上->右elseDecideBodyDirection(idx);//不是corner的情况在考虑body
}void DrawCorner(int nIndex, int idx)
{IMAGE img;loadimage(&img, L"jpg", MAKEINTRESOURCE(IDR_JPG6 + nIndex), SNAKE_DRAW_SIZE, SNAKE_DRAW_SIZE);putimage(snake.pt[idx].x * SNAKE_DRAW_SIZE, snake.pt[idx].y * SNAKE_DRAW_SIZE, &img);
}void DecideBodyDirection(int idx)
{if (snake.pt[idx].x == snake.pt[idx - 1].x || snake.pt[idx].x == snake.pt[idx + 1].x)//上下DrawBody(0, idx);else if (snake.pt[idx].y == snake.pt[idx - 1].y || snake.pt[idx].y == snake.pt[idx + 1].y)//左右DrawBody(1, idx);
}void DrawBody(int nIndex, int idx)
{IMAGE img;loadimage(&img, L"jpg", MAKEINTRESOURCE(IDR_JPG10 + nIndex), SNAKE_DRAW_SIZE, SNAKE_DRAW_SIZE);putimage(snake.pt[idx].x * SNAKE_DRAW_SIZE, snake.pt[idx].y * SNAKE_DRAW_SIZE, &img);
}void DecideTailDirection()
{int idx = snake.nCount - 1;if (snake.pt[idx].y == snake.pt[idx - 1].y && snake.pt[idx].x < snake.pt[idx - 1].x)//往右DrawTail(0, idx);else if (snake.pt[idx].y == snake.pt[idx - 1].y && snake.pt[idx].x > snake.pt[idx - 1].x)//往左DrawTail(1, idx);else if (snake.pt[idx].y > snake.pt[idx - 1].y && snake.pt[idx].x == snake.pt[idx - 1].x)//往上DrawTail(2, idx);else if (snake.pt[idx].y < snake.pt[idx - 1].y && snake.pt[idx].x == snake.pt[idx - 1].x)//往下DrawTail(3, idx);
}void DrawTail(int nIndex, int idx)
{IMAGE img;loadimage(&img, L"jpg", MAKEINTRESOURCE(IDR_JPG12 + nIndex), SNAKE_DRAW_SIZE, SNAKE_DRAW_SIZE);putimage(snake.pt[idx].x * SNAKE_DRAW_SIZE, snake.pt[idx].y * SNAKE_DRAW_SIZE, &img);
}void DrawSnake()
{for (int i = 0; i < snake.nCount; i++){if (0 == i)DecideHeadDirection();else if (i == snake.nCount - 1)DecideTailDirection();elseDecideCornerDirection(i);}
}int IsEatBigFood()
{if (1 == bigFood.isEat)return 0;for (int i = bigFood.fpt.x; i < bigFood.fpt.x + 3; i++){for (int j = bigFood.fpt.y; j < bigFood.fpt.y + 3; j++){if (snake.pt[0].x == i && snake.pt[0].y == j)return 1;}}return 0;
}void LevelUp()
{if (pattern == EmPattern::emTimeLimitedPattern)return;//WCHAR szLevelUp[32];if (nCurScore > arrScore[nCurLevel]){//swprintf_s(szLevelUp, L"恭喜你,升到第%d级", nCurLevel + 1);//::MessageBox(0, szLevelUp, L"升级啦", 0);nCurLevel++;if (nCurSpeed > 0)nCurSpeed -= MINUS_SPEED;}
}void EatFood()
{if (snake.pt[0].x == food.fpt.x && snake.pt[0].y == food.fpt.y){nCurScore += FOOD_SCORE;snake.nCount++;food.isEat = 1;ProduceBigFood();}if (IsEatBigFood()){nCurScore += BIG_FOOD_SCORE;snake.nCount++;bigFood.isEat = 1;}LevelUp();
}int IsFoodPosOk(int x, int y)
{for (int i = 0; i < snake.nCount; i++){if (snake.pt[i].x == x && snake.pt[i].y == y)return 0;}if (0 == bigFood.isEat){for (int i = bigFood.fpt.x; i < bigFood.fpt.x + 3; i++){for (int j = bigFood.fpt.y; j < bigFood.fpt.y + 3; j++){if (x == i && y == j)return 0;}}}return 1;
}int IsBigFoodPosOk(int x, int y)
{for (int i = x; i < x + 3; i++){for (int j = y; j < y + 3; j++){if (i < 0 || i > REGION_WIDTH / SNAKE_DRAW_SIZE - 1 || j < 0 || j > REGION_HEIGHT / SNAKE_DRAW_SIZE - 1)return 0;for (int k = 0; k < snake.nCount; k++){if (snake.pt[k].x == i && snake.pt[k].y == j)return 0;}}}return 1;
}void ProduceFood()
{if (0 == food.isEat)return;while (1){food.fpt.x = rand() % (REGION_WIDTH / SNAKE_DRAW_SIZE);food.fpt.y = rand() % (REGION_HEIGHT / SNAKE_DRAW_SIZE);if (IsFoodPosOk(food.fpt.x, food.fpt.y))break;}food.isEat = 0;
}void DrawFood()
{IMAGE img;loadimage(&img, L"jpg", MAKEINTRESOURCE(IDR_JPG1), SNAKE_DRAW_SIZE, SNAKE_DRAW_SIZE);putimage(food.fpt.x * SNAKE_DRAW_SIZE, food.fpt.y * SNAKE_DRAW_SIZE, &img);
}int ProduceBigFood()
{if (0 == bigFood.isEat)//大食物没被吃掉,不产生return 0;if (rand() % 2 == 0){while (1){bigFood.fpt.x = rand() % (REGION_WIDTH / SNAKE_DRAW_SIZE);bigFood.fpt.y = rand() % (REGION_HEIGHT / SNAKE_DRAW_SIZE);if (IsBigFoodPosOk(bigFood.fpt.x, bigFood.fpt.y))break;}bigFood.isEat = 0;return 1;}return 0;
}void DrawBigFood()
{if (1 == bigFood.isEat)return;IMAGE img;loadimage(&img, L"jpg", MAKEINTRESOURCE(IDR_JPG1), SNAKE_DRAW_SIZE * 3, SNAKE_DRAW_SIZE * 3);putimage(bigFood.fpt.x * SNAKE_DRAW_SIZE, bigFood.fpt.y * SNAKE_DRAW_SIZE, &img);
}int main()
{HWND hWnd = GetConsoleWindow();SendMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1)));initgraph(WND_WIDTH, WND_HEIGHT);srand((unsigned int)time(NULL));InitFirstScene();getchar();closegraph();return 0;
}

运行结果:
这里写图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/65401.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

贪吃蛇微信小程序源码

每日分享两个小程序源码 下载地址&#xff1a;无极低码&#xff1a;wheart.cnhttps://wheart.cn/so/home?mdw&ridf6d836c8-d54a-11ed-96fa-52540016e6ac <!--snake.wxml--> <view class"control" bindtouchstart"tapStart" bindtouchmove&qu…

win10系统激活提示无法连接到你组织的激活服务器如何解决

1、在桌面新建一个文本文档&#xff0c;把以下代码复制进去&#xff0c;如图所示&#xff1a; slmgr /ipk W269N-WFGWX-YVC9B-4J6C9-T83GX slmgr /skms kms.03k.org slmgr /ato 2、点击文件选择“另存为”&#xff0c;在弹出的界面中&#xff0c;将保存位置选择在桌面&#xff…

无法在此设备上激活WINDOWS因为无法连接到你的组织的激活服务器

在搜索框里搜索 cmd&#xff0c; 使用管理员权限运行&#xff0c;执行一句命令&#xff1a; slmgr /skms http://kms.03k.org点完回车以后&#xff0c;再打一句命令激活 slmgr /ato查激活日期 按下Windows R &#xff0c;输入cmd&#xff0c;出来dos对话框后&#xff0c;输入…

microsoft微软登录新账户/切换账户失败,一直转圈,提示“你似乎没有连接到internet”

无论有没有微软账户&#xff0c;是切换账户还是新电脑登录&#xff0c;原理都是一样的&#xff0c;先使用一个账号注册/登录/设置好微软账户&#xff0c;然后再进行你原本的操作。 在可以进入到桌面并且联网的情况下&#xff0c;登录不上微软账户的几种常用解决方法&#xff1…

登录微软账号时无法连接到网络

登录微软账号时无法连接到网络 关闭代理&#xff0c;手动设置ipv4DNS地址&#xff08;微软dns服务器&#xff1a;4.2…2.1)&#xff0c;改完记得改回来。

解决微软newbing chat的Sorry, looks like your network settings are preventing access to this featur问题

2023.03.25最近大家都有疑惑&#xff0c;已经"魔法"了&#xff0c;突然newbing chat用不了&#xff0c;弹出“Sorry, looks like your network settings are preventing access to this featur”&#xff0c; 已下是解决方法&#xff08;步骤操作的前提&#xff1a;…

成功解决长时间挂起虚拟机后再次打开无法连接网络,并提示网络激活失败(亲测有效)

成功解决长时间挂起虚拟机后再次打开无法连接网络&#xff0c;并提示网络激活失败&#xff08;亲测有效&#xff01;&#xff09; 之前做区块链的一个虚拟机很久没打开&#xff0c;一直处于挂起状态&#xff0c;一直提示网络连接激活失败。试了很多种方法没解决&#xff0c;更…

专治疑难系列 - 无法激活网络的解决方法

‍‍&#x1f3e1;博客主页&#xff1a; Passerby_Wang的博客_CSDN博客-系统运维,云计算,Linux基础领域博主 &#x1f310;所属专栏&#xff1a;『转治疑难系列』 &#x1f30c;上期文章&#xff1a; 无 &#x1f4f0;如觉得博主文章写的不错或对你有所帮助的话&#xff0c;还…

Nature综述:应对新出现的抗真菌耐药性对人类健康的威胁

编译&#xff1a;微科盟小木&#xff0c;编辑&#xff1a;微科盟居居、江舜尧。 微科盟原创微文&#xff0c;欢迎转发转载&#xff0c;转载须注明来源《微生态》公众号。 导读 侵袭性真菌感染对公共健康构成了重大威胁&#xff0c;是抗菌素耐药性的一个未得到充分认识的组成部分…

在传染病中,肠道微生物-免疫力-营养在优化治疗策略中的作用

谷禾健康 传染病&#xff0c;肠道微生物&#xff0c;营养 传染病和感染目前是许多地区尤其是低收入国家主要死亡原因&#xff0c;也是婴儿和老年人等弱势群体的主要风险。免疫系统在这些感染的易感性、持续性和清除中起着至关重要的作用。由于 70-80% 的免疫细胞存在于肠道中&a…

Microbiome:人类肠道和病原菌的可移动抗性组驱动环境中抗生素抗性增长

点击蓝字 关注我们 编译&#xff1a;张璐 校稿&#xff1a;张慧林 论文ID 原名&#xff1a;Mobile resistome of human gut and pathogen drives anthropogenic bloom of antibiotic resistance 译名&#xff1a;人类肠道和病原菌的可移动抗性组驱动环境中抗生素抗性增长 第…

抗生素对微生物组和人体健康的影响

谷禾健康 说起抗生素&#xff0c;可能会觉得有些抽象&#xff0c;那如果说阿莫西林、头孢、红霉素、阿奇霉素等等这些日常生活经常使用的药物&#xff0c;会不会有一些熟悉的感觉。当我们发现身体有一些小炎症(如头痛发热、喉咙痒疼、咳嗽)的时候&#xff0c;首先会想到要使用这…

肠道菌群、性激素与疾病:探索它们的交互作用

谷禾健康 我们的身体中有很多不同的器官&#xff0c;组织&#xff0c;腺体等会产生许多信号分子来精确控制和影响身体的反应和活动&#xff0c;这些信号分子包括激素、神经递质、生长因子、细胞因子等。它们可以促进或抑制细胞的生长和分化&#xff0c;调节细胞间的相互作用和通…

抗生素对肠道微生物群的影响

在与细菌性疾病的斗争中&#xff0c;抗生素是不可避免的。抗生素是人类使用了几十年的治疗细菌感染的救命药物。 虽然抗生素挽救了数百万人的生命&#xff0c;但它们也会消灭一些常驻细菌。现有文献已经确定了与抗生素相关的肠道微生物群失调&#xff08;多样性降低&#xff09…

国外问卷调查项目详解(真正的保姆级教程)

大家好&#xff0c;我是小飞匠&#xff0c;也聊了不少关于国外问卷调查项目的话题&#xff0c;但是不少朋友对于国外问卷调查还是不太了解&#xff0c;今天来做一个国外问卷调查项目详解(全网最全最细致的教程)&#xff0c;如果能够给到大家一点点帮助那也是极好的。 什么是国…

扒一扒传智播客深藏在背后的内幕

扒一扒传智播客深藏在背后的内幕 —— 传智坚持开Java基础班有何猫腻 Java基础太简单&#xff0c;自学一个月就能搞定&#xff1f;大学学了计算机基础的&#xff0c;感觉报基础班有点浪费钱&#xff0c;浪费时间&#xff01;找工作会项目都行了&#xff0c;基础班感觉没多大用…

“马导”怒怼“小鲜肉”,当马儿遇到配音,短视频内容让人捧腹

“马导”怒怼“小鲜肉”&#xff0c;当马儿遇到配音&#xff0c;短视频内容让人捧腹 搞笑配音短视频其实是非常受人欢迎的&#xff0c;尤其是有才华的作者为小动物们配上的搞笑配音&#xff0c;更是让小动物们有了一种拟人的感觉&#xff0c;叫人一看就觉得非常有趣。比如关于以…

中国的程序员培训是不是有问题?

中国技术开放日的出海团对日本进行了为期一周的访问。笔者随行了头两天&#xff0c;参加 Slush Asia 大会&#xff0c;并访问了 Gungho 和 Deloitte 两家企业。虽然已经在日本生活了四年&#xff0c;但这样的体验却甚少&#xff0c;对中日两国的技术力有不少思考。 不知从什么时…

b站韩顺平老师的坦克大战

一.主要的几个类 Mypanel WwyTankGame01AnemyTank //写代码时候把单词拼错了哈哈不好意思BombRecorderNodeShotTankHero 二.功能实现的思路 1.画出敌我坦克 2.实现发射子弹 3.击中时坦克爆炸和消失 4.解决出界问题 5.解决碰撞问题 三.功能的实现 1. Mypanel 这个类…

Linux的入门全解

基于Ubuntu的Linux入门指南 写在前面浅谈LinuxWindows与LinuxLinux起源与发展初学者的学习方式 虚拟机与Ubuntu的安装虚拟机的安装与配置Linux系统的安装与配置 软件的安装与使用Windows与Linux的文件传输工具&#xff1a;VMToolsUbuntu下的软件商城&#xff1a;snap文本编辑器…