首先成果展示给大家放上链接:
以下是代码部分(有点长):
#include <iostream>
#include <fstream>
#include <string>
#include <conio.h>
#include<cstring>
#include<iomanip>
#include<windows.h>
#include<stdlib.h>
#include<time.h>
#include<filesystem>
using namespace std;
int IFRUN = 0;
#define SIZE 100//最大用户容量
int scount = 0;//用作储存当前已注册用户数
void COLOR_PRINT(const char* s, int color)
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | color);
printf(s);
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | 7);
}
void mihayo() {
cout << "\t\t===============================================================" << endl;
cout << "\t\t\t\t─ ─ ─ ╔ ╦ ╗ ╔ ╗ ─ ╔ ═ ╦ ╗ " << endl;
cout << "\t\t\t\t╔ ═ ═ ╬ ╣ ╚ ╝ ╠ ═ ╬ ╗ ║ ╠ ═ ╗" << endl;
cout << "\t\t\t\t║ ║ ║ ║ ║ ╔ ╗ ║ ╬ ╠ ╩ ╗ ║ ╬ ║" << endl;
cout << "\t\t\t\t╚ ╩ ╩ ╩ ╩ ╝ ╚ ╩ ═ ╩ ═ ═ ╩ ═ ╝" << endl;
cout << "\t\t===============================================================" << endl;
}
class Controller
{
public:
Controller() {}
void full_screen()
{
HWND hwnd = GetForegroundWindow();
int cx = GetSystemMetrics(SM_CXSCREEN); /* 屏幕宽度 像素 */
int cy = GetSystemMetrics(SM_CYSCREEN); /* 屏幕高度 像素 */
LONG l_WinStyle = GetWindowLong(hwnd, GWL_STYLE); /* 获取窗口信息 */
/* 设置窗口信息 最大化 取消标题栏及边框 */
SetWindowLong(hwnd, GWL_STYLE, (l_WinStyle | WS_POPUP | WS_MAXIMIZE));
SetWindowPos(hwnd, HWND_TOP, 0, 0, cx, cy, 0);
}
void SetFont(int size = 30) {
CONSOLE_FONT_INFOEX cfi;
cfi.cbSize = sizeof cfi;
cfi.nFont = 0;
cfi.dwFontSize.X = 0;
cfi.dwFontSize.Y = size; //设置字体大小
cfi.FontFamily = FF_DONTCARE;
cfi.FontWeight = FW_NORMAL; //字体粗细 FW_BOLD
wcscpy_s(cfi.FaceName, L"黑体"); //设置字体,必须是控制台已有的
SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), FALSE, &cfi);
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_FONT_INFO consoleCurrentFont;
GetCurrentConsoleFont(handle, FALSE, &consoleCurrentFont);
}
COORD getXY() //通过WindowsAPI函数获取光标的位置
{
CONSOLE_SCREEN_BUFFER_INFO pBuffer;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &pBuffer);//利用标准输出句柄获得光标坐标信息
return COORD{ pBuffer.dwCursorPosition.X, pBuffer.dwCursorPosition.Y };//封装为表示坐标的COORD结构
}
COORD getScrnInfo() //获取控制台窗口缓冲区大小
{
HANDLE hStd = GetStdHandle(STD_OUTPUT_HANDLE); //获得标准输出设备句柄
CONSOLE_SCREEN_BUFFER_INFO scBufInf; //定义一个窗口缓冲区信息结构体
GetConsoleScreenBufferInfo(hStd, &scBufInf); //获取窗口缓冲区信息
return scBufInf.dwSize; //返回窗口缓冲区大小
}
void moveXY(COORD pstn)
{
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pstn);
//通过标准输出句柄控制光标的位置
}
void clearDisplay(COORD firstPst, COORD lastPst) //清除部分屏幕内容,从firstPst坐标到lastPst坐标之间的内容
{
int yDValue(lastPst.Y - firstPst.Y); //记录首末位置纵坐标差值,控制迭代次数
COORD size(getScrnInfo()); //记录目前控制台缓冲区大小
moveXY(firstPst); //移动光标到首位置
for (int y(0); y <= yDValue; y++) //一层循环控制清除行数
{
for (int x(firstPst.X); x <= size.X; x++) //二层循环避免重复清除
{
std::cout << ' '; //输出一个空格来覆盖原内容,达到清除效果
int px; //记录光标当前位置的横坐标
if (x != size.X)
px = x + 1;
else
px = 0;
if (y == yDValue && px == lastPst.X) //与光标末位置作对比,达到末位置即退出循环
break;
}
}
moveXY(firstPst);
}
void loading() //等待界面,模拟动态进度条过程
{
COORD headPst(getXY()); //记录最初位置,便于结束后清除进度条内容
HANDLE hStd(GetStdHandle(STD_OUTPUT_HANDLE));
CONSOLE_CURSOR_INFO cInfo;
GetConsoleCursorInfo(hStd, &cInfo); //获取光标信息的句柄
cInfo.bVisible = false; //修改光标可见性
SetConsoleCursorInfo(hStd, &cInfo); //设置光标不可见
COORD firstPst; //存储光标坐标,为清除做铺垫
COORD lastPst;
int n(0); //模拟进度条数字
int m(0); //记录进度条方块总数
srand((unsigned)time(NULL)); //取时间作为随机数种子,避免伪随机数
mihayo();
cout << "\t\t\tLoading";
while (n < 100) //达到较好的动态效果
{
m = n / 5;
n += rand() % 14 + 1;
if (n < 100)
{
for (int i(n / 5 - m); i > 0; i--)
std::cout << "█";
firstPst = getXY(); //获取输出前坐标
//std::cout << n << "%"; //输出百分比进度条
lastPst = getXY(); //获取输出之后的光标位置
}
else
{
n = 100; //最大值为100,达到则退出操作
std::cout << "█";
//std::cout << n << "%";
lastPst = getXY();
break;
}
Sleep(80);
clearDisplay(firstPst, lastPst); //清除现有图形,重新绘制
}
cout << endl;
//clearDisplay(headPst, lastPst); //清除进度条图形
cInfo.bVisible = true; //光标可见性改为可见
SetConsoleCursorInfo(hStd, &cInfo);
}
};
void printspace()//输出空格
{
cout << endl;
}
void printFireAttack()//火输
{
cout << "\t\t\t\t姓名" << " \t系别" << " \t定位" << endl;
cout << "\t\t\t\t======================" << endl;
cout << "\t\t\t\t迪卢克" << " 火系" << " 输出" << "\n"
<< "\t\t\t\t可莉" << " 火系" << " 输出" << "\n"
<< "\t\t\t\t胡桃" << " 火系" << " 输出" << "\n"
<< "\t\t\t\t安柏" << " 火系" << " 输出" << "\n"
<< "\t\t\t\t香菱" << " 火系" << " 输出" << "\n"
<< "\t\t\t\t烟绯" << " 火系" << " 输出" << endl;
}
void printFireDefend()//输出火系的辅助角色
{
cout << "\t\t\t\t姓名" << " \t系别" << " \t定位" << endl;
cout << "\t\t\t\t======================" << endl;
cout << "\t\t\t\t班尼特" << " 火系" << " 辅助" << "\n"
<< "\t\t\t\t辛焱" << " 火系" << " 辅助" << endl;
}
void printIceAttack()//输出冰系的输出角色
{
cout << "\t\t\t\t姓名" << " \t系别" << " \t定位" << endl;
cout << "\t\t\t\t======================" << endl;
cout << "\t\t\t\t甘雨" << " 冰系" << " 输出" << "\n"
<< "\t\t\t\t优菈" << " 冰系" << " 输出" << "\n"
<< "\t\t\t\t凯亚" << " 冰系" << " 输出" << endl;
}
void printIceDefend()//输出冰系的辅助角色
{
cout << "\t\t\t\t姓名" << " \t系别" << " \t定位" << endl;
cout << "\t\t\t\t======================" << endl;
cout << "\t\t\t\t七七" << " 冰系" << " 辅助" << "\n"
<< "\t\t\t\t重云" << " 冰系" << " 辅助" << "\n"
<< "\t\t\t\t迪奥娜" << " 冰系" << " 辅助" << "\n"
<< "\t\t\t\t罗莎莉亚" << " 冰系" << " 辅助" << endl;
}
void printWaterAttack()//输出水系的输出角色
{
cout << "\t\t\t\t姓名" << " \t系别" << " \t定位" << endl;
cout << "\t\t\t\t======================" << endl;
cout << "\t\t\t\t达达利亚" << " 水系" << " 输出" << endl;
}
void printWaterDefend()//输出水系的辅助角色
{
cout << "\t\t\t\t姓名" << " \t系别" << " \t定位" << endl;
cout << "\t\t\t\t======================" << endl;
cout << "\t\t\t\t莫娜" << " 水系" << " 辅助" << "\n"
<< "\t\t\t\t芭芭拉" << " 水系" << " 辅助" << "\n"
<< "\t\t\t\t行秋" << " 水系" << " 辅助" << endl;
}
void printThunderAttack()//输出雷系的输出角色
{
cout << "\t\t\t\t姓名" << " \t系别" << " \t定位" << endl;
cout << "\t\t\t\t======================" << endl;
cout << "\t\t\t\t刻晴" << " 雷系" << " 输出" << "\n"
<< "\t\t\t\t雷泽" << " 雷系" << " 输出" << "\n"
<< "\t\t\t\t北斗" << " 雷系" << " 输出" << endl;
}
void printThunderDefend()//输出雷系的辅助角色
{
cout << "\t\t\t\t姓名" << " \t系别" << " \t定位" << endl;
cout << "\t\t\t\t======================" << endl;
cout << "\t\t\t\t丽莎" << " 雷系" << " 辅助" << "\n"
<< "\t\t\t\t菲谢尔" << " 雷系" << " 辅助" << endl;
}
void printRockAttack()//岩输
{
cout << "\t\t\t\t姓名" << " \t系别" << " \t定位" << endl;
cout << "\t\t\t\t======================" << endl;
cout << "\t\t\t\t凝光" << " 岩系" << " 输出" << endl;
}
void printRockDefend()//输出岩系的辅助角色
{
cout << "\t\t\t\t姓名" << " \t系别" << " \t定位" << endl;
cout << "\t\t\t\t======================" << endl;
cout << "\t\t\t\t钟离" << " 岩系" << " 辅助" << "\n"
<< "\t\t\t\t阿贝多" << " 岩系" << " 辅助" << "\n"
<< "\t\t\t\t诺艾尔" << " 岩系" << " 辅助" << endl;
}
void printWindAttack()//风输
{
cout << "\t\t\t\t姓名" << " \t系别" << " \t定位" << endl;
cout << "\t\t\t\t======================" << endl;
cout << "\t\t\t\t魈" << " 风系" << " 输出" << endl;
}
void printWindDefend()//输出风系的辅助角色
{
cout << "\t\t\t\t姓名" << " \t系别" << " \t定位" << endl;
cout << "\t\t\t\t======================" << endl;
cout << "\t\t\t\t琴" << " 风系" << " 辅助" << "\n"
<< "\t\t\t\t温迪" << " 风系" << " 辅助" << "\n"
<< "\t\t\t\t枫原万叶" << " 风系" << " 辅助" << "\n"
<< "\t\t\t\t砂糖" << " 风系" << " 辅助" << endl;
}
class SystemControl
{
public:
SystemControl()
{
HeroNum = 0;
}
void RunControl();
int choHero(int work=0);//选择角色
int search(int work=0);//角色图鉴
void reaction();//元素反应
void card();//抽卡
void my();//我的
void army();//编队
void old();//历史方案
void setTeam();//创建新方案
void damage(string id,string he[4]);//伤害
double level(string user,int lel)
{
double damage1=0;
if (lel > 0 && lel <= 20)
{
damage1 = (lel * 1.815);
}
if (lel > 20 && lel <= 30)
{
damage1 = 36.3 + ((lel - 20) * 2.5);
}
if (lel > 30 && lel <= 40)
{
damage1 = 61.3 + ((lel - 30) * 3.16);
}
if (lel > 40 && lel <= 50)
{
damage1 = 92.9 + ((lel - 40) * 5.21);
}
if (lel > 50 && lel <= 60)
{
damage1 = 145 + ((lel - 50) * 7.6);
}
if (lel > 60 && lel <= 70)
{
damage1 = 221 + ((lel - 60) * 10.3);
}
return damage1;
}
void menu();//菜单
//Hero Num[100];//最多放100个角色信息
int HeroNum;
};
void SystemControl::menu()
{
system("cls");
cout << endl;
mihayo();
printspace();
cout << "\t\t\t\t ==========================" << endl;
cout << "\t\t\t\t ||请选择你要进行的操作:||" << endl;
cout << "\t\t\t\t || 1.模拟抽卡 ||" << endl;
cout << "\t\t\t\t || 2.角色图鉴 ||" << endl;
cout << "\t\t\t\t || 3.元素反应 ||" <&l