#include <iostream>
#include <string.h>
using namespace std;
struct Level {
int width;
int height;
char wi_ch[20];
char he_ch[20];
char map_ch[20][20];
char target_ch[20][20];
};
Level levels[] = {
{
4, 3,
{' ', 'B','B','B','B'},
{' ', 'A','A','A'},
{
{},
{' ', 'O','O','O','O'},
{' ', 'O','O','O','O'},
{' ', 'O','O','O','O'}
},
{
{},
{' ', 'A','A','A','A'},
{' ', 'A','B','B','A'},
{' ', 'A','A','A','A'}
}
},
{
5, 4,
{' ', 'C','C','C','C','C'},
{' ', 'D','D','D','D'},
{
{},
{' ', 'O','O','O','O','O'},
{' ', 'O','O','O','O','O'},
{' ', 'O','O','O','O','O'},
{' ', 'O','O','O','O','O'}
},
{
{},
{' ', 'D','D','D','D','D'},
{' ', 'D','C','C','C','D'},
{' ', 'D','C','C','C','D'},
{' ', 'D','D','D','D','D'}
}
},
{
3, 3,
{' ', 'X','X','X'},
{' ', 'Y','Y','Y'},
{
{},
{' ', 'O','O','O'},
{' ', 'O','O','O'},
{' ', 'O','O','O'}
},
{
{},
{' ', 'Y','Y','Y'},
{' ', 'Y','X','Y'},
{' ', 'Y','Y','Y'}
}
}
};
int width, height;
char wi_ch[20], he_ch[20], target_ch[20][20], map_ch[20][20];
bool check_win();
bool check_string(string s, int low, int upp);
void print_target();
void print_map();
void copy_arr(char a[], char b[], int l);
int main() {
string c;
int n, step = 0, level = 0;
bool wrong_inp = 0, is_win = 0;
width = levels[level].width;
height = levels[level].height;
copy_arr(wi_ch,levels[level].wi_ch, width);
copy_arr(he_ch,levels[level].he_ch, height);
for (int i = 1;i <= height;i++) {
for (int j = 1;j <= width;j++) {
map_ch[i][j] = levels[level].map_ch[i][j];
}
}
for (int i = 1;i <= height;i++) {
for (int j = 1;j <= width;j++) {
target_ch[i][j] = levels[level].target_ch[i][j];
}
}
while (step <= 1000) {
if (level+1 >= sizeof(levels)/sizeof(Level)) {
is_win = 1;
break;
}
system("clear");
if (wrong_inp == 1) {
cout << "请输入图中对应标出的行列哦" << endl;
wrong_inp = 0;
}
print_target();
print_map();
cout << "第 " << level + 1 << " 幅画作" << endl;
if (check_win()) {
cout << "恭喜您用"<<step<<"步完成了画作"<<endl;
cout << "任意字符加回车键开启下一幅画作...";
cin >> c;
level++;
width = levels[level].width;
height = levels[level].height;
copy_arr(wi_ch,levels[level].wi_ch, width);
copy_arr(he_ch,levels[level].he_ch, height);
for (int i = 1;i <= height;i++) {
for (int j = 1;j <= width;j++) {
map_ch[i][j] = levels[level].map_ch[i][j];
}
}
for (int i = 1;i <= height;i++) {
for (int j = 1;j <= width;j++) {
target_ch[i][j] = levels[level].target_ch[i][j];
}
}
step = 0;
continue;
}
cout << "输入你要涂刷的行列值(输入0退出):";
cin >> c;
if (c == "0") {
break;
}
if (!check_string(c, height+width)) {
wrong_inp = 1;
continue;
}
step++;
n = c - '0';
if (1 <= n && n <= height) {
for (int i = 1; i <= width; i++) {
map_ch[n][i] = he_ch[n];
}
} else {
for (int i = 1; i <= height; i++) {
map_ch[i][n - height] = wi_ch[n - height];
}
}
}
if (is_win) {
cout << "恭喜您完成所有画作" << endl;
}
else {
cout << "再接再厉,你已经完成了" <<level<<"幅画作"<< endl;
}
cout << "任意字符加回车键结束...";
cin >> c;
return 0;
}
bool check_win() {
for (int h = 1; h <= height; h++) {
for (int w = 1; w <= width; w++) {
if (map_ch[h][w] != target_ch[h][w]) {
return false;
}
}
}
return true;
}
#include <string>
#include <sstream>
#include <limits>
using namespace std;
bool check_string(const string& s, int low, int upp) {
istringstream iss(s);
int num;
iss >> num;
if (iss.fail() || !iss.eof()) {
return false;
}
return (num >= low && num <= upp);
}
void print_target() {
cout << "目标画作:" << endl;
for (int h = 1; h <= height; h++) {
for (int w = 1; w <= width; w++) {
cout << target_ch[h][w];
}
cout << endl;
}
}
void print_map() {
cout << "您的画作:" << endl;
for (int h = 1; h <= height; h++) {
for (int w = 1; w <= width; w++) {
if (w == 1)
cout << he_ch[h] << h << " ";
cout << map_ch[h][w];
}
cout << endl;
}
cout << " ";
for (int i = 1; i <= width; i++) {
cout << i + height;
}
cout << endl << " ";
for (int i = 1; i <= width; i++) {
cout << wi_ch[i];
}
cout << endl;
}
void copy_arr(char a[], char b[], int l) {
for (int i = 1;i <= l;i++) {
a[i] = b[i];
}
}