这次的改进测底的解决了之前的bug,终于可以正常的玩了。
#include"stdafx.h"
#include<stdlib.h>
#include<conio.h>
#include<Windows.h>
#include<iostream>
#include<cstring>
#include<ctime>
using namespace std;
#define PR_Box cout<<"■"
#define PR_Gold cout<<"★"
#define PR_Ag cout<<"☆"
#define PR_FBird cout<<"Ю"
#define PR_DBird cout<<"Ф"
#define PR_Land cout<<"┳┳┯"
#define PR_Bg_TL cout<<"╔"
#define PR_Bg_TR cout<<"╗"
#define PR_Bg_DL cout<<"╚"
#define PR_Bg_DR cout<<"╝"
#define PR_Bg_X cout<<"═"
#define PR_Bg_Y cout<<"║"
#define PR_Blank cout<<" ";
#define Sp 10000000
const int n=19;
const int m=39;
char map[100][100];
const int Init_x=10;
const int Init_y=20;
const int t=10;
long long T=4;
const int Spend=Sp*3;
const int Down_Spend=100;
const int Lenth=8;
bool Down_flag=true;
char GameOver[]="游戏结束!";
enum Direction{Up=12,Down=13};
enum Size{Box,Blank,Bird,Gold,Ag};
class Birds
{
private:
int x;
int y;
int direction;
public:
Birds():x(Init_x),y(Init_y),direction(Up){}
bool Move_Bird();
bool Check_Bird();
bool Bird_Up();
bool Bird_Down();
bool Bird_Left();
bool Bird_Right();
friend bool MoveMap(Birds* &b);
};
bool Birds::Move_Bird()
{
if(GetAsyncKeyState(VK_UP))
if(!Bird_Up())
return false;
/*if(GetAsyncKeyState(VK_DOWN))
if(!Bird_Down())
return false;*/
if(GetAsyncKeyState(VK_LEFT))
if(!Bird_Left())
return false;
if(GetAsyncKeyState(VK_RIGHT))
if(!Bird_Right())
return false;
return true;
}
bool Birds::Check_Bird()
{
if(map[x][y]==Box)
return false;
return true;
}
bool Birds::Bird_Up()
{
if(x>2)
{
map[x][y]=Blank;
x-=2;
if(!Check_Bird())
return false;
map[x][y]=Bird;
}
return true;
}
bool Birds::Bird_Down()
{
if(x<n)
{
map[x][y]=Blank;
x++;
if(!Check_Bird())
return false;
map[x][y]=Bird;
}
return true;
}
bool Birds::Bird_Left()
{
if(y>t+1)
{
map[x][y]=Blank;
y--;
if(!Check_Bird())
return false;
map[x][y]=Bird;
}
return true;
}
bool Birds::Bird_Right()
{
if(y<m)
{
map[x][y]=Blank;
y++;
if(!Check_Bird())
return false;
map[x][y]=Bird;
}
return true;
}
Birds *bird;
void CreateBird()
{
bird=new Birds;
}
void InitMap()
{
int i,j;
///*
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
map[i][j]=Blank;
for(i=1;i<=8;i++)
{
map[Init_x-1][i]=Box;
map[Init_x][i]=Box;
map[Init_x+1][i]=Box;
}
for(j=Init_x-2;j<=Init_x+2;j++)
map[j][i]=Box;
i++;
map[Init_x-1][i]=Box;
map[Init_x][i]=Box;
map[Init_x+1][i]=Box;
i++;
map[Init_x][i]=Box;
/*for(i=1;i<=n;i++)
for(j=1;j<=t;j++)
map[i][j]=Box;
for(i=1;i<=n;i++)
for(j=t+1;j<=m;j++)
map[i][j]=Blank;
for(i=1;i<=5;i++)
{
map[i][37]=Box;
map[i][38]=Box;
}
for(;i<=7;i++)
{
map[i][36]=Box;
map[i][37]=Box;
map[i][38]=Box;
map[i][39]=Box;
}
for(i+=5,j=1;j<=2;i++,j++)
{
map[i][36]=Box;
map[i][37]=Box;
map[i][38]=Box;
map[i][39]=Box;
}
for(;i<=n;i++)
{
map[i][37]=Box;
map[i][38]=Box;
}
strcpy(map[2]," This is doubi Art");
strcpy(map[6]," You can try it ");
strcpy(map[10]," small strong-doubi");
strcpy(map[19]," made by Mr Lin ");*/
map[Init_x][Init_y]=Bird;
}
void menu1()
{
cout<<"═══════════════════════════════════════\n";
}
void menu2()
{
cout<<"\n┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┳\n";
}
void SetSpend(int t)
{
int i;
for(i=1;i<=t;i++)
;
}
void PrintInitMap()
{
menu1();
int i;
for(i=1;i<10;i++)
PR_Gold;
cout<<"本游戏纯属盗版 如有雷同纯属巧合!哈哈哈!";
for(i=1;i<10;i++)
PR_Gold;
for(i=1;i<=18;i++)
cout<<endl;
cout<<"\t\t\t\t\t\t\t制作人————林美辰\n";
menu2();
}
void PrintMap()
{
SetSpend(Spend);
system("CLS");
menu1();
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(map[i][j]==Box)
{
PR_Box;
continue;
}
if(map[i][j]==Blank)
{
PR_Blank;
continue;
}
if(map[i][j]==Bird)
{
PR_FBird;
continue;
}
}
cout<<endl;
}
menu2();
}
void PrintEndMap()
{
system("CLS");
menu1();
int k=1;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(i==10)
{
if(j>=30&&j<=40)
{
switch(k)
{
case 1:cout<<"游";
break;
case 2:cout<<"戏";
break;
case 3:cout<<"结";
break;
case 4:cout<<"束";
break;
case 5:cout<<"!";
}
k++;
}
continue;
}
if(map[i][j]==Box)
{
PR_Box;
continue;
}
if(map[i][j]==Blank)
{
PR_Blank;
continue;
}
if(map[i][j]==Bird)
{
PR_DBird;
continue;
}
}
cout<<endl;
}
menu2();
}
int tx=0;
int flag=-1;
void SetBox(int x)
{
int i;
if(T%Lenth==0)
{
map[5+x][m]=Box;
map[5+x-1][m]=Box;
map[11+x][m]=Box;
map[11+x+1][m]=Box;
}
else if(T%Lenth==1)
{
for(i=1;i<=5+x;i++)
map[i][m]=Box;
for(i=11+x;i<=n;i++)
map[i][m]=Box;
}
else if(T%Lenth==2)
{
for(i=1;i<=5+x;i++)
map[i][m]=Box;
for(i=11+x;i<=n;i++)
map[i][m]=Box;
}
else if(T%Lenth==3)
{
map[5+x][m]=Box;
map[5+x-1][m]=Box;
map[11+x][m]=Box;
map[11+x+1][m]=Box;
}
}
bool MoveMap(Birds* &b)
{
int i,j;
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
if(j>1)
{
if(map[i][j]==Box)
{
map[i][j-1]=map[i][j];
map[i][j]=Blank;
}
else if(map[i][j]==Bird&&i<n)
{
if(Down_flag==true)
{
map[i+1][j]=map[i][j];
map[i][j]=Blank;
b->x++;
}
Down_flag=Down_flag==true?false:true;
}
}
}
}
if(!bird->Check_Bird())
return false;
srand(time(0));
T++;
if(T%4==0)
{
tx=rand()%3;
flag=rand()%2;
flag=flag==0?-1:1;
tx*=flag;
SetBox(tx);
}
else if(T%4==1)
{
SetBox(tx);
}
else if(T%4==2)
{
SetBox(tx);
}
else if(T%4==3)
{
SetBox(tx);
}
if(!bird->Check_Bird())
return false;
return true;
}
int main()
{
InitMap();
PrintInitMap();
cin.get();
CreateBird();
PrintMap();
while(1)
{
if(!MoveMap(bird))
break;
PrintMap();
if(!bird->Move_Bird())
break;
if(!bird->Check_Bird())
break;
PrintMap();
}
cout<<"游戏失败\n";
cin.get();
PrintEndMap();
cin.get();
return 0;
}