0
已解决
被禁言


初级守护
代码:
#include <iostream>
#include <cstdlib>
#include <windows.h>
#include <cstdio>
#include <conio.h>
#define k(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
struct play{
int x,y;
}pl;
string bb[100]={"","##","tr","lf","&&","++","--",".."};//背包
int b1[100];//数
int ph[100]={0,10,5,1,3,12,15,20};
struct map{
string s;
int y;
string s1;//掉落物
}map[305][1105];
void setColor(int color) {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, color);
}
void gotoxy(int x, int y) {
COORD pos = {x, y};
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOut, pos);
}
void csh(){
int n=140,nn=140,m=5; //高 目标
int fl1=1,fl2,fl3,fl4,fl5,fl6=150,fl7; //
for(int i=1;i<=1000;i++){
if(fl1){
fl7=0;
if(fl2!=3)fl2=rand()%3+1;
else fl2=rand()%2+1;
if(fl2==1){
fl3=rand()%30+30;
nn=n+rand()%3-1;
}else if(fl2==2){
fl3=rand()%50;
fl5=fl3;
fl4=rand()%2*2+2;
}else{
fl7=1;
fl3=rand()%10+30;
fl5=fl3;
fl4=2;
fl6=n;
}
fl1=0;
}
if(fl2==1){
if(n>nn)n-=rand()%2;
else n+=rand()%2;
fl3--;
if(fl3==0)fl1=1;
}else if(fl2==2){
if(fl4%2==0){
if(n>90 )n-=rand()%3;
fl3--;
}else{
if(n<190)n+=rand()%3;
fl3--;
}
if(fl3==0){
fl3=fl5;
fl4--;
if(fl4%2==0){
fl3=rand()%50;
fl5=fl3;
}
if(fl4==0){
fl1=1;
}
}
}else{
if(fl4%2==0){
if(n>90 )n+=rand()%3;
fl3--;
}else{
if(n<190)n-=rand()%3;
fl3--;
}
if(fl3==0){
fl3=fl5;
fl4--;
if(fl4%2==0){
fl3=rand()%10+30;
fl5=fl3;
}
if(fl4==0){
fl1=1;
fl6=max(fl6,n);
}
}
}
for(int j=1;j<=200;j++){
if(j>=n){
map[j][i].s="##";
map[j][i].y=10;
}
else map[j][i].s=" ";
if(j>fl6&&map[j][i].s==" "&&fl7)map[j][i].s="ss";
// cout<<map[j][i].s;
}
if(m>6)m-=rand()%2;
else m+=rand()%2;
for(int j=n;j>=n-m;j--){
map[j][i].s="&&";
map[j][i].y=3;
}
// cout<<endl;
}
for(int j=1;j<=1000;j++){
for(int i=1;i<=200;i++){
if(map[i][j].s=="&&"&&map[i-1][j].s==" "&&rand()%5==0&&map[i-1][j-1].s==" "){//树
int tall=rand()%4+4;
int tt=tall-rand()%3-2;
int dt=rand()%2+1;
for(int k=i;k>=i-tall;k--){
map[k][j].s="tr";
map[k][j].y=5;
}
for(int k=i-tall-1;k>=i-tall-dt;k--){
map[k][j].s="lf";
map[k][j].y=1;
}
for(int k=i-tall-dt+1;k<=i-tall-dt+tt+1;k++){
map[k][j-1].s="lf";
map[k][j+1].s="lf";
map[k][j-1].y=1;
map[k][j+1].y=1;
}
}
if(map[i][j].s=="##"){//矿
int p=rand()%1500;
if(p==1||p==2||p==3||p==4||p==5){
for(int I=i-1;I<=i+1;I++){
for(int J=j-1;J<=j+1;J++){
if(rand()%2==0){
map[I][J].s="++";
map[I][J].y=12;
}
}
}
}else if(p==6||p==7||p==8){
map[i][j].s="--";
map[i][j].y=15;
if(rand()%2==0){
map[i][j+1].s="--";
map[i][j+1].y=15;
}
if(rand()%2==0){
map[i+1][j].s="--";
map[i+1][j].y=15;
}
if(rand()%2==0){
map[i][j-1].s="--";
map[i][j-1].y=15;
}
if(rand()%2==0){
map[i-1][j].s="--";
map[i-1][j].y=15;
}
}else if(p==0){
map[i][j].s="..";
map[i][j].y=20;
if(rand()%2==0){
map[i][j+1].s="..";
map[i][j+1].y=20;
}
}
}
}
}
for(int i=80;i<=160;i++){
if(map[i][200].s!=" "){
pl.x=i;
break;
}
}
pl.y=200;
return;
}
void water(){
for(int j=1;j<=1000;j++){
for(int i=1;i<=200;i++){
if(map[i][j].s=="ss"){
if(map[i+1][j].s==" "){
map[i+1][j].s="ss";
}
if(map[i][j-1].s==" "){
map[i][j-1].s="ss";
}
if(map[i][j+1].s==" "){
map[i][j+1].s="ss";
}
}
}
}
return;
}
int blood=10,Q=10;
void out(int i1,int i2,int j1,int j2){
for(int i=i1;i<=i2;i++){
for(int j=j1;j<=j2;j++){
if(map[i][j].s==" ")setColor(955);
if(map[i][j].s=="##")setColor(904);
if(map[i][j].s=="&&")setColor(870);
if(map[i][j].s=="ss"||map[i][j].s=="ss")setColor(17 );
if(map[i][j].s=="tr")setColor(238);
if(map[i][j].s=="lf")setColor(802);
if(map[i][j].s=="++")setColor(896);
if(map[i][j].s=="--")setColor(910);
if(map[i][j].s=="..")setColor(907);
if(i==pl.x&&j==pl.y){
setColor(946);
cout<<"Yo";
continue;
}
cout<<map[i][j].s;
setColor(0);
}
cout<<endl;
}
return;
}
void game(){
int cnt=0,fl1,fl2=0,tim=0,fl3=1,fl4=pl.x;
while(true){
cnt++;
Sleep(5);
water();
gotoxy(0,0);
setColor(7);
cout<<"x:"<<pl.x<<" "<<"y:"<<pl.y<<endl;
setColor(10);
for(int i=1;i<=10;i++){
if(i<=blood)cout<<"|";
else cout<<" ";
}
setColor(9);
cout<<endl;
for(int i=1;i<=10;i++){
if(i<=Q)cout<<"O";
else cout<<" ";
}
setColor(7);
cout<<endl;
out(pl.x-10,pl.x+10,pl.y-20,pl.y+20);
if(fl2!=0)tim--;
if(tim==0){
if(fl2==1){
for(int i=1;i<=7;i++){
if(bb[i]==map[pl.x-1][pl.y].s){
b1[i]++;
}
}
map[pl.x-1][pl.y].s=" ";
}
if(fl2==2){
for(int i=1;i<=7;i++){
if(bb[i]==map[pl.x+1][pl.y].s){
b1[i]++;
}
}
map[pl.x+1][pl.y].s=" ";
}
if(fl2==3){
for(int i=1;i<=7;i++){
if(bb[i]==map[pl.x][pl.y-1].s){
b1[i]++;
}
}
map[pl.x][pl.y-1].s=" ";
}
if(fl2==4){
for(int i=1;i<=7;i++){
if(bb[i]==map[pl.x][pl.y+1].s){
b1[i]++;
}
}
map[pl.x][pl.y+1].s=" ";
}
fl2=0;
tim=0;
}
if(map[pl.x+1][pl.y].s!=" "){
if(pl.x>fl4+3){
blood-=(pl.x-fl4-3)/2;
}
fl4=pl.x;
}
if(Q==0&&cnt%5==0&&blood>0)blood--;
if(cnt%20==0&&blood<10)blood++;
if(blood<=0){
system("cls");
setColor(7);
cout<<"Game Over!!!";
return;
}
if(cnt%5==0&&Q<10&&map[pl.x][pl.y].s!="ss")Q++;
if(map[pl.x][pl.y].s=="ss"&&Q>0&&cnt%10==0)Q--;
if(map[pl.x+1][pl.y].s==" "||map[pl.x+1][pl.y].s=="ss"&&(cnt-fl1)%3==0)pl.x++;
if(k('W')&&pl.x>10 &&map[pl.x+1][pl.y].s!=" "){
if(map[pl.x-1][pl.y].s==" "||map[pl.x-1][pl.y].s=="ss"){
fl2=0;
if(map[pl.x-1][pl.y].s==" "&&cnt>=fl1+5){
fl1=cnt;
pl.x-=2;
}else if(map[pl.x-1][pl.y].s=="ss")pl.x-=2;
}else{
if(fl2==0)tim=map[pl.x-1][pl.y].y;
fl2=1;
}
}
if(k('S')&&pl.x<180){
if(map[pl.x+1][pl.y].s==" "||map[pl.x+1][pl.y].s=="ss"){
pl.x++;
fl2=0;
}else{
if(fl2==0)tim=map[pl.x+1][pl.y].y;
fl2=2;
}
}
if(k('A')&&pl.y>10){
if(map[pl.x][pl.y-1].s==" "||map[pl.x][pl.y-1].s=="ss"){
pl.y--;
fl2=0;
}else{
if(fl2==0)tim=map[pl.x][pl.y-1].y;
fl2=3;
}
}
if(k('D')&&pl.y<980){
if(map[pl.x][pl.y+1].s==" "||map[pl.x][pl.y+1].s=="ss"){
pl.y++;
fl2=0;
}else{
if(fl2==0)tim=map[pl.x][pl.y+1].y;
fl2=4;
}
}
if(k('K')){//指令
setColor(7);
cout<<endl<<"请输入指令:";
string s;
cin>>s;
if(s=="tp"){
int xx,yy;
cin>>xx>>yy;
pl.x=xx;
pl.y=yy;
}
if(s=="setblock"){
int xx,yy;
string s;
cin>>xx>>yy>>s;
map[xx][yy].s=s;
}
if(s=="fill"){
int x1,y1,x2,y2;
string s;
cin>>x1>>y1>>x2>>y2;
cin>>s;
if(s=="kk")s=" ";
for(int i=x1;i<=x2;i++){
for(int j=y1;j<=y2;j++){
map[i][j].s=s;
for(int k=1;k<=7;k++){
if(bb[k]==s)map[i][j].y=b1[k];
}
}
}
}
system("cls");
}
if(k('E')){//背包
system("cls");
for(int i=1;i<=7;i++){
if(bb[i]=="##")setColor(904);
if(bb[i]=="&&")setColor(870);
if(bb[i]=="tr")setColor(238);
if(bb[i]=="lf")setColor(802);
if(bb[i]=="++")setColor(896);
if(bb[i]=="--")setColor(910);
if(bb[i]=="..")setColor(907);
cout<<bb[i];
setColor(7);
cout<<" *"<<b1[i]<<endl<<endl;
}
Sleep(1000);
}
if(k('Q')&&b1[fl3]!=0){
b1[fl3]--;
map[pl.x+1][pl.y].s=bb[fl3];
map[pl.x+1][pl.y].y=ph[fl3];
}
if(k('1')){
fl3=1;
}
if(k('2')){
fl3=2;
}
if(k('3')){
fl3=3;
}
if(k('4')){
fl3=4;
}
if(k('5')){
fl3=5;
}
if(k('6')){
fl3=6;
}
if(k('7')){
fl3=7;
}
}
}
int main(){
int a;
cin>>a;
while(a--)rand();
csh();
game();
return 0;
}
1.移动与放置
按动w s a d移动/破坏,按q往脚下垫方块
2.状态栏:
第一行是血条,第二行使氧气,别从高处摔下来/再水里呆太久就不会去世
3.指令:
目前有3条指令:
1.tp x y 传送到x,y处
2.setblock x y block 在x,y处放置block
3.fill x1 y1 x2 y2 block 在从x1,y1到x2,y2处填充block
4.方块参照:
石头:##
土:&&
水:ss
空气:kk
0
已采纳
void Hide(){
HANDLE hOut;
CONSOLE_CURSOR_INFO curInfo;
hOut=GetStdHandle(STD_OUTPUT_HANDLE);
curInfo.dwSize=1;
curInfo.bVisible=0;
SetConsoleCursorInfo(hOut,&curInfo);
}
加入此段代码,在main函数里调用可以隐藏光标
0
0
0
0
0