//转自:https://www.luogu.com.cn/blog/I-am-your-dad/xiao-you-hu-21-lian-lian-kan-you-hu
#include <iostream>
#include <windows.h>
#include <cstdio>
#include <conio.h>
#include <cstring>
using namespace std;
void block(int x,int y){
HANDLE hCon;
hCon = GetStdHandle(STD_OUTPUT_HANDLE);
COORD setps;
setps.X = x;
setps.Y = y;
SetConsoleCursorPosition(hCon,setps);
}
void color(int a){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
}
void HideCursor(){
CONSOLE_CURSOR_INFO cursor_info = {1, 0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
int mo = 0, n = 0, zx = 1, zy = 1, zz = 0, z1 = 1, m = 0;
int dis[4][2] = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
int co[10] = {0, 12, 14, 11, 10, 13};
int ca[10][10];
int a[10][10];
bool yin[10];
int guan[20][15] = {{0},
{4, 1, 5, 2, 5, 2, 3, 2, 4},
{5, 1, 5, 2, 4, 3, 2, 4, 2},
{3, 1, 4, 4, 2, 3, 3},
{5, 1, 3, 2, 5, 3, 5},
{3, 1, 1, 1, 1, 1, 3},
{5, 1, 5, 2, 4, 3, 3},
{4, 1, 2, 4, 3, 1, 4, 1, 1},
{5, 2, 3, 2, 5, 1, 3, 3, 5},
{4, 1, 4, 5, 3, 5, 3, 1, 3},
{5, 1, 3, 1, 4, 5, 3, 5, 2}
};
void mem(){
n = 0; zx = 1; zy = 1; zz = 0; z1 = 1; m = 0;
memset(a, 0, sizeof(a));
memset(a, 0, sizeof(ca));
}
bool in(int x, int y){
return 0 < x && x <= n && 0 < y && y <= n;
}
bool zou(int zi, int zj, int zti, int ztj){
for(int i = 0; i < 4; i++){
int zzx = zi + dis[i][0];
int zzy = zj + dis[i][1];
if(in(zzx, zzy)){
if(a[zzx][zzy] == a[zti][ztj] && !(zzx == zti && zzy == ztj)){
return true;
}else{
if(a[zi][zj] < 99){
if(a[zzx][zzy] == a[zi][zj] * 100 + 1){
if(zou(zzx, zzy, zti, ztj)){
return true;
}
}
}else{
if(a[zzx][zzy] == a[zi][zj] + 1){
if(zou(zzx, zzy, zti, ztj)){
return true;
}
}
}
}
}
}
return false;
}
bool ying(){
for(int i = 1; i <= m; i++){
yin[i] = false;
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(a[i][j] == 0){
return false;
}else if(a[i][j] < 99){
if(zou(i, j, i, j)){
yin[a[i][j]] = true;
}
}
}
}
for(int i = 1; i <= m; i++){
if(yin[i] == false){
return false;
}
}
return true;
}
void nuo(){
if(zz > 0){
if(z1 == 1){
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(a[i][j] / 100 == zz){
a[i][j] = 0;
}
}
}
}
if(a[zx][zy] > 99){
if(a[zx][zy] / 100 == zz){
int z2 = a[zx][zy] % 100;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(a[i][j] / 100 == a[zx][zy] / 100 && a[i][j] % 100 > z2){
a[i][j] = 0;
}
}
}
z1 = z2 + 1;
}else{
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(a[i][j] / 100 == a[zx][zy] / 100 && !(i == zx && j == zy)){
a[i][j] = 0;
}
}
}
a[zx][zy] = zz * 100 + z1;
z1++;
}
}else if(a[zx][zy] > 0){
z1 = 1;
zz = 0;
}else{
a[zx][zy] = zz * 100 + z1;
z1++;
}
}
}
void output(){
block(0, 0);
color(15);
cout << "当前状态:";
if(zz == 0){
cout << "松开";
}else{
cout << "按下";
}
if(mo == 1){
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(a[i][j] != ca[i][j] || zx == i && zy == j){
block(j * 2, i + 1);
if(a[i][j] > 99){
if(zx == i && zy == j){
color(co[a[i][j] / 100] * 16 + 15);
if(zz > 0){
cout << "┼";
}else{
int z1z = 0, z2z = 0;
for(int k = 0; k < 4; k++){
int zzi = i + dis[k][0];
int zzj = j + dis[k][1];
if(in(zzi, zzj)){
if(a[zzi][zzj] == a[i][j] + 1){
z1z = k + 1;
break;
}
}
}
p1:if(z1z == 0){
for(int k = 0; k < 4; k++){
int zzi = i + dis[k][0];
int zzj = j + dis[k][1];
if(in(zzi, zzj)){
if(a[zzi][zzj] == a[i][j] / 100){
z1z = k + 1;
break;
}
}
}
if(z1z == 0){
cout << "┼";
}else{
goto p1;
}
}else{
for(int k = 0; k < 4; k++){
int zzi = i + dis[k][0];
int zzj = j + dis[k][1];
if(in(zzi, zzj)){
if(a[zzi][zzj] == a[i][j] - 1){
z2z = k + 1;
break;
}
}
}
if(z2z == 0){
for(int k = 0; k < 4; k++){
int zzi = i + dis[k][0];
int zzj = j + dis[k][1];
if(in(zzi, zzj)){
if(a[zzi][zzj] == a[i][j] / 100){
z2z = k + 1;
break;
}
}
}
}
if(z1z == 1){
if(z2z == 2){cout << "┌";}else if(z2z == 3){cout << "└";}else if(z2z == 4){cout << "─";}
}else if(z1z == 2){
if(z2z == 1){cout << "┌";}else if(z2z == 3){cout << "│";}else if(z2z == 4){cout << "┐";}
}else if(z1z == 3){
if(z2z == 1){cout << "└";}else if(z2z == 2){cout << "│";}else if(z2z == 4){cout << "┘";}
}else if(z1z == 4){
if(z2z == 1){cout << "─";}else if(z2z == 2){cout << "┐";}else if(z2z == 3){cout << "┘";}
}
}
}
}else{
color(co[a[i][j] / 100]);
int z1z = 0, z2z = 0;
for(int k = 0; k < 4; k++){
int zzi = i + dis[k][0];
int zzj = j + dis[k][1];
if(in(zzi, zzj)){
if(a[zzi][zzj] == a[i][j] + 1){
z1z = k + 1;
break;
}
}
}
p2:if(z1z == 0){
for(int k = 0; k < 4; k++){
int zzi = i + dis[k][0];
int zzj = j + dis[k][1];
if(in(zzi, zzj)){
if(a[zzi][zzj] == a[i][j] / 100){
z1z = k + 1;
break;
}
}
}
if(z1z == 0){
cout << "┼";
}else{
goto p2;
}
}else{
for(int k = 0; k < 4; k++){
int zzi = i + dis[k][0];
int zzj = j + dis[k][1];
if(in(zzi, zzj)){
if(a[zzi][zzj] == a[i][j] - 1){
z2z = k + 1;
break;
}
}
}
if(z2z == 0){
for(int k = 0; k < 4; k++){
int zzi = i + dis[k][0];
int zzj = j + dis[k][1];
if(in(zzi, zzj)){
if(a[zzi][zzj] == a[i][j] / 100){
z2z = k + 1;
break;
}
}
}
}
if(z1z == 1){
if(z2z == 2){cout << "┌";}else if(z2z == 3){cout << "└";}else if(z2z == 4){cout << "─";}
}else if(z1z == 2){
if(z2z == 1){cout << "┌";}else if(z2z == 3){cout << "│";}else if(z2z == 4){cout << "┐";}
}else if(z1z == 3){
if(z2z == 1){cout << "└";}else if(z2z == 2){cout << "│";}else if(z2z == 4){cout << "┘";}
}else if(z1z == 4){
if(z2z == 1){cout << "─";}else if(z2z == 2){cout << "┐";}else if(z2z == 3){cout << "┘";}
}
}
}
}else if(a[i][j] > 0){
if(zx == i && zy == j){
color(co[a[i][j]] * 16 + 15);
}else{
color(co[a[i][j]]);
}
cout << "■";
}else{
color(15);
if(zx == i && zy == j){
cout << "┼";
}else{
cout << " ";
}
}
}
if(zx == i && zy == j){
ca[i][j] = -1;
}else{
ca[i][j] = a[i][j];
}
}
}
}else{
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(a[i][j] != ca[i][j]){
block(j, i + 1);
if(a[i][j] > 99){
if(zx == i && zy == j){
color(co[a[i][j] / 100] * 16 + 15);
if(zz > 0){
cout << "┼";
}else{
int z1z = 0, z2z = 0;
for(int k = 0; k < 4; k++){
int zzi = i + dis[k][0];
int zzj = j + dis[k][1];
if(in(zzi, zzj)){
if(a[zzi][zzj] == a[i][j] + 1){
z1z = k + 1;
break;
}
}
}
p3:if(z1z == 0){
for(int k = 0; k < 4; k++){
int zzi = i + dis[k][0];
int zzj = j + dis[k][1];
if(in(zzi, zzj)){
if(a[zzi][zzj] == a[i][j] / 100){
z1z = k + 1;
break;
}
}
}
if(z1z == 0){
cout << "┼";
}else{
goto p3;
}
}else{
for(int k = 0; k < 4; k++){
int zzi = i + dis[k][0];
int zzj = j + dis[k][1];
if(in(zzi, zzj)){
if(a[zzi][zzj] == a[i][j] - 1){
z2z = k + 1;
break;
}
}
}
if(z2z == 0){
for(int k = 0; k < 4; k++){
int zzi = i + dis[k][0];
int zzj = j + dis[k][1];
if(in(zzi, zzj)){
if(a[zzi][zzj] == a[i][j] / 100){
z2z = k + 1;
break;
}
}
}
}
if(z1z == 1){
if(z2z == 2){cout << "┌";}else if(z2z == 3){cout << "└";}else if(z2z == 4){cout << "─";}
}else if(z1z == 2){
if(z2z == 1){cout << "┌";}else if(z2z == 3){cout << "│";}else if(z2z == 4){cout << "┐";}
}else if(z1z == 3){
if(z2z == 1){cout << "└";}else if(z2z == 2){cout << "│";}else if(z2z == 4){cout << "┘";}
}else if(z1z == 4){
if(z2z == 1){cout << "─";}else if(z2z == 2){cout << "┐";}else if(z2z == 3){cout << "┘";}
}
}
}
}else{
color(co[a[i][j] / 100]);
int z1z = 0, z2z = 0;
for(int k = 0; k < 4; k++){
int zzi = i + dis[k][0];
int zzj = j + dis[k][1];
if(in(zzi, zzj)){
if(a[zzi][zzj] == a[i][j] + 1){
z1z = k + 1;
break;
}
}
}
p4:if(z1z == 0){
for(int k = 0; k < 4; k++){
int zzi = i + dis[k][0];
int zzj = j + dis[k][1];
if(in(zzi, zzj)){
if(a[zzi][zzj] == a[i][j] / 100){
z1z = k + 1;
break;
}
}
}
if(z1z == 0){
cout << "┼";
}else{
goto p4;
}
}else{
for(int k = 0; k < 4; k++){
int zzi = i + dis[k][0];
int zzj = j + dis[k][1];
if(in(zzi, zzj)){
if(a[zzi][zzj] == a[i][j] - 1){
z2z = k + 1;
break;
}
}
}
if(z2z == 0){
for(int k = 0; k < 4; k++){
int zzi = i + dis[k][0];
int zzj = j + dis[k][1];
if(in(zzi, zzj)){
if(a[zzi][zzj] == a[i][j] / 100){
z2z = k + 1;
break;
}
}
}
}
if(z1z == 1){
if(z2z == 2){cout << "┌";}else if(z2z == 3){cout << "└";}else if(z2z == 4){cout << "─";}
}else if(z1z == 2){
if(z2z == 1){cout << "┌";}else if(z2z == 3){cout << "│";}else if(z2z == 4){cout << "┐";}
}else if(z1z == 3){
if(z2z == 1){cout << "└";}else if(z2z == 2){cout << "│";}else if(z2z == 4){cout << "┘";}
}else if(z1z == 4){
if(z2z == 1){cout << "─";}else if(z2z == 2){cout << "┐";}else if(z2z == 3){cout << "┘";}
}
}
}
}else if(a[i][j] > 0){
if(zx == i && zy == j){
color(co[a[i][j]] * 16 + 15);
}else{
color(co[a[i][j]]);
}
cout << "■";
}else{
color(15);
if(zx == i && zy == j){
cout << "┼";
}else{
cout << " ";
}
}
}
if(zx == i && zy == j){
ca[i][j] = -1;
}else{
ca[i][j] = a[i][j];
}
}
}
}
}
/*void output1(){
block(0, 7);
for(int i = 1; i <= n; i++){
cout << " ";
cout << endl;
}
block(0, 7);
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
cout << a[i][j] << " ";
}
cout << endl;
}
}*/
int main( ){
HideCursor();
color(15 * 16);
system("mode con lines=5 cols=42");
cout << " 欢迎来到*杨柳白皮*的连连看!" << endl;
Sleep(500);
cout << " F键打开个人主页" << endl << " ";
char zzz1 = getch();
if(zzz1 == 'F' || zzz1 == 'f'){
system("start https://www.luogu.com.cn/user/359425");
}
Sleep(500);
system("pause");
system("cls");
Sleep(200);
cout << " 请选择合适的输出格式——" << endl;
Sleep(750);
cout << " 1.高配版-1" << endl;
Sleep(200);
cout << " 2.高配版-2" << endl;
Sleep(200);
p_1:char zzz2 = getch();
if(zzz2 >= '1' && zzz2 <= '2'){
mo = zzz2 - '0';
}else{
goto p_1;
}
cout << zzz2;
p_3:Sleep(500);
mem();
color(15);
system("mode con cols=25 lines=10");
Sleep(500);
cout << "游戏开始!" << endl;
Sleep(750);
cout << "请选择关卡(1~5):";
p_2:char zzz3 = getch();
if(zzz3 >= '1' && zzz3 <= '5'){
cout << zzz3 << endl;
Sleep(500);
}else{
goto p_2;
}
int zzz4 = zzz3 - '0';
cout << "加载中";Sleep(200);cout << "▁";Sleep(200);cout << "▂";Sleep(200);cout << "▃";Sleep(200);cout << "▅";Sleep(200);cout << "▆";Sleep(200);cout << "▇";
Sleep(750);
m = guan[zzz4 * 2 - 1][0];
for(int i = 1; i <= guan[zzz4 * 2 - 1][0]; i++){
a[guan[zzz4 * 2 - 1][i * 2 - 1]][guan[zzz4 * 2][i * 2 - 1]] = i;
a[guan[zzz4 * 2 - 1][i * 2]][guan[zzz4 * 2][i * 2]] = i;
}
n = guan[zzz4 * 2][0];
cout << endl << "加载成功!";
Sleep(250);
system("cls");
while(true){
output();
//output1();
if(ying()){
break;
}
char zz1 = getch();
if(zz1 == 'w'){
if(in(zx - 1, zy)){
zx--;
}
nuo();
}else if(zz1 == 's'){
if(in(zx + 1, zy)){
zx++;
}
nuo();
}else if(zz1 == 'a'){
if(in(zx, zy - 1)){
zy--;
}
nuo();
}else if(zz1 == 'd'){
if(in(zx, zy + 1)){
zy++;
}
nuo();
}else if(zz1 == ' '){
if(a[zx][zy] > 0 && a[zx][zy] <= 9){
if(zz == 0){
z1 = 1;
zz = a[zx][zy];
}else{
zz = 0;
}
}else if(a[zx][zy] > 99){
if(zz == 0){
z1 = a[zx][zy] % 100 + 1;
zz = a[zx][zy] / 100;
}else{
zz = 0;
}
}
}
Sleep(20);
}
color(15);
Sleep(750);
system("cls");
block(0, 0);
cout << "第" << zzz3 << "关挑战成功!" << endl;
Sleep(1500);
system("pause");
goto p_3;
return 0;
}