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

  • 大小: 0.04M
    文件類(lèi)型: .zip
    金幣: 1
    下載: 0 次
    發(fā)布日期: 2024-04-16
  • 語(yǔ)言: C/C++
  • 標(biāo)簽: 貪吃蛇??

資源簡(jiǎn)介

c 實(shí)現(xiàn)貪吃蛇圖形界面

資源截圖

代碼片段和文件信息

#include
#include?
#include?
#include?
#include?
#include?
#include?
#include
#include?“tools.h“
using?namespace?std;
#define?w?72
#define?s?80
#define?a?75
#define?d?77
#define?maxs?1320
#define?maxwidth?102???//地圖的長(zhǎng)度
#define?maxheight?32???//地圖的寬度
#define?X?21???????????//定義地圖左上角為坐標(biāo)原點(diǎn)
#define?Y?1
#define?speed?100
/*地圖對(duì)象*/
class?Map?{
public:
int?map[maxheight][maxwidth]?=?{?0?};
void?food();
void?wall();
};

/*蛇對(duì)象*/
class?Snake?{
private:
int?dction;
int?length;
bool?ifalive;
public:
Map?belong;
int?x[maxs];
int?y[maxs];
Snake(int?length_s);
void?draw();
void?pb();
void?up();
void?down();
void?left();
void?right();
void?move(char?menu);
void?death();
int?eatfood(char?menu);
};

Snake::Snake(int?length_s)?{
srand((int)time(0));
x[0]?=?rand()?%?(maxwidth-2)?+?X?+1;
y[0]?=?rand()?%?(maxheight?-?4)?+?Y?+3?;
length?=?length_s;
dction?=?s;
ifalive?=true;
for?(int?i?=?1;?i?!=?length;?i++){
x[i]?=?x[0];
y[i]?=?y[i?-?1]?-?1;
}
draw();
}
void?Map::food()?{
int?n;
int?x?y;
srand((unsigned)time(0));
n?=?rand()?%?5?+?1;
for?(int?i?=?1;?i?<=?n;?i++)?{
while?(1)?{
x?=?rand()?%?(maxwidth?-?2)?+?1;
y?=?rand()?%?(maxheight?-?2)?+?1;
if(map[y][x]!=2)
break;
}
map[y][x]?=?1;
showch(x?+?X?y?+?Y?‘?‘?COLOR_HYELLOW?COLOR_BLACK);
}
}
void?Map::wall()?{
setcolor(COLOR_BLACK?COLOR_WHITE);
setconsoleborder(150?40);
for?(int?i?=?0;?i? showch(X?+?i?Y?‘?‘?COLOR_HBLUE?COLOR_BLACK);
showch(X?+?i?Y?+?maxheight-1?‘?‘?COLOR_HBLUE?COLOR_BLACK);
map[0][i]?=?2;
map[maxheight?-?1][i]?=?2;
}
for?(int?i?=?0;?i? showch(X?Y+1?+?i?‘?‘?COLOR_HBLUE?COLOR_BLACK);
showch(X?+?maxwidth-1?Y+1?+?i?‘?‘?COLOR_HBLUE?COLOR_BLACK);
????map[i][0]?=?map[i][maxwidth?-?1]?=?2;
}

}
void?Snake::draw()?{
for?(int?i?=?0;?i? ????if(i!=0)
????showch(x[i]?y[i]?‘?‘?COLOR_HGREEN?COLOR_BLACK);
if?(i?==?0)
showch(x[i]?y[i]?‘?‘?COLOR_HRED?COLOR_BLACK);
}
}
/*上下左右移動(dòng)中代碼重復(fù)部分*/
void?Snake::pb()?{
showch(x[length?-?1]?y[length?-?1]?‘?‘?COLOR_BLACK?COLOR_WHITE);
for?(int?i?=?length?-?1;?i?!=?0;?i--)?{
x[i]?=?x[i?-?1];
y[i]?=?y[i?-?1];
}
}
void?Snake::up()?{
pb();
y[0]--;
draw();
Sleep(speed);
}
void?Snake::down()?{
pb();
y[0]++;
draw();
Sleep(speed);
}
void?Snake::left()?{
pb();
x[0]--;
draw();
Sleep(speed);
}
void?Snake::right()?{
pb();
x[0]++;
draw();
Sleep(speed);
}
/*控制小蛇移動(dòng)函數(shù)?*/
void?Snake::move(char?menu)?{
int?score?=?0score_max?=0score_sn_death?n?=?0;
char?_score[1000];
belong.wall();
belong.food();
ifstream?infile(“record.txt“?ios::in);
if?(!infile)?{
cerr?< exit(1);
}
while?(!infile.eof())?{???//在小蛇移動(dòng)之前先讀出歷史最高分
score_s??=?0;
if(menu==‘1‘)
????infile.g

?屬性????????????大小?????日期????時(shí)間???名稱(chēng)
-----------?---------??----------?-----??----
?????文件????????8218??2019-05-10?12:23??big_2.cpp
?????文件????????6999??2019-05-09?22:48??tools.cpp
?????文件????????1064??2019-05-10?22:23??tools.h
?????文件???????38304??2020-07-04?19:21??貪吃蛇大作戰(zhàn)報(bào)告.docx

評(píng)論

共有 條評(píng)論