math.io
#include <bits/stdc++.h>
#include <windows.h>
#include <stdio.h>
#include <fstream>
#include <conio.h>
#include <time.h>
using namespace std;
inline void HideCursor() {
CONSOLE_CURSOR_INFO cursor_info = {1, 0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
inline void ShowCursor() {
CONSOLE_CURSOR_INFO cursor_info = {1, 1};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
inline void SetPos(int x, int y) {
COORD pos;
pos.X = y * 2, pos.Y = x;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
inline void aa_print(string s) {
int len = s.size();
for (int i = 0; i < len; i++) {
cout << s[i];
Sleep(20);
}
return;
}
inline void Color(int a) {
if (a == 0) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
if (a == 1) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 11);
if (a == 2) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
if (a == 3) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 5);
if (a == 4) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 4);
if (a == 5) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 9);
if (a == 6) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);
if (a == 7) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 8);
if (a == 8) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
if (a == 9) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 13);
if (a == 10) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
if (a == 11) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 1);
}//白蓝绿紫红靛黄 深灰 浅灰 粉
bool c[100];
/*
c[1] 0
c[2] 1
c[3] 2
c[4] 3
c[5] 4
c[6] 5
c[7] +
*/
int len = 50;
bool is_craft3;//有没有三元合成台
pair <pair <int, int>, int> c2[100005] = {
{{0, 0}, 0},
{{1, 1}, 7},//0 0 -> +
{{2, 2}, 7} //1 1 -> +
};
int c2_len = 2;
pair <pair <int, int>, pair <int, int> > c3[100005] = {
{{0, 0}, {0, 0}},
{{1, 7}, {1, 1}},//0 + 0 -> 0
{{1, 7}, {2, 2}},//0 + 1 -> 1
{{1, 7}, {3, 3}},//0 + 2 -> 2
{{1, 7}, {4, 4}},//0 + 3 -> 3
{{1, 7}, {5, 5}},//0 + 4 -> 4
{{1, 7}, {6, 6}},//0 + 5 -> 5
{{2, 7}, {1, 2}},//1 + 0 -> 1
{{2, 7}, {2, 3}},//1 + 1 -> 2
{{2, 7}, {3, 4}},//1 + 2 -> 3
{{2, 7}, {4, 5}},//1 + 3 -> 4
{{2, 7}, {5, 6}},//1 + 4 -> 5
{{3, 7}, {1, 3}},//2 + 0 -> 2
{{3, 7}, {2, 4}},//2 + 1 -> 3
{{3, 7}, {3, 5}},//2 + 2 -> 4
{{3, 7}, {4, 6}},//2 + 3 -> 5
{{4, 7}, {1, 4}},//3 + 0 -> 3
{{4, 7}, {2, 5}},//3 + 1 -> 4
{{4, 7}, {3, 6}},//3 + 2 -> 5
{{5, 7}, {1, 5}},//4 + 0 -> 4
{{5, 7}, {2, 6}},//4 + 1 -> 5
{{6, 7}, {1, 6}}//5 + 0 -> 5
};
int c3_len = 21;
void fileOut() {
ofstream out("mathtemp.txt");
for (int i = 1; i + 9 <= len; i += 10) {
int sum = 0, xum = 0;
for (int j = i; j <= i + 9; j++) {
out << (c[j] ^ c[j - 1]) << " ";
sum += c[j];
xum ^= c[j];
}out << sum + xum << " ";
}
out.close();
return;
}
char s;
bool fileIn() {
ifstream in("mathtemp.txt");
for (int i = 1; i + 9 <= len; i += 10) {
int sum = 0, xum = 0;
for (int j = i; j <= i + 9; j++) {
if (in >> c[j]) {
c[j] ^= c[j - 1];
sum += c[j];
xum ^= c[j];
}else {
fileOut();
in.close();
return 0;
}
}
int x;
if (!(in >> x)) {
fileOut();
in.close();
return 0;
}
if (sum + xum != x) {
fileOut();
in.close();
return 0;
}
}
in.close();
return 1;
}
void print_word() {//输出math.io
Color(0);
SetPos(0, 10);printf("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
SetPos(1, 10);printf("$");
Color(2);printf(" |\\\\ /|| /\\ =====| || || =| /==\\\\ ");Color(0);
printf("$");
SetPos(2, 10);printf("$");
Color(2);printf(" ||\\//|| //\\\\ || ||==|| || || ");Color(0);
printf("$");
SetPos(3, 10);printf("$");
Color(2);printf(" || || /===\\\\ || ||==|| || || || ");Color(0);
printf("$");
SetPos(4, 10);printf("$");
Color(2);printf(" || || // \\\\ || || || = || \\==// ");Color(0);
printf("$");
SetPos(5, 10);printf("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
return;
}
void face0();
void face1();
void face2();
void face2_1();
void face2_2();
void face3();
int craft2(int id1, int id2);
int craft3(int id1, int id2, int id3);
signed main() {
SetConsoleTitle("math.io");
system("mode con cols=90 lines=25");
HideCursor();
print_word();
SetPos(8, 18);
aa_print("读档[r]/新档[n]");
s = getch();
while (s != 'r' && s != 'n') {
s = getch();
}
if (s == 'r') {
if (!fileIn()) {
SetPos(9, 15);
Color(4);
printf("未找到存档,已自动建立新档");
Color(0);
Sleep(2000);
for (int i = 1; i <= len; i++) {
if (i <= 2) {
c[i] = 1;
}else {
c[i] = 0;
}
}
fileOut();
}else {
is_craft3 = c[7];
}
}else {
for (int i = 1; i <= len; i++) {
if (i <= 2) {
c[i] = 1;
}else {
c[i] = 0;
}
}
fileOut();
}
face0();
return 0;
}
void face0() {//主界面
while (1) {
system("cls");
print_word();
SetPos(8, 10);
printf("查看卡牌[q]");
SetPos(8, 19);
printf("合成台[w]");
SetPos(8, 27);
printf("帮助说明[e]");
SetPos(0, 39);
Color(4);
printf("退出游戏[x]");
Color(0);
char s = getch();
while (s != 'q' &&s != 'w' && s != 'e' && s != 'x') {
s = getch();
}
if (s == 'q') {
face1();
}else if (s == 'w') {
face2();
}else if (s == 'e') {
face3();
}else {
fileOut();
system("cls");
exit(0);
}
}
return;
}
void print_name(int id) {
// printf("| |");
switch(id) {
case 1:
printf("| 0 |");
break;
case 2:
printf("| 1 |");
break;
case 3:
printf("| 2 |");
break;
case 4:
printf("| 3 |");
break;
case 5:
printf("| 4 |");
break;
case 6:
printf("| 5 |");
break;
case 7:
printf("| + |");
break;
case 8:
printf("| 10 |");
break;
}
return;
}
void print_card(int id) {
SetPos(0, 8); printf("/-----------------------------\\");
SetPos(1, 8); printf("| / + |");
SetPos(2, 8); printf("| / + |");
SetPos(3, 8); printf("|_/ |");
SetPos(4, 8); printf("| + |");
SetPos(5, 8); printf("| + |");
SetPos(6, 8); printf("| |");
SetPos(7, 8); printf("| + + |");
SetPos(8, 8); printf("| |");
SetPos(9, 8); printf("| + |");
SetPos(10, 8);printf("| + |");
SetPos(11, 8);printf("| + + |");
SetPos(12, 8);printf("| + |");
SetPos(13, 8);printf("| |");
SetPos(14, 8);printf("| + + |");
SetPos(15, 8);printf("| |");
SetPos(16, 8);printf("| |");
SetPos(17, 8);printf("| |");
SetPos(18, 8);printf("| |");
SetPos(19, 8);printf("| |");
SetPos(20, 8);printf("| |");
SetPos(21, 8);printf("| |");
SetPos(22, 8);printf("\\-----------------------------/");
switch(id) {
case 1:
SetPos(14, 8);
printf("|-----------------------------");
SetPos(15, 9);
printf("描述:一个处于临界的数字。");
SetPos(16, 9);
printf("有诗曰:万物的开端,一切的终");
SetPos(17, 9);
printf("结。");
SetPos(10, 22);
printf("0");
SetPos(2, 9);
printf("D");
SetPos(3, 12); printf(" /||||||||\\=\\");
SetPos(4, 12); printf(" /=/ \\=\\");
SetPos(5, 12); printf("/=/ \\=\\");
SetPos(6, 12); printf("|=| |=|");
SetPos(7, 12); printf("|=| || |=|");
SetPos(8, 12); printf("|=| || |=|");
SetPos(9, 12); printf("|=| |=|");
SetPos(10, 12); printf("\\=\\ /=/");
SetPos(11, 12); printf(" \\=\\ /=/");
SetPos(12, 12); printf(" \\||||||||/=/");
break;
case 2:
SetPos(14, 8);
printf("|-----------------------------");
SetPos(15, 9);
printf("描述:一个整数。作为原始的计");
SetPos(16, 9);
printf("数单位。");
SetPos(10, 22);
printf("1");
SetPos(2, 9);
printf("D");
SetPos(3, 12); printf(" /==|");
SetPos(4, 12); printf(" //|=|");
SetPos(5, 12); printf(" // |=|");
SetPos(6, 12); printf(" |=|");
SetPos(7, 12); printf(" |=|");
SetPos(8, 12); printf(" |=|");
SetPos(9, 12); printf(" |=|");
SetPos(10, 12); printf(" |=|");
SetPos(11, 12); printf(" |=|");
SetPos(12, 12); printf(" |||||||||||");
break;
case 3:
SetPos(14, 8);
printf("|-----------------------------");
SetPos(15, 9);
printf("描述:一个自然数。初步建立起");
SetPos(16, 9);
printf("了对于数字和进制的认知。");
SetPos(10, 22);
printf("2");
SetPos(2, 9);
printf("D");
SetPos(3, 12); printf(" /======\\");
SetPos(4, 12); printf(" /=/ \\=\\");
SetPos(5, 12); printf(" /=/ 10 |=|");
SetPos(6, 12); printf(" |=|");
SetPos(7, 12); printf(" /=/");
SetPos(8, 12); printf(" /==/");
SetPos(9, 12); printf(" /==/");
SetPos(10, 12); printf(" /=/");
SetPos(11, 12); printf(" /=/");
SetPos(12, 12); printf(" ||||||||||||");
break;
case 4:
printf("|-----------------------------");
SetPos(15, 9);
printf("描述:一个自然数。");
SetPos(10, 22);
printf("3");
SetPos(2, 9);
printf("D");
SetPos(3, 12); printf(" /======\\");
SetPos(4, 12); printf(" /=/ \\=\\");
SetPos(5, 12); printf(" /=/ |=|");
SetPos(6, 12); printf(" /=/");
SetPos(7, 12); printf(" /===/");
SetPos(8, 12); printf(" \\=\\");
SetPos(9, 12); printf(" \\=\\");
SetPos(10, 12); printf(" \\=\\ |=|");
SetPos(11, 12); printf(" \\=\\ /=/");
SetPos(12, 12); printf(" \\======/");
break;
break;
}
return;
}
void face1() {
system("cls");
SetPos(0, 41);
Color(4);
printf("退出[x]");
Color(0);
SetPos(0, 0);printf("---------------");
SetPos(1, 0);printf("| 区域1 |");
SetPos(2, 0);printf("---------------");
vector <int> num;
for (int i = 1; i <= len; i++) {
if (c[i]) {
num.push_back(i);
}
}
int l = 0, r = min((int)num.size() - 1, 4), now = 0;
while (1) {
for (int j = 0; j <= r - l; j++) {
SetPos(3 + 4 * j, 0);
if (j + l == now)Color(6),printf("| [w] |"),Color(0);
else printf("| |");
SetPos(4 + 4 * j, 0);
if (j + l == now)Color(6);
print_name(num[j + l]);
if (j + l == now)Color(0);
SetPos(5 + 4 * j, 0);
if (j + l == now)Color(6),printf("| [s] |"),Color(0);
else printf("| |");
if (j != r - l) {
SetPos(6 + 4 * j, 0);printf("|-------------|");
}else {
SetPos(6 + 4 * j, 0);printf("---------------");
}
}
print_card(num[now]);
char s = getch();
while (s != 'w' && s != 's' && s != 'x') {
s = getch();
}
if (s == 'x') {
break;
}else if (s == 'w') {
if (now != 0) {
now--;
if (now < l) {
l--;r--;
}
}
}else {
if (now != num.size() - 1) {
now++;
if (now > r) {
l++;r++;
}
}
}
}
return;
}
void face2() {
system("cls");
SetPos(0, 41);
Color(4);
printf("退出[x]");
Color(0);
while (1) {
SetPos(6, 12);printf(" #---------------#---------------#");
SetPos(7, 12);printf(" | | |");
SetPos(8, 12);printf(" | | |");
SetPos(9, 12);printf(" | 二元合成台[c] | |");
SetPos(10, 12);printf(" | | |");
SetPos(11, 12);printf(" | | |");
SetPos(12, 12);printf(" #---------------#---------------#");
if (is_craft3) {
SetPos(9, 13);
Color(6);
printf(" 二元合成台[c]");
Color(0);
SetPos(9, 21);
Color(6);
printf(" 三元合成台[d]");
Color(0);
}else {
SetPos(9, 13);
Color(6);
printf(" 二元合成台[c]");
Color(0);
SetPos(9, 23);
Color(4);
printf("未解锁");
Color(0);
}
s = getch();
if (s == 'x') {
return;
}else if (s == 'c') {
face2_1();
return;
}else if (s == 'd' && is_craft3) {
face2_2();
return;
}
}
return;
}
void face2_1() {
system("cls");
vector <int> num;
for (int i = 1; i <= len; i++) {
if (c[i]) {
num.push_back(i);
}
}
int l = 0, r = min((int)num.size() - 1, 4), now = 0;
int card1 = -1, card2 = -1;//两张放上去的卡牌
while (1) {
SetPos(0, 41);
Color(4);
printf("退出[x]");
Color(0);
SetPos(0, 0);printf("---------------");
SetPos(1, 0);printf("| 区域1 |");
SetPos(2, 0);printf("---------------");
for (int j = 0; j <= r - l; j++) {
SetPos(3 + 4 * j, 0);
if (j + l == now)Color(6),printf("| [w] |"),Color(0);
else printf("| |");
SetPos(4 + 4 * j, 0);
if (j + l == now)Color(6);
print_name(num[j + l]);
if (j + l == now)Color(0);
SetPos(5 + 4 * j, 0);
if (j + l == now)Color(6),printf("| [s] |"),Color(0);
else printf("| |");
if (j != r - l) {
SetPos(6 + 4 * j, 0);printf("|-------------|");
}else {
SetPos(6 + 4 * j, 0);printf("---------------");
}
}
SetPos(5, 10); printf("#-------------# #-------------#");
SetPos(6, 10); printf("| |\\ /| |");
SetPos(7, 10); printf("| | \\ + / | |");
SetPos(8, 10); printf("| | \\ / | |");
SetPos(9, 10); printf("| | + & + | |");
SetPos(10, 10);printf("| | / \\ | |");
SetPos(11, 10);printf("| | / + \\ | |");
SetPos(12, 10);printf("| |/ \\| |");
SetPos(13, 10);printf("#-------------# #-------------#");
SetPos(15, 11);printf("#---------##---------##---------#");
SetPos(16, 11);printf("| 添加[a] || 清空[d] || 合成[c] |");
SetPos(17, 11);printf("#---------##---------##---------#");
if (card1 != -1) {
SetPos(9, 10);
print_name(card1);
}
if (card2 != -1) {
SetPos(9, 21);
print_name(card2);
}
char s = getch();
while (s != 'w' && s != 's' && s != 'x' && s != 'a' && s != 'd' && s != 'c') {
s = getch();
}
if (s == 'x') {
break;
}else if (s == 'w') {
if (now != 0) {
now--;
if (now < l) {
l--;r--;
}
}
}else if (s == 's') {
if (now != num.size() - 1) {
now++;
if (now > r) {
l++;r++;
}
}
}else if (s == 'a') {
if (card1 == -1) {
card1 = num[now];
}else if (card2 == -1) {
card2 = num[now];
}
}else if (s == 'd') {
card1 = card2 = -1;
}else if (s == 'c') {
if (card2 == -1)continue;
SetPos(15, 11);printf("#---------##---------##---------#");
SetPos(16, 11);printf("| 合成中…|| |");
SetPos(17, 11);printf("#---------##---------##---------#");
SetPos(16, 17);
Color(2);
for (int i = 1; i <= 20; i++) {
cout << "-";
Sleep(100 + card1 + card2);
}
Color(0);
int id = craft2(card1, card2);
fileOut();
if (id && !c[id]) {
c[id] = 1;
if (r == num.size() - 1 && r - l < 4)r++;
num.push_back(id);
}
card1 = card2 = -1;
}
}
return;
}
void face2_2() {
system("cls");
vector <int> num;
for (int i = 1; i <= len; i++) {
if (c[i]) {
num.push_back(i);
}
}
int l = 0, r = min((int)num.size() - 1, 4), now = 0;
int card1 = -1, card2 = -1, card3 = -1;
while (1) {
SetPos(0, 41);
Color(4);
printf("退出[x]");
Color(0);
SetPos(0, 0);printf("---------------");
SetPos(1, 0);printf("| 区域1 |");
SetPos(2, 0);printf("---------------");
for (int j = 0; j <= r - l; j++) {
SetPos(3 + 4 * j, 0);
if (j + l == now)Color(6),printf("| [w] |"),Color(0);
else printf("| |");
SetPos(4 + 4 * j, 0);
if (j + l == now)Color(6);
print_name(num[j + l]);
if (j + l == now)Color(0);
SetPos(5 + 4 * j, 0);
if (j + l == now)Color(6),printf("| [s] |"),Color(0);
else printf("| |");
if (j != r - l) {
SetPos(6 + 4 * j, 0);printf("|-------------|");
}else {
SetPos(6 + 4 * j, 0);printf("---------------");
}
}
SetPos(1, 10); printf(" #-------------#");
SetPos(2, 10); printf(" | |");
SetPos(3, 10); printf(" | |");
SetPos(4, 10); printf(" | |");
SetPos(5, 10); printf(" | |");
SetPos(6, 10); printf(" /| |\\");
SetPos(7, 10); printf(" //| |\\\\");
SetPos(8, 10); printf(" // | | \\\\");
SetPos(9, 10); printf(" // #-------------# \\\\");
SetPos(10, 10);printf("#-------------# #-------------#");
SetPos(11, 10);printf("| | | |");
SetPos(12, 10);printf("| |-------| |");
SetPos(13, 10);printf("| |-------| |");
SetPos(14, 10);printf("| | | |");
SetPos(15, 10);printf("| | | |");
SetPos(16, 10);printf("| | | |");
SetPos(17, 10);printf("| | | |");
SetPos(18, 10);printf("#-------------# #-------------#");
SetPos(20, 11);printf("#---------##---------##---------#");
SetPos(21, 11);printf("| 添加[a] || 清空[d] || 合成[c] |");
SetPos(22, 11);printf("#---------##---------##---------#");
if (card1 != -1) {
SetPos(14, 10);
print_name(card1);
}
if (card2 != -1) {
SetPos(5, 15);putchar(' ');
print_name(card2);
}
if (card3 != -1) {
SetPos(14, 21);
print_name(card3);
}
char s = getch();
while (s != 'w' && s != 's' && s != 'x' && s != 'a' && s != 'd' && s != 'c') {
s = getch();
}
if (s == 'x') {
break;
}else if (s == 'w') {
if (now != 0) {
now--;
if (now < l) {
l--;r--;
}
}
}else if (s == 's') {
if (now != num.size() - 1) {
now++;
if (now > r) {
l++;r++;
}
}
}else if (s == 'a') {
if (card1 == -1) {
card1 = num[now];
}else if (card2 == -1) {
card2 = num[now];
}else if (card3 == -1) {
card3 = num[now];
}
}else if (s == 'd') {
card1 = card2 = card3 = -1;
}else if (s == 'c') {
if (card3 == -1)continue;
SetPos(20, 11);printf("#---------##---------##---------#");
SetPos(21, 11);printf("| 合成中…|| |");
SetPos(22, 11);printf("#---------##---------##---------#");
SetPos(21, 17);
Color(2);
for (int i = 1; i <= 20; i++) {
cout << "-";
Sleep(100 + card1 + card2 + card3);
}
Color(0);
int id = craft3(card1, card2, card3);
fileOut();
if (id && !c[id]) {
c[id] = 1;
if (r == num.size() - 1 && r - l < 4)r++;
num.push_back(id);
}
card1 = card2 = card3 = -1;
}
}
return;
}
int craft2(int id1, int id2) {
for (int i = 1; i <= c2_len; i++) {
if (id1 == c2[i].first.first && id2 == c2[i].first.second) {
int id3 = c2[i].second;
if (id3 == 7) {
is_craft3 = 1;//解锁+
}
print_card(id3);
SetPos(1, 25);
Color(2);
printf("合成成功!\n");
SetPos(2, 25);
aa_print("请按任意键继续……");
Color(0);
s = getch();
system("cls");
return id3;
}
}
SetPos(16, 12);
Color(4);
cout << "合成失败";
Color(0);
Sleep(3000);
fileOut();
return 0;
}
int craft3(int id1, int id2, int id3) {
for (int i = 1; i <= c3_len; i++) {
if (id1 == c3[i].first.first && id2 == c3[i].first.second && id3 == c3[i].second.first) {
int id4 = c3[i].second.second;
print_card(id4);
SetPos(1, 25);
Color(2);
printf("合成成功!\n");
SetPos(2, 25);
aa_print("请按任意键继续……");
Color(0);
s = getch();
system("cls");
return id4;
}
}
SetPos(21, 12);
Color(4);
cout << "合成失败";
Color(0);
Sleep(3000);
fileOut();
return 0;
}
void face3() {
system("cls");
SetPos(0, 0);
Color(2);
printf("播放[任意]");
Color(0);
SetPos(0, 41);
Color(4);
printf("退出[x]");
Color(0);
ShowCursor();
SetPos(4, 2);
aa_print("math.io 是一款由 Marshall 自主研发的 C++ 控制台卡牌合成游戏。");
s = getch();
if (s == 'x') {
HideCursor();
return;
}
SetPos(5, 2);
aa_print("游戏发生在一个被称作「数学大陆」的幻想世界,");
s = getch();
if (s == 'x') {
HideCursor();
return;
}
SetPos(6, 2);
aa_print("在这里,被 Euclid 选中的人将被授予「合成台」,导引合成之力。");
s = getch();
if (s == 'x') {
HideCursor();
return;
}
SetPos(7, 2);
aa_print("你将扮演一位名为「OIer」的神秘角色,在自由的合成中邂逅外观各异、能力独特的卡牌们,");
s = getch();
if (s == 'x') {
HideCursor();
return;
}
SetPos(8, 2);
aa_print("和他们一起回溯往事,建起失散的数学大厦,同时逐步发掘“数学”的秘密。");
SetPos(9, 2);
aa_print("............");
s = getch();
HideCursor();
while (s != 'x') {
SetPos(10, 2);
Color(4);
printf("(已完毕)");
Color(0);
s = getch();
}
return;
}
/*
目前BUG:
*/