解决问题:

初步搭建植此青绿中的地图显示
先是用户的拼图选择,选用文件读取,但仍有问题,拼图不够显眼。
可在可视化部分做成按钮
接下来可为拼图排除已选,即已选的会显示已选,再选会报错,提示选择其他或着直接不显示该图。意味着要在输出时再插一个循环检索
设计分块显示
如上,维护两个数组,一个记录长度,一个记录该拼图是否被选,后期回溯功能实现时开类的数组就行了
接下来设计地图
✖▼●▼■✖✖▼■▼▼●■✖■▼●✖▼▼●✖▼■▼●■✖✖▼■✖▼●●
乱码出现
以上符号均不可打出
故用!代替▼,O代替●,X代替✖,*表示■。
写出空白做题板后将其与当前地图,放置拼图序号,可选择性结合为一种地图
其中,左上角为信号格,左下角为数目数量格,右上角为拼图编号图,右下角为目标图像。
按设计可实现显示x-y的刻度,但以目前的图来说有些复杂,提示下让用户自己看吧,实现的部分或许可以放在可视化里?总之这个功能之后再说

    ……
case 1:
for(int i=0;i<18;i++)
{
if(i%6!=5||i%6!=4||i%6!=3)
notice_map[i]='*';
else notice_map[i]='0';
}
break;
default:
cout<<"不存在这种选项"<<endl;
}

本来想在结尾加上判断,但是不好实现重新生成激活信号的方法,故将在传入前就判断。
根据x,y对数组赋值有些问题,

now_map[y*6+x]++

