5*5的。
最开始地面加载不出来,就当是特性吧。
#include
#include
#include
#include
#include
#define KEY_DOWN(VK_NONAME)((GetAsyncKeyState(VK_NONAME)&0x8000)?1:0)
using namespace std;
int main(){
string a[6][15];
int ra;
int score=0, tmp;
int x1=1,y1=2,x2=1,y2=3;
int jump=0;
for(int i=0;i<5;i++)
{
for(int j=0;j<13;j++)a[i][j]=" ";
}
while(1)
{
tmp = score / 10;
for(int i=1;i<5;i++)
{
for(int j=0;j<14;j++)
a[i][j-1]=a[i][j];
}
a[0][13]=a[1][13]=a[2][13]=a[3][13]=" ";
a[4][13]=".";
srand((unsigned)time(NULL)+rand());
ra=rand()%6;
if(ra==1&&a[3][12]!="|"&&a[2][12]!="o"&&a[3][11]!="|"&&a[4][0]!=" "&&a[1][12]!="o")a[3][13]="|";
if(ra==2&&a[3][12]!="|"&&a[2][12]!="o"&&a[3][11]!="|"&&a[4][0]!=" "&&a[1][12]!="o")a[3][13]=a[2][13]="|";
if(ra==2&&a[3][12]=="|"&&a[2][12]!="o"&&a[3][11]!="|"&&a[4][0]!=" "&&a[1][12]!="o")a[3][13]=a[2][13]="|";
if(ra==3&&a[3][12]!="|"&&a[3][11]!="o"&&a[2][12]!="|"&&a[4][0]!=" "&&score>=100)a[2][13]="o";
if(ra==4&&a[4][0]!=" "&&a[3][12]!="|"&&score>=100) a[1][13]="o";
if(jump==0)x1=1;y1=2;x2=1;y2=3;
if(KEY_DOWN('S'))
{
if(!jump){
x1=2;y1=3;}
else {
jump=0;
x1=1;y1=2;x2=1;y2=3;
}
}
else if(KEY_DOWN('W')&&jump==0)
{
y1-=2;y2-=2;
jump=1;
}
if(jump==4)
{
jump=0;
x1=1;y1=2;x2=1;y2=3;
}
if(jump!=0)jump++;
for(int i=0;i<5;i++)
{
for(int j=0;j<14;j++)
{
if(i==y1&&j==x1||i==y2&&j==x2)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY);
cout<<"龙";
if(a[i][j]=="o"||a[i][j]=="|"){
cout<<"You died"<<endl;
cout<<"score:"<<score;
char c;
cin>>c;
return 0;
}
}
else if(a[i][j]=="o")
{
if((score/200)%2==0)SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY);
else SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY);
cout<<a[i][j];
}
else if(a[i][j]=="."||a[i][j]=="|"){
if((score/200)%2==0)SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY);
else SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY);
cout<<a[i][j];
}
else{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY);
if(rand()%50==1)a[i][j]=" ";
cout<<a[i][j];
}
}
cout<<endl;
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY);
cout<<"score:"<<score;
score++;
if(score>2000)Sleep(50);
else Sleep(250 - tmp);
system("cls");
}
return 0;
}
玩法详见poj
#include
#include
using namespace std;
int main() {
int x1=3,y1=1,x2,y2,cnt=0;
char move;
char map[7][7]={
'#','#','#','#','#','#','#',
'#','.','.','.','#','#','#',
'#','.','.','#','#','O','#',
'#','.','.','<','.','E','#',
'#','.','.','<','.','E','#',
'#','.','.','.','.','^','#',
'#','#','#','#','#','#','#'};
int flag=1;
int win=0;
while(1){
system("cls");
if(flag==1){x2=x1;y2=y1;if(map[y1][x1]=='O')win=1;if(map[y1][x1]=='E')win=-1;}
if(flag==2){y2=y1-1;x2=x1;}
if(flag==3){x2=x1-1;y2=y1;}
for(int i=0;i<7;i++){
for(int j=0;j<7;j++){
if(i==y1&&j==x1||i==y2&&j==x2){
cout<<'X';
if(map[i][j]=='#'||map[i][j]=='<'||i<0||i>6||j<0||j>6)win=-1;
if(map[i][j]=='^'){
for(int p=0;p<6;p++){
for(int q=0;q<6;q++){
if(map[p][q]=='<')map[p][q]='>';
else if(map[p][q]=='>')map[p][q]='<';
}
}
}
}
else cout<<map[i][j];
}
cout<<endl;
}
if(win==-1){
cout<<"Lose";
return 0;
}
if(win==1){
cout<<"win";
return 0;
}
move = _getch();
if(move=='w'){
y1--;
if(flag==1){flag=2;}
else if(flag==2){y1--;flag=1;}
else if(flag==3){flag=3;}
}
if(move=='s'){
y1++;
if(flag==1){flag=2;y1++;}
else if(flag==2){flag=1;}
else if(flag==3){flag=3;}
}
if(move=='a'){
x1--;
if(flag==1){flag=3;}
else if(flag==2){flag=2;}
else if(flag==3){flag=1;x1--;}
}
if(move=='d'){
x1++;
if(flag==1){x1++;flag=3;}
else if(flag==2){flag=2;}
else if(flag==3){flag=1;}
}
}
return 0;
}