- C20250020's blog
五行下落
- 2023-11-26 22:27:40 @
规则:按照五行相生相克关系,如果A生B,A克C,那么2个A叠在一起会变成B,A和C叠在一起会让C消失。AAA在同一横排中,则左右2边A消失,中间A升级。升级后的棋子和原来的属性相同,升级棋子死亡时,出现爆炸,周围3x3格子棋子消失。一列堆满判负。a左s右x落子。目前棋盘 1x5,h是宽度,l是高度。
#include<cstdio>
#include<iostream>
#include<queue>
#include<ctime>
#include<algorithm>
#include<string>
#include "windows.h"
using namespace std;
int a[10][10];
//1金2水3木4火5土101鑫102淼103森104焱105垚ins'--'
//SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);;
const int ins = -10004,h = 5,l = 1;
void gravity(int aa,int b,int c){
for(int i = 1;i <= aa;i++)
for(int j = b;j <= c;j++)
if(a[i][j] == ins){
a[i][j] = a[i- 1][j];
a[i - 1][j] = ins;
}
}
void py(int ys){
if(ys == 1){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN );;
printf("金");
return;
}
if(ys == 2){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE );;
printf("水");
return;
}
if(ys == 3){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN );;
printf("木");
return;
}
if(ys == 4){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED );;
printf("火");
return;
}
if(ys == 5){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY );;
printf("土");
return;
}
if(ys == 101){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN );;
printf("鑫");
return;
}
if(ys == 102){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE );;
printf("淼");
return;
}
if(ys == 103){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN );;
printf("森");
return;
}
if(ys == 104){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED );;
printf("焱");
return;
}
if(ys == 105){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY );;
printf("垚");
return;
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED );;
if(ys == 0){
printf("万");
return;
}
printf("--");
return;
}
void show(){
for(int i = 0;i <= l;i++){
for(int j = 1;j <= h;j++){
py(a[i][j]);
printf(" ");
}
printf("\n");
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED );;
}
void fy(int i,int j){
if(i > l) return;
if(j > h) return;
if(j <= h - 2 && a[i][j] == a[i][j + 1] && a[i][j + 2] == a[i][j] && a[i][j] < 6 && a[i][j] > 0){
a[i][j + 1] = a[i][j] + 100;
a[i][j] = a[i][j + 2] = ins;
gravity(i,j,j + 2);
printf("(%d,%d),(%d,%d),(%d,%d)发生了压缩反应。\n",i,j,i,j + 1,i,j + 2);
fy(0,1);
return;
}
bool flag = false;
if(a[i][j] % 5 == a[i - 1][j] % 5 && i >= 1 && a[i][j] > 0){
flag = (a[i][j] >= 100) || (a[i - 1][j] >= 100);
a[i - 1][j] = ins;
a[i][j] = a[i][j] % 5 + 1;
gravity(i,j,j);
printf("(%d,%d),(%d,%d)发生了相生反应。\n",i - 1,j,i,j);
if(flag){
int aaa = a[i][j];
for(int k = i - 1;k <= i + 1;k++)
for(int l = j - 1;l <= j + 1;l++)
a[k][l] = ins;
a[i][j] = aaa;
printf("(%d,%d)发生了爆炸反应。\n",i,j);
gravity(i - 1,j - 1,j + 1);
fy(0,1);
return;
}
fy(0,1);
}
if(a[i][j] % 5 == (a[i - 1][j] + 2) % 5 && i >= 1 && a[i][j] > 0){
flag = (a[i][j] >= 100);
a[i][j] = a[i - 1][j];
a[i - 1][j] = ins;
gravity(i,j,j);
printf("(%d,%d),(%d,%d)发生了相克反应。\n",i - 1,j,i,j);
if(flag){
int aaa = a[i][j];
for(int k = i - 1;k <= i + 1;k++)
for(int l = j - 1;l <= j + 1;l++)
a[k][l] = ins;
a[i][j] = aaa;
printf("(%d,%d)发生了爆炸反应。\n",i,j);
gravity(i - 1,j - 1,j + 1);
fy(0,1);
return;
}
fy(0,1);
}
if(i == l && j == h) return;
if(j < h) fy(i,j + 1);
fy(i + 1,1);
}
int main(){
srand(time(NULL));
int cnt = 0;
for(int i = 0;i <= 6;i++)
for(int j = 0;j <= 6;j++)
a[i][j] = ins;
string s;
while(true){
// show();
cnt++;
printf("第%d步:\n",cnt);int xxx = rand() % 102 - 1;
if(xxx == 0) xxx = rand() % 5 + 101;
else xxx = xxx % 5 + 1;
a[0][1] = xxx;
char c = 'a';
int cc = 1;
while(c != 'x'){
show();
cin >> s;
c = s[0];
a[0][cc] = ins;
if(c == 'a' && cc > 1) cc--;
if(c == 's' && cc < h) cc++;
a[0][cc] = xxx;
}
gravity(l,1,h);
show();
for(int i = 0;i <= l;i++)
for(int j = 1;j <= h;j++)
if(a[i][j] == 0){
printf("请问你要将万能卡变为什么?\n");
for(int k = 1;k <= 5;k++){
printf("%d.",k);
py(k);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED );;
printf(" ");
}
printf("\n");
int nn;
scanf("%d",&nn);
if(nn > 0 && nn < 6) a[i][j] = nn;
else return 0;
break;
}
fy(0,1);
if(a[0][1] + a[0][2] + a[0][3] + a[0][4] + a[0][5] != 5 * ins){
printf("你输了,最终步数:%d\n",cnt);
break;
}
}
return 0;
}