大家好,我是LCR
如果喜欢这篇文章的话,那就动动小手点个赞吧
更新内容
- 修复退格键(Backspace)退至运行界面边缘就会终止程序的情况
- 新增图标"┼",使程序更具可玩性
- 修复部分显示问题,游玩体验更流畅
更新代码
首先是Backspace的修改:
if((int)a==8){
gotoxy(x,y);
cout<<" ";
f[x][y]=0;
x-=2;
gotoxy(x,y); //代码整体顺序更换
if(x<2) x=99; //此处修改
}
其次是新增图标与显示问题:
if(a=='e'){
bj++;
const int mun=8;
if(bj%mun==1)
yangshi="█ ";
if(bj%mun==2)
yangshi="●";
if(bj%mun==3)
yangshi="◎";
if(bj%mun==4)
yangshi="╳ ";//这里加了个空格
if(bj%mun==5)
yangshi="○";
if(bj%mun==6)
yangshi="┼ ";//新增,并且加了个空格
if(bj%mun==7)
yangshi="★ ";
if(bj%mun==0)
yangshi="";
}
总代码
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
#include<time.h>
using namespace std;
int f[1005][1005];
void color(int a);
void gotoxy(int x,int y);
void color (int a) {
if (a == 0 || a == 14 || a == 20) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
} else if (a == 1 || a == 12) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_BLUE);
} else if (a == 2) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
FOREGROUND_INTENSITY|FOREGROUND_GREEN);
} else if (a == 3) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE);
} else if (a == 4 || a == 11) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
FOREGROUND_INTENSITY|FOREGROUND_RED);
} else if (a == 5 || a == 13) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN);
} else if (a == 7) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
FOREGROUND_GREEN|FOREGROUND_BLUE);
} else if (a == 15) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY);
} else if (a == 16) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE), FOREGROUND_GREEN);
} else if (a == 17) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE), FOREGROUND_RED);
} else if (a == 8) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE), FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
} else if (a == 6) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
FOREGROUND_INTENSITY|FOREGROUND_BLUE);
} else if (a == 9) {
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
FOREGROUND_INTENSITY|FOREGROUND_RED|BACKGROUND_RED|BACKGROUND_GREEN);
}
}
void gotoxy(int x,int y){
COORD p;
HANDLE handle=GetStdHandle(STD_OUTPUT_HANDLE);
p.X=x;
p.Y=y;
SetConsoleCursorPosition(handle,p);
}
//◎●★█┪┓╮╯╳↖ ↗↙ ↘←┼ →↑↓〔●〕﹝○﹞
int main(){
int bj=0,lor=0;
char a;
string yangshi;
int x=0,y=2;
cout<<"请自己创建世界(全屏效果最好)...\n";
cout<<"w/s/a/d移动并创建 Esc退出游戏 e更换创造样式 Backspace撤销... c切换颜色\n";
getche();
system("cls");
gotoxy(x,y);
color(lor);
yangshi="◎";
while(1){
gotoxy(0,0);
cout<<"w/s/a/d移动并创建 Esc退出游戏 e更换创造样式 Backspace撤销 c切换颜色\n";
color(0);
gotoxy(80,20);
if(yangshi!="")cout<<"当前创造样式:";
color(lor);
cout<<yangshi;
if(yangshi=="")cout<<"当前创造样式:无";
gotoxy(x,y);
a=getch();
if((a=='w'&&f[x][y-1]==0)){
if(yangshi!="")f[x][y]=1;
y--;
gotoxy(x,y);
color(lor);
cout<<yangshi;
}
if((a=='s'&&f[x][y+1]==0)){
if(yangshi!="")f[x][y]=1;
y++;
gotoxy(x,y);
color(lor);
cout<<yangshi;
}
if((a=='a'&&f[x-2][y]==0)){
if(yangshi!="")f[x][y]=1;
x-=2;
gotoxy(x,y);
color(lor);
cout<<yangshi;
}
if((a=='d'&&f[x+2][y]==0)){
if(yangshi!="")f[x][y]=1;
x+=2;
gotoxy(x,y);
color(lor);
cout<<yangshi;
}
if(a=='k'){
break;
}
if(a=='e'){
bj++;
const int mun=8;
if(bj%mun==1)
yangshi="█ ";
if(bj%mun==2)
yangshi="●";
if(bj%mun==3)
yangshi="◎";
if(bj%mun==4)
yangshi="╳ ";
if(bj%mun==5)
yangshi="○";
if(bj%mun==6)
yangshi="┼ ";
if(bj%mun==7)
yangshi="★ ";
if(bj%mun==0)
yangshi="";
}
if((int)a==27){
gotoxy(0,30);
exit(0);
}
if((int)a==8){
gotoxy(x,y);
cout<<" ";
f[x][y]=0;
x-=2;
gotoxy(x,y);
if(x<2) x=99;
}
if(a=='c'){
lor++;
if(lor>15) lor=0;
}
}
color(0);
return 0;
}
谢谢大家,喜欢的话请点个赞吧