从0还是从1 开始会使结果出问题.
(懒得贴图片了,放下结果和代码吧

输出结果

读取关卡
- - - - - - - - -

| ! * O X O ! |
| ! * O X O ! |
| ! * O X O ! |
| ! * O X O ! |
| ! * O X O ! |
| ! * O X O ! |
- - - - - - - - -
打印地图
- - - - - - - - - - - - - - - - - - -
| 0 0 | 0 0 | 0 0 | 0 0 | 0 0 | 0 0 |
| 0 ! | 0 * | 0 O | 0 X | 0 O | 0 ! |
- - - - - - - - - - - - - - - - - -
| 0 0 | 0 0 | 0 0 | 0 0 | 0 0 | 0 0 |
| 0 ! | 0 * | 0 O | 0 X | 0 O | 0 ! |
- - - - - - - - - - - - - - - - - - -
| 0 0 | 0 0 | 0 0 | 0 0 | 0 0 | 0 0 |
| 0 ! | 0 * | 0 O | 0 X | 0 O | 0 ! |
- - - - - - - - - - - - - - - - - -
| 0 0 | 0 0 | 0 0 | 0 0 | 0 0 | 0 0 |
| 0 ! | 0 * | 0 O | 0 X | 0 O | 0 ! |
- - - - - - - - - - - - - - - - - - -
| 0 0 | 0 0 | 0 0 | 0 0 | 0 0 | 0 0 |
| 0 ! | 0 * | 0 O | 0 X | 0 O | 0 ! |
- - - - - - - - - - - - - - - - - -
| 0 0 | 0 0 | 0 0 | 0 0 | 0 0 | 0 0 |
| 0 ! | 0 * | 0 O | 0 X | 0 O | 0 ! |
- - - - - - - - - - - - - - - - - -
打印拼图
---------------------------------------------------------------
* 1 * 2 * 3 * 4 * 5 * 6 * 7
* **** * *** * *** * ** * ** * *
* **** * *** * *** * ** * ** * * * *
* **** * *** * *** * * * *
---------------------------------------------------------------
开始做答吧
打印拼图
---------------------------------------------------------------
* 1 * 2 * 3 * 4 * 5 * 6 * 7
* **** * *** * *** * ** * ** * *
* **** * *** * *** * ** * ** * * * *
* **** * *** * *** * * * *
---------------------------------------------------------------
那么,在这第1次放置,你要选择哪个拼图?

2
- - - - - - - - - - - - - - - - - - -
| * 0 | * 0 | * 0 | * 0 | * 0 | * 0 |
| 0 ! | 0 * | 0 O | 0 X | 0 O | 0 ! |
- - - - - - - - - - - - - - - - - -
| * 0 | * 0 | * 0 | * 0 | * 0 | * 0 |
| 0 ! | 0 * | 0 O | 0 X | 0 O | 0 ! |
- - - - - - - - - - - - - - - - - - -
| * 0 | * 0 | * 0 | * 0 | * 0 | * 0 |
| 0 ! | 0 * | 0 O | 0 X | 0 O | 0 ! |
- - - - - - - - - - - - - - - - - -
| * 0 | * 0 | * 0 | * 0 | * 0 | * 0 |
| 0 ! | 0 * | 0 O | 0 X | 0 O | 0 ! |
- - - - - - - - - - - - - - - - - - -
| 0 0 | 0 0 | 0 0 | 0 0 | 0 0 | 0 0 |
| 0 ! | 0 * | 0 O | 0 X | 0 O | 0 ! |
- - - - - - - - - - - - - - - - - -
| 0 0 | 0 0 | 0 0 | 0 0 | 0 0 | 0 0 |
| 0 ! | 0 * | 0 O | 0 X | 0 O | 0 ! |
- - - - - - - - - - - - - - - - - -
注意:请将拼图左上角填入地图块中含*的位置
地图有36个区块,打出每个区块的坐标即可,例如(1,1)表示第一个区块
那么,以x y的形式输入你想要的地区吧
1 1
错误坐标,请重试
1 2
操作完毕,请看图
- - - - - - - - - - - - - - - - - - -
| * 0 | * 0 | * 0 | * 0 | * 0 | * 0 |
| 0 ! | 0 * | 0 O | 0 X | 0 O | 0 ! |
- - - - - - - - - - - - - - - - - -
| * 0 | * 0 | * 0 | * 0 | * 0 | * 0 |
| 1 ! | 1 * | 1 O | 0 X | 0 O | 0 ! |
- - - - - - - - - - - - - - - - - - -
| * 0 | * 0 | * 0 | * 0 | * 0 | * 0 |
| 1 ! | 1 * | 1 O | 0 X | 0 O | 0 ! |
- - - - - - - - - - - - - - - - - -
| * 0 | * 0 | * 0 | * 0 | * 0 | * 0 |
| 1 ! | 1 * | 1 O | 0 X | 0 O | 0 ! |
- - - - - - - - - - - - - - - - - - -
| 0 0 | 0 0 | 0 0 | 0 0 | 0 0 | 0 0 |
| 0 ! | 0 * | 0 O | 0 X | 0 O | 0 ! |
- - - - - - - - - - - - - - - - - -
| 0 0 | 0 0 | 0 0 | 0 0 | 0 0 | 0 0 |
| 0 ! | 0 * | 0 O | 0 X | 0 O | 0 ! |
- - - - - - - - - - - - - - - - - -
打印拼图
-----------------------------------------------------
* 1 * 3 * 4 * 5 * 6 * 7
* **** * *** * ** * ** * *
* **** * *** * ** * ** * * * *
* **** * *** * * * *
-----------------------------------------------------
那么,在这第2次放置,你要选择哪个拼图?

代码

#include <iostream>
#include "Plant.h"
#include <fstream>
using namespace std;
map::map() // 构造,开自定义数组
{
ifstream ifs;
ifs.open("original.txt", ios::in);
if (ifs.is_open())
{
for (int i = 0; i <= 35; i++)
{
ifs >> Level_map[0]; // 读取每行,确保不超出数组的范围
}
ifs.close();
}
ifs.close();
cout << "读取关卡" << endl;
for (int i = 0; i < 36; i++)
{
if (i == 0)
cout << "- - - - - - - - -" << endl;
if (i % 6 == 0)
cout << "| ";
cout << Level_map[0][i] << " ";
if (i % 6 == 5)
cout << " |" << endl;
}
cout << "- - - - - - - - -" << endl;
for (int i = 0; i < 36; i++)
{
now_map[i] = 0;
} // 初始化做题板
for (int i = 0; i < 36; i++)
{
choice_map[i] = '0';
} // 初始化可放入拼图的信号的图
for (int i = 0; i < 36; i++)
{
notice_map[i] = '0';
} // 初始化记录放入拼图的图
}; // 输入流读取文件
map::~map(){};
void map::mapread()
{
ifstream ifs;
ifs.open("original.txt", ios::in);
if (ifs.is_open())
{
for (int i = 0; i < 6; i++)
for (int j = 0; j < 36; j++)
ifs >> Level_map[i][j];
}
ifs.close();
}
void map::showmap(int a)
{
for (int i = a - 1, j = 0; j < 6; j++) // 从0开始算
{
cout << Level_map[i][j] << " ";
}
cout << endl;
}
choice &map::re_choice()
{
return choice;
}
void map::showuse()
{
for (int i = 0; i < 36; i++)
{
if (i == 0)
cout << "- - - - - - - - -" << endl;
if (i % 6 == 0)
cout << "| ";
cout << now_map[i] << " ";
if (i % 6 == 5)
cout << " |" << endl;
}
cout << "- - - - - - - - -" << endl;
}
void map::delemap()
{
for (int i = 0; i < 36; i++)
{
notice_map[i] = '0';
} // 初始化记录放入拼图的图
}
void map::showall(int a)
{
for (int i = 0; i < 6; i++) // 打印行数
{
if (i % 2 == 0)
{
cout << "- - - - - - - - - - - - - - - - - - -" << endl;
}
else if (i % 2 == 1)
cout << "- - - - - - - - - - - - - - - - - -" << endl; // 边框打印
cout << "| ";
for (int j = i * 6; j < i * 6 + 6; j++) // 打印列数
{
cout << notice_map[j] << " " << choice_map[j];
cout << " | ";
}
cout << endl;
cout << "| ";
for (int j = i * 6; j < i * 6 + 6; j++) // 打印列数
{
cout << now_map[j] << " " << Level_map[a][j];
cout << " | ";
}
cout << endl;
}
cout << "- - - - - - - - - - - - - - - - - -" << endl; // 边框打印
}
void map::putnotice(int a)
{
switch (a)
{
case 7:
case 6:
for (int i = 0; i < 36; i++)
notice_map[i] = '*';
break;
case 5:
case 4:
for (int i = 0; i < 30; i++)
{
if (i % 6 != 5)
notice_map[i] = '*';
else
notice_map[i] = '0';
}
break;
case 3:
case 2:
for (int i = 0; i < 24; i++)
{
if (i % 6 != 5 || i % 6 != 4)
notice_map[i] = '*';
else
notice_map[i] = '0';
}
break;
case 1:
for (int i = 0; i < 18; i++)
{
if (i % 6 != 5 || i % 6 != 4 || i % 6 != 3)
notice_map[i] = '*';
else
notice_map[i] = '0';
}
break;
}
}
void map::revise(int x, int y, int n) // 左上角为参考系,赋值要向下衍生
{
switch (n)
{
case 7:
case 6:
now_map[(y - 1) * 6 + (x - 1)]++;
break;
case 5:
case 4:
now_map[(y - 1) * 6 + (x - 1)]++;
now_map[(y - 1) * 6 + (x)]++;
now_map[(y) * 6 + (x - 1)]++;
now_map[(y) * 6 + (x)]++;
break;
case 3:
case 2:
for (int i = 0; i < 3; i++) // 9格有点多,循环吧
{
now_map[(y - 1) * 6 + (x - 1 + i)]++;
now_map[(y) * 6 + (x - 1 + i)]++;
now_map[(y + 1) * 6 + (x - 1 + i)]++;
}
break;
case 1:
for (int i = 0; i < 4; i++) // 16格有点多,循环吧
{
now_map[(y - 1) * 6 + (x - 1 + i)]++;
now_map[(y) * 6 + (x - 1 + i)]++;
now_map[(y + 1) * 6 + (x - 1 + i)]++;
now_map[(y + 2) * 6 + (x - 1 + i)]++;
}
break;
}
}
bool map::check(int x, int y, int n)//判断解
{
switch (n)
{

case 5:
case 4:
if (x % 6 == 5 || y % 6 == 5)
return false;
case 3:
case 2:
if (x % 6 >= 4 || y % 6 >= 4)
return false;
case 1:
if (x % 6 >= 3 || y % 6 >= 4)
return false;
}
return true;
}
void map::work(int n)
{
cout << "打印地图" << endl;
showall(0);
cout << "打印拼图" << endl;
re_choice().openchoice();
cout << "开始做答吧" << endl;
int num = 0;
for (int i = 0; i < 7; i++)
{
cout << "打印拼图" << endl;
re_choice().openchoice();
cout << "那么,在这第" << i + 1 << "次放置,你要选择哪个拼图?" << endl;
cin >> num;
if (num > 8 || num < 1) // 越界判断
{
cout << "没有这么多的拼图,请按图示控制在1~7内" << endl;
cout << "请重新输入" << endl;
cin >> num;
}
re_choice().in_false(num - 1); // 删除已选的拼图
putnotice(num); // 生成信号
showall(0);
int posx = 0; // 记录位置
int posy = 0;
if (i == 0)
{
cout << "注意:请将拼图左上角填入地图块中含*的位置" << endl;
cout << "地图有36个区块,打出每个区块的坐标即可,例如(1,1)表示第一个区块" << endl;
}
cout << "那么,以x y的形式输入你想要的地区吧" << endl;
cin >> posx >> posy;
if(check(posx,posy,num))
{
cout<<"错误坐标,请重试"<<endl;
cin>>posx>>posy;
}
revise(posx,posy,num);
cout<<"操作完毕,请看图"<<endl;
showall(0);
}
}
//-------------------------------------------------------------------------
choice::choice() // 为程序入值
{
ifstream ifs;
ifs.open("solve.txt", ios::in);
if (ifs.is_open())
{
for (int i = 0; i < 6; i++)
{
ifs.getline(puzzle[i], 78); // 读取每行,确保不超出数组的范围
}
ifs.close();
}
else
{
cout << "文件读取失败" << endl;
}
for (int i = 0; i < 7; i++)
choiced[i] = true;
width[0] = 11;
width[1] = 10;
width[2] = 10;
width[3] = 9;
width[4] = 9;
width[5] = 8;
width[6] = 6; // 设置字符数,输出时能决定哪些不输
}
choice::~choice(){};
void choice::openchoice()
{
for (int i = 0; i < 6; i++)
{
int sum = 0;
for (int k = 0; k < 7; k++) // 共七块拼图
{
if (choiced[k] == false)
{
sum += width[k];
} // 跳过,++
else
{
for (int j = 0; j < width[k]; j++)
{ // 使用 '\0' 标志行末尾
cout << puzzle[i][j + sum];
} // 输出
sum += width[k];
}
}
cout << endl;
}
}
void choice::in_false(int a)
{
choiced[a] = false;
}
void choice::in_true(int a)
{
choiced[a] = true;
}

粘贴了cpp中的所有内容,记做$plusmaxultra$-$0.1$