#include
#include
#include
#include
using namespace std;
int eee = 0,ala = 0;
int fen = true;
int x = 1,y = 1,nextx,nexty,ranx,rany,scole = 0,er = 1;
int random(int b)
{
return rand()%b+1;
}
void SetCCPos(int x, int y){
HANDLE hOut;
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
COORD pos;
pos.X = x;pos.Y = y;
SetConsoleCursorPosition(hOut, pos);
}
int main()
{
srand((int)time(0));
char giao[7];
int len;
cout << "输入想要的大小" << endl;
cin >> len;
system("cls");
cout << "输入想要的等级变化(1-7级)。" << endl;
for(int i = 0;i <= 6;i++){
cout << i+1 << "级:";
cin >> giao[i];
}
system("cls");
int abc = len-2;
char a[len][len],now[len][len];
for(int i = 0;i <= len-1;i++){
for(int j = 0;j <= len-1;j++){
if(i == 0 or j == 0 or i == len-1 or j == len-1)
a[i][j] = '*';
else if(i == 1 and j == 1)
a[i][j] = giao[eee];
else
a[i][j] = ' ';
}
}
for(int i = 0;i < len;i++){
for(int j = 0;j < len;j++){
cout << a[i][j] << " ";
if(a[i][j] != giao[eee] and a[i][j] != '$')
now[i][j] = a[i][j];
else
now[i][j] = ' ';
}
cout << endl;
}
cout << "退出按p,移动awsd。" << endl << "目标:“吃”$。每10分升级,最高7级。" << endl;
cout << "你的分数目前是:" << scole << endl;
cout << "你的等级目前是:" << eee+1 << endl;
char b;
for(int fdfdbsdbqpxpmfj;true;b = getch()){
if(b == 'w'){
nextx = -1;
nexty = 0;
}
else if(b == 'a'){
nextx = 0;
nexty = -1;
}
else if(b == 's'){
nextx = 1;
nexty = 0;
}
else if(b == 'd'){
nextx = 0;
nexty = 1;
}
else if(b == 'p'){
cout << "你的分数是:" << scole << endl << "感谢游玩!";
exit(0);
}
if(a[x+nextx][y+nexty] != '*'){
if(a[x+nextx][y+nexty] == '$'){
scole++;
fen = true;
SetCCPos(16,len+2);
cout << scole;
}
a[x][y] = ' ';
a[x+nextx][y+nexty] = giao[eee];
x += nextx;
y += nexty;
}
if(fen){
ranx = random(abc);
rany = random(abc);
while(a[ranx][rany] == giao[eee]){
ranx = random(abc);
rany = random(abc);
}
a[ranx][rany] = '$';
fen = false;
}
for(int i = 0;i < len;i++){
for(int j = 0;j < len;j++){
if(a[i][j] != now[i][j]){
SetCCPos(j*2,i);
cout << a[i][j];
}
}
}
if(scole%10 == 0 and eee != 6 and scole != 0){
eee = scole/10;
ala = scole/10+1;
SetCCPos(16,len+3);
cout << eee+1;
}
if(eee == 6 and er == 1){
system("cls");
SetCCPos(0,0);
cout << "你赢了,恭喜你!" << endl;
exit(0);
}
for(int i = 0;i < len;i++){
for(int j = 0;j < len;j++){
now[i][j] = a[i][j];
}
}
}
return 0;
}



