1
马博闻
修练者
修练者
复制到DEV C++
#include <iostream>
#include <conio.h>
#include <windows.h>
using namespace std;
void Color(int a){//颜色控制函数(部分代码为复制)
if(a==0) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);//标准
if(a==1) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_BLUE); //浅蓝
if(a==2) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN); //绿
if(a==3) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE); //紫红
if(a==4) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED); //浅橙
if(a==5) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN); //浅黄
if(a==6) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE); //蓝
if(a==7) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE); //浅灰
if(a==8) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED); //红
if(a==9) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY|BACKGROUND_GREEN|BACKGROUND_BLUE); //浅蓝 外
if(a==10) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY|BACKGROUND_RED|BACKGROUND_BLUE); //紫红 外
if(a==11) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED|FOREGROUND_BLUE); //深紫
if(a==12) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED|FOREGROUND_GREEN); //棕黄
if(a==13) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY); //深灰
if(a==14) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN|FOREGROUND_BLUE); //较浅蓝
return;
}
struct map_s{
int flag;
string s;
}map[105][505];
struct pla_s{
int x,y;
}pl;
string blo[10]={"","##","&&","--","//","\\\\","||","%%"," a"};
int blo_cnt=1;
string now_blo="##";
void CSH(){
pl.x=79;
pl.y=11;
for(int i=1;i<=100;i++){
for(int j=1;j<=500;j++){
if(i<80) map[i][j].s=" ";
else if(i<85) map[i][j].s="&&";
else map[i][j].s="##";
}
}
}
void SC(){
system("cls");
Color(5);
for(int i=1;i<=22;i++)cout<<"++";
cout<<endl;
for(int i=pl.x-10;i<=pl.x+10;i++){
Color(5);
cout<<"+";
for(int j=pl.y-10;j<=pl.y+10;j++){
if(i<=0||j<=0||i>=100||j>=500)continue;
if(i==pl.x&&j==pl.y){
Color(0);
cout<<"Yo";
}else{
if(map[i][j].s=="&&")Color(12);
if(map[i][j].s=="##")Color(13);
if(map[i][j].s=="--")Color(6);
if(map[i][j].s=="%%")Color(2);
if(map[i][j].s==" a")Color(8);
if(map[i][j].s=="||"||map[i][j].s=="//"||map[i][j].s=="\\\\")Color(4);
cout<<map[i][j].s;
}
}
Color(5);
cout<<"+";
cout<<endl;
}
Color(5);
for(int i=1;i<=22;i++)cout<<"++";
Color(0);
cout<<endl<<"Your Block:";
if(now_blo=="&&")Color(12);
if(now_blo=="##")Color(13);
if(now_blo=="--")Color(6);
if(now_blo=="%%")Color(2);
if(now_blo==" a")Color(8);
if(now_blo=="||"||now_blo=="//"||now_blo=="\\\\")Color(4);
cout<<now_blo;
return;
}
int main(){
CSH();
SC();
while(1){
char c=getch();
if(c=='w'&&pl.x>11)pl.x--;
if(c=='s'&&pl.x<89)pl.x++;
if(c=='a'&&pl.y>11)pl.y--;
if(c=='d'&&pl.y<489)pl.y++;
if(c=='t')map[pl.x][pl.y].s=now_blo;
if(c=='y')map[pl.x][pl.y].s=" ";
if(c=='h'&&blo_cnt<8)blo_cnt++;
if(c=='g'&&blo_cnt>1)blo_cnt--;
now_blo=blo[blo_cnt];
SC();
}
return 0;
}
按 w s a d 移动
按 g h 切换方块
按 t y 放置/删除方块
0
0
0
0
0
0
0