8 Star 6 Fork 1

ssSiXxx/人生重开模拟器

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
StartLife.cpp 20.71 KB
一键复制 编辑 原始数据 按行查看 历史
zero-pyy 提交于 2023-12-01 11:54 +08:00 . 修复属性点过低报错
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
#include"Count.h"
//该项用于演绎人生的界面输出
//规定每个文本框的大小为:文字输出框大小 长:1180 宽:30 上边界y坐标:130 下边界y坐标:770 岁数输出框 长100 宽30 间隔10
//各按键位置:
//负责人:mc
//整合特殊事件人生和常规人生功能 界面移动功能 基础界面绘制 连播,单击播放功能
void Startlife(character* role) {
//initgraph(1440, 900, EX_SHOWCONSOLE);
//BeginBatchDraw();
cleardevice();
int distance, width; //记录每个边框间距及宽度
static int age = 0; //使用静态本地变量记录当前输出岁数
int Accident = 1;
char myage[20];
ExMessage player;
static int Die = 0; //判断死亡
int Accidentjg = 0;
//使用静态本地变量保存当前文本输出的位置 防止因为调用其他函数使文本位置的数据丢失
static int Firstxy[5]; //首个文本框初始位置 分别为FLx, FRx, FLy, FRy
Firstxy[1] = 80; Firstxy[2] = 1360; Firstxy[3] = 135; Firstxy[4] = 165;//首文本输出框位置,
static int Lastxy[5];
for (int i = 1; i < 5; i++) {
Lastxy[i] = Firstxy[i];
}
textBox* Start, * DEnd, * Now; //双向链表指针
//链表指针初始化
Start = (textBox*)malloc(sizeof(textBox));
Start->last = NULL;
DEnd = Start;
Now = DEnd->Next;
cleardevice();
prinPlayLife();
prinRole(role);
prinlifeview();
//正在为你生成人生......
static int SPflag = SPLifeJG(); //是否有特殊人生的抽奖
//static int SPflag = 1; //是否有特殊人生的抽奖
FlushBatchDraw();
while (1) {
flushmessage();
player = getmessage();
sprintf(myage, "%d岁\n", age);
//printf("%d岁\n", age);
if (age == 51) {
Die = 1;
}
if (!Die) {
Accidentjg = AccidentJG();
if (Accident) if (Accidentjg) {
/* printf("触发意外死亡\n");*/
Die = 1;
AccidentHP(myage, DEnd);
DEnd = DEnd->Next;
Accident = 0;
}
if (DeathJG(role)) {
prinDeath(role, DEnd, myage);
Die = 1;
}
}
if (!Die && !DeathJG(role)) {
//printf("人生事件抽取\n");
if (SPflag) {
SpecialDeal(role, DEnd, age++, &Die);
DEnd = DEnd->Next;
}
else if (age < 51) {
DailyDeal(role, DEnd, age++);
DEnd = DEnd->Next;
}
}
//if (age == 51) printf("Start=%s\n", Start->Next->str);
//if(DEnd) printf("DEnd=%s\n", DEnd->str);
//Start, DEnd;
move(Firstxy, Lastxy, Start->Next, DEnd, Now, &player, role);
//不移动的正常输出
if (ClickJudge(100, 800, 264, 840, &player)) {
if (DEnd) prinLife(Firstxy, Lastxy, Start->Next, DEnd, Now, &player, role);
}
if (ClickJudge(1180, 800, 1344, 840, &player)) {
//退出游戏按键操作
freeall(Start);
exit(0);
}
if (ClickJudge(460, 800, 624, 840, &player)) {
//再来一次按键操作
cleardevice();
age = 0, Die = 0;
freeall(Start);
TalentSelect(role);
}
if (ClickJudge(820, 800, 984, 840, &player) ){
closegraph();
print_lifesummary(role);
}
}
//closegraph();
}
void print_lifesummary(character* role) {
initgraph(800,600);
setbkcolor(RGB(79, 79, 79));
cleardevice();
char* str = (char*)"人生总结";
settextstyle(40, 0, "宋体", 0, 0, FW_BOLD, false, false, false);
int width1 = textwidth(str);
outtextxy((getwidth() - width1) / 2, 60,str);
char* summary1 = (char*)"./TextStore/Summary/家境.txt";
char* summary2 = (char*)"./TextStore/Summary/快乐.txt";
char* summary3 = (char*)"./TextStore/Summary/颜值.txt";
char* summary4 = (char*)"./TextStore/Summary/智力.txt";
char* summary5 = (char*)"./TextStore/Summary/体质.txt";
FILE* fs;
char* summ = (char*)malloc(120 * sizeof(char));
int summary;
srand(time(0));
summary = rand() % 4;
if ((fs = fopen(summary1, "r")) == NULL)
{
printf("Error opening file %s\n", summary1);
exit(1);
}
else {
for (int i = 0; i < 4; i++) {
fscanf(fs, "%s", summ);
if (i == summary) {
settextstyle(30, 0, "宋体", 0, 0, FW_BOLD, false, false, false);
int width = textwidth(summ);
outtextxy((getwidth() - width) / 2, 180, summ);
}
}
}
fclose(fs);
if ((fs = fopen(summary2, "r")) == NULL)
{
printf("Error opening file %s\n", summary1);
exit(1);
}
else {
for (int i = 0; i < 4; i++) {
fscanf(fs, "%s", summ);
if (i == summary) {
settextstyle(30, 0, "宋体", 0, 0, FW_BOLD, false, false, false);
int width = textwidth(summ);
outtextxy((getwidth() - width) / 2, 230, summ);
}
}
}
fclose(fs);
if ((fs = fopen(summary3, "r")) == NULL)
{
printf("Error opening file %s\n", summary1);
exit(1);
}
else {
for (int i = 0; i < 4; i++) {
fscanf(fs, "%s", summ);
if (i == summary) {
settextstyle(30, 0, "宋体", 0, 0, FW_BOLD, false, false, false);
int width = textwidth(summ);
outtextxy((getwidth() - width) / 2, 280, summ);
}
}
}
fclose(fs);
if ((fs = fopen(summary4, "r")) == NULL)
{
printf("Error opening file %s\n", summary1);
exit(1);
}
else {
for (int i = 0; i < 4; i++) {
fscanf(fs, "%s", summ);
if (i == summary) {
settextstyle(30, 0, "宋体", 0, 0, FW_BOLD, false, false, false);
int width = textwidth(summ);
outtextxy((getwidth() - width) / 2, 330, summ);
}
}
}
fclose(fs);
if ((fs = fopen(summary5, "r")) == NULL)
{
printf("Error opening file %s\n", summary1);
exit(1);
}
else {
//printf("weofjaoidsjmdddklddddsaddjddfddld");
for (int i = 0; i < 4; i++) {
fscanf(fs, "%s", summ);
if (i == summary) {
settextstyle(30, 0, "宋体", 0, 0, FW_BOLD, false, false, false);
int width = textwidth(summ);
outtextxy((getwidth() - width) / 2, 380, summ);
}
}
}
fclose(fs);
char* a = (char*)"退出游戏";
settextstyle(50, 0, "宋体", 0, 0, FW_BOLD, false, false, false);
settextcolor(RED);
int width2 = textwidth(a);
outtextxy((getwidth() - width2) / 2, 500, a);
ExMessage m;
while (true) {
if (peekmessage(&m, EX_MOUSE)) {
if (ClickJudge(320, 500, 480, 550, &m)) {
closegraph();
exit(0);
}
}
}
}
void move(int* Firstxy, int* Lastxy, textBox* Head, textBox* DEnd, textBox* Now, ExMessage* player, character* role) {
//按下上下箭头的界面移动 向Move函数传入移动信息
if (GetAsyncKeyState(VK_UP)) {
Firstxy[3] -= 10;
Firstxy[4] -= 10;
Lastxy[3] -= 10;
Lastxy[4] -= 10;
prinmove(Firstxy, Lastxy, Head, DEnd, Now, player, role);
}
else if (GetAsyncKeyState(VK_DOWN)) {
Firstxy[3] += 10;
Firstxy[4] += 10;
Lastxy[3] += 10;
Lastxy[4] += 10;
prinmove(Firstxy, Lastxy, Head, DEnd, Now, player, role);
}
}
//特殊人生输出处理整合
//功能:整合输出特殊人生(printLife) 特殊人生事件抽取 + 写入链表
//传入参数:人物属性结构体 输出框的位置
void SpecialDeal(character* role, textBox* DEnd, int SPage, int* Die) {
//存储特殊文本库
static char SP1[] = "./TextStore//Special//Special1.txt"; static char SP2[] = "./TextStore//Special//Special2.txt"; static char SP3[] = "./TextStore//Special//Special3.txt"; static char SP4[] = "./TextStore//Special//Special4.txt";
static char* SP;
static int i = 0;
int cnt = 0;
//抽取特殊文本库
while (!i) {
//printf("抽取特殊事件库\n");
i = Random() % 5; //取余后的数不大于4
//i = 2;
if (cnt >= 3) i = 2;
//printf("i=%d\n", i);
if (i < 5 && i > 0) {
switch (i) {
case 1:SP = SP1; i = -1; break;
case 2:SP = SP2; i = -1; break;
case 3:SP = SP3; i = -1; break;
case 4:SP = SP4; i = -1; break;
}
}
if (i == -1) {
i = -2;
break;
}
cnt++;
}
static FILE* fp;
if (i == -2) {
i = -1;
fp = fopen(SP, "r");
}
//得到特定岁数
static int theage = 0, Endage = 0;
if (!theage) fscanf(fp, "%d", &theage);
if (!Endage) fscanf(fp, "%d", &Endage);
//printf("theage=%d\n",theage);
char prin[512] = "0"; //记录输出文案
char myage[50] = "0"; //记录写入链表岁数
sprintf(myage, "%d岁", SPage);
char ch[50] = "0"; //记录变化属性
//抽取人生事件
//死亡退出
if (DeathJG(role)) {
prinDeath(role, DEnd, myage);
return;
}
//在特定岁数输出特殊文本库
if (SPage >= theage && SPage <= Endage) {
if (fp) {
int JGend = 1;
JGend = fscanf(fp, "%s", prin);
sprintf(myage, "%d岁", SPage);
//传入链表记录
if (JGend) {
DEnd = NodeCreate(prin, myage, DEnd); //写入链表
}
}
}
//否则抽取常规事件
if (SPage < theage) {
DailyLFPlay(SPage, DEnd, role);
}
if (SPage > Endage) {
fclose(fp);
*Die = 1;
theage = Endage = 0;
i = 0;
}
}
// 以下函数组合功能: 输出特别人生
// 由于特殊人生不全是在常规库内抽取 需要额外封装 通过判断年龄确定输出哪一个文本库的内容 若需要从常规事件库抽取则调用 DailyDeal 函数 否则输出特定剧情
//功能:利用 Random 函数判断特殊事件是否发生(取余两位数的结果小于个位数)
bool SPLifeJG() {
if ((Random() % 100) < 10) return 1;
else return 0;
}
//常规事件库抽取(所有经历均从Daily库内抽取 作为独立实现常规人生的模块整合)
//功能: 打开常规事件库输出文案 不需要按键判断
//传入参数:人物属性点结构体
void DailyDeal(character* role, textBox* DEnd, int DLage) {
//while (DLage != 51 && DeathJG(role)) {
// DailyLFPlay(DLage, DEnd, role);
// DLage++;
//}
char myage[20];
sprintf(myage, "%d岁", DLage);
if (DeathJG(role)) {
prinDeath(role, DEnd, myage);
return;
}
if (DLage < 51 && !DeathJG(role)) {
DailyLFPlay(DLage, DEnd, role);
}
}
//功能:从常规事件库内抽取一件事件并将事件写入链表 改变属性值
//传入参数:当前人生岁数 (用于抽取不同岁数库的判断) 链表尾指针
void DailyLFPlay(int age, textBox* DEnd, character* role) {
//存储文件
//printf("常规事件抽取\n");
static char* strs[51];
static char str0[] = "./TextStore//Daily//0.txt"; static char str10[] = "./TextStore//Daily//10.txt"; static char str20[] = "./TextStore//Daily//20.txt"; static char str30[] = "./TextStore//Daily//30.txt"; static char str40[] = "./TextStore//Daily//40.txt"; static char str50[] = "./TextStore//Daily//50.txt";
static char str1[] = "./TextStore//Daily//1.txt"; static char str11[] = "./TextStore//Daily//11.txt"; static char str12[] = "./TextStore//Daily//12.txt"; static char str13[] = "./TextStore//Daily//13.txt"; static char str14[] = "./TextStore//Daily//14.txt"; static char str15[] = "./TextStore//Daily//15.txt"; static char str16[] = "./TextStore//Daily//16.txt"; static char str17[] = "./TextStore//Daily//17.txt"; static char str18[] = "./TextStore//Daily//18.txt"; static char str19[] = "./TextStore//Daily//19.txt";
static char str2[] = "./TextStore//Daily//2.txt"; static char str21[] = "./TextStore//Daily//21.txt"; static char str22[] = "./TextStore//Daily//22.txt"; static char str23[] = "./TextStore//Daily//23.txt"; static char str24[] = "./TextStore//Daily//24.txt"; static char str25[] = "./TextStore//Daily//25.txt"; static char str26[] = "./TextStore//Daily//26.txt"; static char str27[] = "./TextStore//Daily//27.txt"; static char str28[] = "./TextStore//Daily//28.txt"; static char str29[] = "./TextStore//Daily//29.txt";
static char str3[] = "./TextStore//Daily//3.txt"; static char str31[] = "./TextStore//Daily//31.txt"; static char str32[] = "./TextStore//Daily//32.txt"; static char str33[] = "./TextStore//Daily//33.txt"; static char str34[] = "./TextStore//Daily//34.txt"; static char str35[] = "./TextStore//Daily//35.txt"; static char str36[] = "./TextStore//Daily//36.txt"; static char str37[] = "./TextStore//Daily//37.txt"; static char str38[] = "./TextStore//Daily//38.txt"; static char str39[] = "./TextStore//Daily//39.txt";
static char str4[] = "./TextStore//Daily//4.txt"; static char str41[] = "./TextStore//Daily//41.txt"; static char str42[] = "./TextStore//Daily//42.txt"; static char str43[] = "./TextStore//Daily//43.txt"; static char str44[] = "./TextStore//Daily//44.txt"; static char str45[] = "./TextStore//Daily//45.txt"; static char str46[] = "./TextStore//Daily//46.txt"; static char str47[] = "./TextStore//Daily//47.txt"; static char str48[] = "./TextStore//Daily//48.txt"; static char str49[] = "./TextStore//Daily//49.txt";
static char str5[] = "./TextStore//Daily//5.txt"; static char str6[] = "./TextStore//Daily//6.txt"; static char str7[] = "./TextStore//Daily//7.txt"; static char str8[] = "./TextStore//Daily//8.txt"; static char str9[] = "./TextStore//Daily//9.txt";
strs[0] = str0; strs[10] = str10; strs[20] = str20; strs[30] = str30; strs[40] = str40; strs[50] = str50;
strs[1] = str1; strs[11] = str11; strs[12] = str12; strs[13] = str13; strs[14] = str14; strs[15] = str15; strs[16] = str16; strs[17] = str17; strs[18] = str18; strs[19] = str19;
strs[2] = str2; strs[21] = str21; strs[22] = str22; strs[23] = str23; strs[24] = str24; strs[25] = str25; strs[26] = str26; strs[27] = str27; strs[28] = str28; strs[29] = str29;
strs[3] = str3; strs[31] = str31; strs[32] = str32; strs[33] = str33; strs[34] = str34; strs[35] = str35; strs[36] = str36; strs[37] = str37; strs[38] = str38; strs[39] = str39;
strs[4] = str4; strs[41] = str41; strs[42] = str42; strs[43] = str43; strs[44] = str44; strs[45] = str45; strs[46] = str46; strs[47] = str47; strs[48] = str48; strs[49] = str49;
strs[5] = str5; strs[6] = str6; strs[7] = str7; strs[8] = str8; strs[9] = str9;
FILE* fp = fopen(strs[age], "r"); //打开文件
char prin[512] = "0"; //存储文案
char myage[50] = "0"; //记录岁数
sprintf(myage, "%d岁", age);
int JGend = 0;
int cnt = 0; //用于防止抽取过慢
//定位 + 抽取事件
while (1) {
int line = Random() % 16; //最多15行
char ch[100] = "0";
char* Ch;
if (cnt < 5) {
for (; line > 0; line--) {
Ch = fgets(ch, 100, fp);
if (Ch == NULL) break;
}
}
else {
fseek(fp, 0, SEEK_SET);
fscanf(fp, "%s", prin);
break;
}
cnt++;
JGend = fscanf(fp, "%s", prin);
if (JGend > 0) break;
else fseek(fp, 0, SEEK_SET);
}
DEnd = NodeCreate(prin, myage, DEnd); //写入链表
//printf("%d岁\n", age);
PlayCompare(role, fp); //改变属性
fclose(fp);
}
//界面上下移动
//利用类似双向链表结构存储人生经历
//逻辑:
//定义两个指针Start DEnd Start用于指向整个链表的头节点 DEnd用于指向整个链表的尾部
//由于每个输出框间的间隔相同 所以只需要将所有输出框坐标与文字输出坐标和第一个输出框的坐标关联起来 改变第一个输出框的坐标即可做到移动文本的效果
//以向上移动为例 对原来的第一个文本框坐标增减
//将多余的内容遮住
//界面移动函数(整合):双向链表的输出指针移动
// 移动实现: 利用每个边框间隔 循环赋值并绘制 直到右下角坐标超出边界时或尾指针指向NULL时结束循环
//传入参数: 上移(1) 下移(2) 以此改变首个文本框坐标
//void move(int MoveMessage, int* Firstxy, int* Lastxy, textBox* Head, textBox* End) {
// //根据移动操作对应边界判断及移动指针
// switch (MoveMessage) {
// case 1:UPmoveJG(Firstxy, Lastxy, Head, End); break;
// case 2:DOWNmoveJG(Firstxy, Lastxy, Head, End); break;
// }
//}
//功能:判断文案输出框上边界是否越界(当首位边框右下角消失在文案输出界面则为越界) 以及双向链表的输出尾指针改变
//传入参数:首位输出边框的左上角右下角坐标 末位输出边框的左上角右下角坐标 输出指针
//void UPmoveJG(int* Firstxy, int* Lastxy, textBox* Head, textBox* End) {
// int UPBoundary; //上边界y坐标
// int DOWNBoundary; //下边界y坐标
//
// //上输出框下边超出边界
// if (Firstxy[4] < UPBoundary) {
// textBox** head = &Head;
// if(Head->last) *head = Head->last;
// }
//
// //下输出框下边走出边界
// if (Lastxy[4] < DOWNBoundary) {
// textBox** end = &End;
// if(End->Next) *end = End->Next;
// }
//}
//
//void DOWNmoveJG(int* Firstxy, int* Lastxy, textBox* Head, textBox* End) {
// int UPBoundary; //上边界y坐标
// int DOWNBoundary; //下边界y坐标
//
// //上输出框上边走出边界
// if (Firstxy[3] > UPBoundary) {
// textBox** head = &Head;
// if(Head->Next) *head = Head->Next;
// }
//
// //下输出框上边超出边界
// if (Lastxy[3] > DOWNBoundary) {
// textBox** end = &End;
// if (End->last) *end = End->last;
// }
//}
//绘制的输出框和文本
//要求:每次输出进行边界判断 输出到最后一个退出函数(到达输出框边界或链表结尾)
//传入参数:第一个文本框的位置 双向链表当前页面的头指针与尾指针
void prinLife(int* Firstxy, int* Lastxy, textBox* Head, textBox* DEnd, textBox* Now, ExMessage* player, character* role) {
int distance, width; //记录输出框间距和宽度
int Lx = Firstxy[1], Ly = Firstxy[3], Rx = Firstxy[2], Ry = Firstxy[4];
width = Firstxy[4] - Firstxy[3]; distance = 10;
textBox* prin = Head;
textBox** now = &Now;
//printf("width=%d distance=%d\n", width, distance);
//printf("进入播放\n"); //若是输出经历
//获取用户操作
//连播
//输出完成后再次点击不做操作
BeginBatchDraw();
prinlifeview();
if (prin != NULL) {
do {
FlushBatchDraw();
settextstyle(25, 0, "宋体", 0, 0, FW_BOLD, false, false, false);
settextcolor(RGB(232, 230, 237));
setlinecolor(WHITE);
setbkmode(TRANSPARENT);
//输出字符串
roundrect(Lx, Ly, Rx, Ry, 5, 5); //输出框
outtextxy(correcttextX(Lx, Lx + 95, prin->myage), correcttextY(Ly, Ry, prin->myage), prin->myage); //岁数
outtextxy(Lx + 105, Ly + 4, prin->str); //经历
Ly += distance + width; Ry += distance + width; //更新边框位置(获取下一个输出框位置)
//printf("Ly=%d Ry=%d\n", Ly, Ry);
prin = prin->Next; //更新prin位置(下一段经历的结点)
*player = getmessage();
prinPlayLife();
prinRole(role);
*now = prin;
move(Firstxy, Lastxy, Head, DEnd, Now, player, role);
if (WM_LBUTTONDOWN)
if (ClickJudge(100, 800, 260, 840, player)) break;
Sleep(500);
} while (prin != NULL);
EndBatchDraw();
//更新数据
Lastxy[3] = Ly; Lastxy[4] = Ry;
return;
}
////右键单次播放
// else if (player->message == WM_RBUTTONDOWN) {
// roundrect(Lastxy[1], Lastxy[3], Lastxy[2], Lastxy[4], 10, 10); //输出框
// outtextxy(correcttextX(Lastxy[1], Lastxy[1] + 100, prin->myage), correcttextY(Lastxy[3], Lastxy[3] + 30, prin->myage), prin->myage); //岁数
// outtextxy(Lastxy[1] + 105, Lastxy[3], prin->str); //经历
// prin = prin->Next; //更新Now位置
// Lastxy[3] += distance + width, Lastxy[4] += distance + width;
// textBox** now = &Now;
// *now = Now->Next;
// player->message = 0;
// return;
// }
}
// 绘制移动后的界面信息
void prinmove(int* Firstxy, int* Lastxy, textBox* Head, textBox* DEnd, textBox* Now, ExMessage* player, character* role) {
int distance, width; //记录输出框间距和宽度
int Lx = Firstxy[1], Ly = Firstxy[3], Rx = Firstxy[2], Ry = Firstxy[4];
width = Firstxy[4] - Firstxy[3]; distance = 10;
textBox* prin = Head;
BeginBatchDraw();
cleardevice();
prinlifeview();
while (prin != Now && prin != NULL) {
settextstyle(25, 0, "宋体", 0, 0, FW_BOLD, false, false, false);
settextcolor(RGB(232, 230, 237));
setlinecolor(WHITE);
setbkmode(TRANSPARENT);
//输出字符串
roundrect(Lx, Ly, Rx, Ry, 10, 10); //输出框
outtextxy(correcttextX(Lx, Lx + 95, prin->myage), correcttextY(Ly, Ry, prin->myage), prin->myage); //岁数
outtextxy(Lx + 105, Ly + 4, prin->str); //经历
Ly += distance + width, Ry += distance + width; //更新边框位置(获取下一个输出框位置)
prin = prin->Next; //更新prin位置(下一段经历的结点)
prinPlayLife();
prinRole(role);
/**player = getmessage();*/
}
FlushBatchDraw();
EndBatchDraw();
}
void prinRole(character* role) {
settextcolor(WHITE);
//颜值:
static char attributes[5][3];
sprintf_s(attributes[1], 10, "%d", role->apprance);
outtextxy(270, 50, attributes[1]);
//智力
sprintf_s(attributes[3], 10, "%d", role->intelligence);
outtextxy(580, 50, attributes[3]);
//家境
sprintf_s(attributes[2], 10, "%d", role->wealth);
outtextxy(890, 50, attributes[2]);
//体质
sprintf_s(attributes[4], 10, "%d", role->health);
outtextxy(1200, 50, attributes[4]);
}
//申请结构体的空间 存储文案和岁数 并初始化
//传入记录的字符串与链表尾部指针的Next成员
textBox* NodeCreate(char* ch, char* myage, textBox* DEnd) {
//printf("写入链表\n");
//printf("%s:%s\n", myage, ch);
textBox* Node = (textBox*)malloc(sizeof(textBox));
textBox** last = &(DEnd->Next);
if (!DEnd) return DEnd;
else {
*last = Node;
Node->Next = NULL;
Node->last = DEnd;
//char* str;//写入经历
//char* ge;//写入年龄
strcpy(Node->str, ch);
strcpy(Node->myage, myage);
return Node;
}
}
////连接结点
////传入需要连接的两个结点
//textBox* Connect(textBox* last,textBox* next) {
// textBox** Last = &last->Next;
// textBox** Next = &next->last;
// *Last = next;
// *Next = last;
// return last;
//}
//使用Start指针释放链表空间
void freeall(textBox* Start) {
textBox* last, * cur = Start;
while (1) {
if (cur != NULL) {
last = cur;
cur = cur->Next;
free(last);
}
else break;
}
}
//匹配对应的属性点名称 改变属性点的数值
//传入参数:人物属性点结构体 文件指针
void PlayCompare(character* role, FILE* fp) {
char str1[] = "家境"; char str2[] = "体质"; char str3[] = "快乐"; char str4[] = "智力"; char str5[] = "颜值";
char* strs[5];//存储对比字符串
strs[0] = str1; strs[1] = str2; strs[2] = str3; strs[3] = str4; strs[4] = str5;
char str[512] = "0";
int judge = 0;//判断字符串是否相等
int getvalue = 0;//获取属性数值
int judgestr = 0;//判断是否为属性名称
int* wealth = &role->wealth; int* health = &role->health; int* happiness = &role->happiness; int* intelligence = &role->intelligence; int* apprance = &role->apprance;
while (1) {
//judgestr = fscanf(fp, "%s", str);
//if (judgestr != 4) break;
fscanf(fp, "%s", str);
judgestr = strlen(str);
//printf("正在匹配:%s\n", str);
if (judgestr != 4) {
sprintf(str, "0");
break;
}
for (int i = 0; i < 5; i++) {
//printf("当前匹配:%s\n", strs[i]);
judge = strcmp(str, strs[i]);
if (!judge) {
//printf("改变属性点\n");
fscanf(fp, "%d", &getvalue);
switch (i) {
case 0: *wealth += getvalue; break;
case 1: *health += getvalue; break;
case 2: *happiness += getvalue; break;
case 3: *intelligence += getvalue; break;
case 4: *apprance += getvalue; break;
}
break;
}
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/sssixxx/life-reboot-simulator.git
git@gitee.com:sssixxx/life-reboot-simulator.git
sssixxx
life-reboot-simulator
人生重开模拟器
master

搜索帮助