91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 6KB
    文件類型: .cpp
    金幣: 1
    下載: 0 次
    發(fā)布日期: 2021-06-04
  • 語言: C/C++
  • 標(biāo)簽: 貪吃蛇??

資源簡(jiǎn)介

寒假里自己寫的一個(gè)貪吃蛇小游戲,利用隊(duì)列寫出來的,代碼不多,大家可以看看

資源截圖

代碼片段和文件信息

#include
#include
#include
#include
#include
using?namespace?std;
//*********************************************************************數(shù)據(jù)聲明區(qū)
#define?Max_Length?1000
#define?width?20 //寬度
#define?length?30 //長(zhǎng)度
#define?Speed?10 //速度
int?map[length][width]; //地圖
enum?Flag?{creatdestory};
struct Direction //方向結(jié)構(gòu)體
{
int?add_x?add_y;
};
struct Direction?Move[4];

struct?Node //節(jié)點(diǎn)結(jié)構(gòu)體
{
int?x?y; //坐標(biāo)
int?d; //方向
};
class?Snake_Body //隊(duì)列類
{
public:
Snake_Body(); //構(gòu)造函數(shù)(初始化函數(shù))
void?Push(struct?Node?tmp); //入隊(duì)函數(shù)
void?Pop(struct?Node?*tmp); //出隊(duì)函數(shù)
void?Get_top(struct?Node?*tmp); //取隊(duì)首函數(shù)
void?Get_end(struct?Node?*tmp); //取隊(duì)尾函數(shù)
private:
struct?Node?node[Max_Length];
int?top; //隊(duì)首
int?end; //隊(duì)尾
};

class?Snake //貪吃蛇類
{
public:
Snake(); //構(gòu)造函數(shù)(初始化)
int?control(); //控制函數(shù)
int?move(); //移動(dòng)函數(shù)
int?get_food(); //判斷是否吃到食物
private:
Node?head; //頭
Node?tail; //尾巴
Snake_Body?body; //身體
};

//**********************************************************************函數(shù)聲明

void?Set_Move(); //初始化方向結(jié)構(gòu)體
void?Set_Map(); //初始化地圖
void?creat_food(); //產(chǎn)生食物
void?out(int&?x?int&?y); //越界處理
void?gameover(); //游戲結(jié)束
void?print_point(struct?Node?tmp?enum?Flag?flag); //畫圖函數(shù)

//**********************************************************************主函數(shù)
void?main()
{
initgraph(width*11length*11);
Set_Move(); //初始化方向結(jié)構(gòu)體
Set_Map(); //初始化地圖
Snake?snake;
snake.control();
gameover();
_getch();
closegraph();
}


//******************************************************************************************************************函數(shù)實(shí)現(xiàn)

//****************************************************************隊(duì)列的相關(guān)函數(shù)

Snake_Body::Snake_Body() //構(gòu)造函數(shù)(初始化函數(shù))
{
top?=?end?=?-1;
}

void?Snake_Body::Push(struct?Node?tmp) //入隊(duì)函數(shù)
{
node[top].d?=?tmp.d;
top++;
if?(top?==?Max_Length)
top?=?0;
node[top]?=?tmp;
}
void?Snake_Body::Pop(struct?Node?*tmp) //出隊(duì)函數(shù)
{
end++;
if?(end?==?Max_Length)
end?=?0;
*tmp?=?node[end];
}

void?Snake_Body::Get_top(struct?Node?*tmp) ? //取隊(duì)首
{
*tmp?=?node[top];
}
void?Snake_Body::Get_end(struct?Node?*tmp) //取隊(duì)尾
{
*tmp?=?node[end];
}

//*****************************************************************************貪吃蛇的相關(guān)函數(shù)
Snake::Snake() //構(gòu)造函數(shù)(初始化)
{
head.x?=?head.y?=?1;
tail.x?=?tail.y?=?1;
head.d?=?tail.d?=?0;
body.Push(head);
}

int?Snake::control() //控制函數(shù)
{
char?choice;
int?x?yd;
Set_Move();
creat_food();
while?(1)
{
body.Get_top(&head);
if?(_kbhit()?==?0)
{
d?=?head.d;
x?=?head.x?+?Move[d].add_x;
y?=?head.y?+?Move[d].add_y;
out(x?y);
if?(map[y][x]?==?1)
return?0;
else
{
if(map[y][x]!=2)
map[y][x]?=?1;
head.x?=?x;
head.y?=?y;
head.d?=?

評(píng)論

共有 條評(píng)論