-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFinal.cpp
More file actions
1025 lines (982 loc) · 30.7 KB
/
Final.cpp
File metadata and controls
1025 lines (982 loc) · 30.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#define _CRT_SECURE_NO_WARNINGS 1
#include"MainScreen.h"
#include"Adven.h"
bool isclicked = false;
int Page = 0;
int Num;
int Counter = 0;
char NameList[20][20] = {
"鲁墨尘","祈墨珏","苗墨北","祈诺昱","湫静安",
"鲁君麟","司寇顾尧","顼淮德","阳子明","太叔离洛",
"苗权震","面千尘","南宫灼光","肜洛意","面修文",
"荆苍何","越松南","越炎冥","华明泽","面非寒",
};
////等级
const char LvlList[71][20] = {
"练气期一阶","练气期二阶","练气期三阶","练气期四阶","练气期五阶","练气期六阶","练气期七阶","练气期八阶","练气期九阶","练气期圆满",
"筑基期一阶","筑基期二阶","筑基期三阶","筑基期四阶","筑基期五阶","筑基期六阶","筑基期七阶","筑基期八阶","筑基期九阶","筑基期圆满",
"金丹期一阶","金丹期二阶","金丹期三阶","金丹期四阶","金丹期五阶","金丹期六阶","金丹期七阶","金丹期八阶","金丹期九阶","金丹期圆满",
"元婴期一阶","元婴期二阶","元婴期三阶","元婴期四阶","元婴期五阶","元婴期六阶","元婴期七阶","元婴期八阶","元婴期九阶","元婴期圆满",
"化神期一阶","化神期二阶","化神期三阶","化神期四阶","化神期五阶","化神期六阶","化神期七阶","化神期八阶","化神期九阶","化神期圆满",
"合体期一阶","合体期二阶","合体期三阶","合体期四阶","合体期五阶","合体期六阶","合体期七阶","合体期八阶","合体期九阶","合体期圆满",
"飞升期一阶","飞升期二阶","飞升期三阶","飞升期四阶","飞升期五阶","飞升期六阶","飞升期七阶","飞升期八阶","飞升期九阶","飞升期圆满",
"仙"
};
//
////新手教程句子数组
const char BeginText[10][100] = {
"红尘三千小世界,修真历练成真仙。欢迎来到修仙模拟器。",
"上一世的你在成仙渡劫时不幸被兄弟老婆背叛,阴差阳错回到了18岁那年。",
"重活一世你决定不再颓废,誓要夺回曾经属于你的一切。",
"点击画面加快修炼。",
"经验值满了点击突破按键进行突破",
"达到一定修为可以外出历练,探索机遇",
"灵石可以在商城中购买装备以及灵丹妙药,或者出售不需要的装备",
"在背包界面中可以更换装备.查看已有的丹药",
"你的境界和三维属性会显示在左上。",
"灵石数量以及修炼时长会显示在右上。",
};
Player_* Player = (Player_*)malloc(sizeof(Player_));
Node* HeadNode;
size_t Timer;
size_t Counter2;
//主点击按钮
Button* XiuXing = MakeButton(128 - 50, 929, 100, 50, "修炼", RGB(137, 207, 240), RGB(255, 166, 87), RGB(30, 144, 255), true);
Button* BagButton = MakeButton(384 - 50, 929, 100, 50, "背包", RGB(137, 207, 240), RGB(255, 166, 87), RGB(30, 144, 255), true);
Button* Adventure = MakeButton(640 - 50, 929, 100, 50, "历练", RGB(137, 207, 240), RGB(255, 166, 87), RGB(30, 144, 255), true);
Button* ShoppingMall = MakeButton(1024 - 178, 929, 100, 50, "商城", RGB(137, 207, 240), RGB(255, 166, 87), RGB(30, 144, 255), true);
Button* LvlUpButton = MakeButton(512 - 50, 700, 100, 50, "突破", RGB(137, 207, 240), RGB(255, 166, 87), RGB(30, 144, 255), true);
Button* ContinueButton = MakeButton(512 - 50, 520, 100, 50, "继续", RGB(255, 166, 87), RGB(255, 166, 87), RGB(255, 166, 87), false);
//显示
Button* DataButton = MakeButton(50, 50, 100, 200, "", RGB(137, 207, 240), RGB(255, 222, 146), RGB(30, 144, 255), false);
Button* AgeCoinButton = MakeButton(1024 - 150, 50, 100, 125, "", RGB(137, 207, 240), RGB(255, 222, 146), RGB(30, 144, 255), false);
Button* NameButton = MakeButton(1024 - 150, 50, 100, 125, "", RGB(137, 207, 240), RGB(255, 222, 146), RGB(30, 144, 255), false);
Button* LvlButton = MakeButton(512 - 125, 800, 250, 50, "", RGB(137, 207, 240), RGB(255, 222, 146), RGB(30, 144, 255), false);
//关闭界面按钮
Button* CloseButton_Bag = MakeButton(720, 50, 35, 35, "关闭", RGB(137, 207, 240), RGB(255, 166, 87), RGB(30, 144, 255), false);
Button* CloseButton_Adven = MakeButton(512 - 50, 600, 100, 40, "关闭", RGB(137, 207, 240), RGB(255, 166, 87), RGB(30, 144, 255), false);
Button* CloseButton_Shop = MakeButton(269, 50, 35, 35, "关闭", RGB(137, 207, 240), RGB(255, 166, 87), RGB(30, 144, 255), false);
//结束按钮k
Button* CloseButton_All = MakeButton(1024 - 90, 10, 70, 35, "保存并退出", RGB(137, 207, 240), RGB(255, 166, 87), RGB(30, 144, 255), true);
Button* MallItemButton[4] = {
MakeButton(512 - 200, 200, 150, 150, "", RGB(137, 207, 240), RGB(255, 166, 87), RGB(30, 144, 255),false),//武器
MakeButton(512 + 50, 200, 150, 150, "", RGB(137, 207, 240), RGB(255, 166, 87), RGB(30, 144, 255),false),//防具
MakeButton(512 - 200, 400, 150, 150, "", RGB(137, 207, 240), RGB(255, 166, 87), RGB(30, 144, 255),false),//饰品
MakeButton(512 + 50, 400, 150, 150, "", RGB(137, 207, 240), RGB(255, 166, 87), RGB(30, 144, 255),false),//丹药
};
Button* BagButtons[4]
{
MakeButton(512 - 200, 200, 150, 150, "", RGB(137, 207, 240), RGB(255, 166, 87), RGB(30, 144, 255),false),
MakeButton(512 + 50, 200, 150, 150, "", RGB(137, 207, 240), RGB(255, 166, 87), RGB(30, 144, 255),false),
MakeButton(512 - 200, 400, 150, 150, "", RGB(137, 207, 240), RGB(255, 166, 87), RGB(30, 144, 255),false),
MakeButton(512 + 50, 400, 150, 150, "", RGB(137, 207, 240), RGB(255, 166, 87), RGB(30, 144, 255),false),
};
Weapon* WeaponInMall;
Armor* ArmorInMall;
Decoration* DecorationInMall;
ELIXIR* ELIXIRInMall;
IMAGE imgBK, imgBag, LvlUpUI;
Button* NextButtons[2] = {
MakeButton(512 - 50, 600, 50, 40, "上一页", RGB(137, 207, 240), RGB(255, 166, 87), RGB(30, 144, 255), false),
MakeButton(512, 600, 50, 40, "下一页", RGB(137, 207, 240), RGB(255, 166, 87), RGB(30, 144, 255), false),
};
int main()
{
//加载数据
Load_All(Player, &HeadNode);
//生成随机名字
//创建主窗口
HWND MainCamera = initgraph(1024, 1024);
//加载图片
loadimage(&imgBK, "beijintu.png");
loadimage(&imgBag, "BeiBao(1).png");
loadimage(&LvlUpUI, "LvlUpUI.png");
//添加背景图
putimage(0, 0, &imgBK);
//新手教程
ExMessage m;
peekmessage(&m, EX_MOUSE);
Instruction(m, imgBK);
setfillcolor(RGB(0, 0, 0));
fillroundrect(200, 765, 824, 785, 20, 10);
//获取鼠标消息
//开始
Timer = time(NULL);
BeginBatchDraw();
while (1)
{
if (time(NULL) - Timer > 1)
{
Counter++;
Counter2++;
Timer = time(NULL);
Player->CurExp = Player->CurExp + Player->ExpSpeed;
if (Counter > 20)
{
Player->Age++;
Counter = 0;
}
if (Counter2 > 1)
{
Adventure->Canclick = true;
ContinueButton->Canclick = true;
Counter2 = 0;
}
}
flushmessage();
DrawButton(XiuXing);
DrawButton(BagButton);
DrawButton(Adventure);
DrawButton(ShoppingMall);
DrawButton(LvlUpButton);
DrawButton(DataButton);
DrawButton(AgeCoinButton);
DrawButton(CloseButton_All);
//经验条
setfillcolor(RGB(0, 0, 0));
fillroundrect(200, 765, 824, 785, 20, 10);
//更新数据
Update(Player);
while (peekmessage(&m, EX_MOUSE));
{
if (IsClickButton(XiuXing, m))
{
putimage(0, 0, &imgBK);
CloseButton_Adven->Canclick = false;
CloseButton_Shop->Canclick = false;
CloseButton_Bag->Canclick = false;
}
//历练
if (IsClickButton(Adventure, m))
{
GoAdventure(imgBag, Player);
CloseButton_Adven->Canclick = true;
ContinueButton->Canclick = true;
}
//战斗继续,continue
if (IsClickButton(ContinueButton, m))
{
GoAdventure(imgBag, Player);
}
//结束
if (IsClickButton(CloseButton_Adven, m))
{
putimage(0, 0, &imgBK);
CloseButton_Adven->Canclick = false;
ContinueButton->Canclick = false;
}
//商城
if (IsClickButton(ShoppingMall, m))
{
ShowMall(imgBag);
CloseButton_Shop->Canclick = true;
}
//突破
if (IsClickButton(LvlUpButton, m))
{
TuPo(Player->rate, imgBK, Player);
}
//商店购买东西
if (CloseButton_Shop->Canclick == true)
{
for (int i = 0; i < 4; i++)
{
if (IsClickButton(MallItemButton[i], m))
{
buyItem(Player, i);
printf("1被点击了");
MallItemButton[i]->Canclick = false;
}
}
}
//背包
if (IsClickButton(BagButton, m))
{
OpenBag(imgBag, HeadNode);
CloseButton_Bag->Canclick = true;
NextButtons[0]->Canclick = true;
NextButtons[1]->Canclick = true;
}
//背包穿戴/使用东西
if (CloseButton_Bag->Canclick == true)
{
//判断是否点击
for (int i = 0; i < 4; i++)
{
if (IsClickButton(BagButtons[i], m))
{
Node* TarNode = TurnToNode(HeadNode, (Page * 4) + i);
printf("2被点击了");
Wearing(TarNode, Player);
UseELIXIR(TarNode, Player, HeadNode);
OpenBag(imgBag, HeadNode);
Update(Player);
}
if (m.message == WM_RBUTTONDOWN)
{
Node* TarNode = TurnToNode(HeadNode, (Page * 4) + i);
DropItem(TarNode);
OpenBag(imgBag, HeadNode);
Update(Player);
break;
}
}
if (IsClickButton(NextButtons[0], m))
{
if (Page > 0)
{
Page--;
}
OpenBag(imgBag, HeadNode);
printf("3被点击了");
}
if (IsClickButton(NextButtons[1], m))
{
if (Num >= (Page + 1) * 4)
{
Page++;
}
OpenBag(imgBag, HeadNode);
printf("4被点击了");
}
}
//三个关闭按钮
if (IsClickButton(CloseButton_Bag, m))
{
putimage(0, 0, &imgBK);
CloseButton_Bag->Canclick = false;
}
if (IsClickButton(CloseButton_Shop, m))
{
putimage(0, 0, &imgBK);
CloseButton_Shop->Canclick = false;
for (int i = 0; i < 4; i++)
{
MallItemButton[i]->Canclick = true;
}
}
//退出并保存
if (IsClickButton(CloseButton_All, m))
{
Save_All(Player, HeadNode);
break;
}
FlushBatchDraw();
m.message = 0;
}
}
EndBatchDraw();
closegraph();
return 0;
}
//初始化姓名
void GetName(Player_* Player) {
if (Player->IsBeginner || Player->Name == NULL)
{
srand((unsigned int)time(NULL));
strcpy(Player->Name, NameList[rand() % 20]);
}
}
//初始化按钮
Button* MakeButton(int x, int y, int w, int h,
const char* Text, COLORREF incolor, COLORREF outcolor,
COLORREF ClickColor, bool Canclick)
{
Button(*btn) = (Button*)malloc(sizeof(Button));
//设置按钮
btn->x = x;
btn->y = y;
btn->w = w;
btn->h = h;
btn->incolor = incolor;
btn->outcolor = outcolor;
btn->ClickColor = ClickColor;
btn->curcolor = btn->outcolor;
int text_length = strlen(Text) + 1;
btn->text = (char*)malloc(sizeof(char) * text_length);
strcpy_s(btn->text, text_length, Text);
return btn;
}
//绘制按钮
void DrawButton(Button* bn)
{
//按钮设置
setlinecolor(RGB(32, 44, 57));
setfillcolor(bn->curcolor);
solidroundrect(bn->x, bn->y, bn->x + bn->w,
bn->y + bn->h, 25, 25);
//文字设置
settextcolor(BLACK);
setbkmode(TRANSPARENT);
settextstyle(15, 0, "宋体");
//文字居中
int textw = textwidth(bn->text);
int texth = textheight(bn->text);
int xx = bn->x + (bn->w - textw) / 2;
int yy = bn->y + (bn->h - texth) / 2;
outtextxy(xx, yy, bn->text);
}
//指定颜色绘制按钮
void DrawButton(Button* bn, COLORREF Color)
{
//按钮设置
setlinecolor(RGB(32, 44, 57));
setfillcolor(Color);
solidroundrect(bn->x, bn->y, bn->x + bn->w, bn->y + bn->h, 25, 25);
//文字设置
settextcolor(BLACK);
setbkmode(TRANSPARENT);
settextstyle(15, 0, "宋体");
//文字居中
int textw = textwidth(bn->text);
int texth = textheight(bn->text);
int xx = bn->x + (bn->w - textw) / 2;
int yy = bn->y + (bn->h - texth) / 2;
outtextxy(xx, yy, bn->text);
}
//判断是否在按钮内部,鼠标悬浮颜色变化
bool IsInButton(Button* bn, ExMessage m) {
if (bn->x< m.x && bn->x + bn->w >m.x
&& bn->y <m.y && bn->y + bn->h >m.y)
{
bn->curcolor = bn->incolor;
return true;
}
bn->curcolor = bn->outcolor;
return false;
}
//按钮点击判断,点击颜色变化
bool IsClickButton(Button* bn, ExMessage m) {
if (IsInButton(bn, m) && bn->Canclick != false
&& m.message == WM_LBUTTONDOWN)
{
peekmessage(&m);
bn->curcolor = bn->ClickColor;
if (m.message == WM_LBUTTONUP)
{
bn->curcolor = bn->incolor;
}
return true;
}
return false;
}
void DropItem(Node* current)
{
if (current == NULL)
{
return;
}
else
{
Node* prev = NULL; // 定义一个指向前一个节点的指针,初始值设为NULL
Node* temp = HeadNode; // 从玩家背包链表头部开始遍历寻找目标节点
while (temp != current) { // 当未到达链表末尾且尚未找到目标节点时继续循环
prev = temp; // 更新前一个节点指针
temp = temp->next; // 移动到下一个节点
}
if (temp == current) { // 如果找到了匹配的节点
if (prev) { // 如果目标节点不是链表的第一个元素
prev->next = current->next; // 将前一个节点的next指针指向目标节点之后的节点
}
else { // 否则,如果目标节点是链表的第一个元素
HeadNode = current->next; // 更新玩家背包链表头部指针
}
free(current); // 释放不再需要的目标节点所占用的内存
}
}
}
//突破按钮在经验不足时不亮
void CanLvlUp(Button* btn, int CurExp, int MaxExp, Player_* Player) {
if (CurExp < MaxExp or Player->Lvl == 70)
{
DrawButton(btn, RGB(139, 134, 130));
btn->Canclick = false;
}
else
{
btn->Canclick = true;
setfillcolor(btn->outcolor);
DrawButton(btn);
}
}
//实现三维数据的显示4
void UpdateData(Button* btn, float HP, float ATK, float DF, int Lvl, char* Name) {
//Button* DataButton = MakeButton(50, 50, 100, 200, "", RGB(137, 207, 240), RGB(255, 222, 146), RGB(30, 144, 255), false);
//文字设置
settextcolor(BLACK);
setbkmode(TRANSPARENT);
settextstyle(15, 0, "宋体");
//文字居中
char HPText[10], ATKText[10], DFText[10];
sprintf(HPText, "%d", (int)HP);
sprintf(ATKText, "%d", (int)ATK);
sprintf(DFText, "%d", (int)DF);
int textw = textwidth(HPText);
int texth = textheight(HPText);
int xx = btn->x + (btn->w - textw) / 2;
int yy = btn->y + btn->h / 2 - 5;
outtextxy(btn->x + 15, btn->y + 10, Name);
outtextxy(btn->x + 15, btn->y + 30, LvlList[Lvl]);
outtextxy(xx - 25, btn->y + 60, "生命:");
outtextxy(xx + 25, btn->y + 60, HPText);
outtextxy(xx - 25, btn->y + 80, "攻击:");
outtextxy(xx + 25, btn->y + 80, ATKText);
outtextxy(xx - 25, btn->y + 100, "防御:");
outtextxy(xx + 25, btn->y + 100, DFText);
if (Player->WearingWeapon->Flag == 0)
{
outtextxy(xx - 25, btn->y + 130, "未装备武器");
}
else
{
outtextxy(xx - 25, btn->y + 130, "已装备武器");
}
if (Player->WearingArmor->Flag == 0)
{
outtextxy(xx - 25, btn->y + 150, "未装备防具");
}
else
{
outtextxy(xx - 25, btn->y + 150, "已装备防具");
}
if (Player->WearingDecoration->Flag == 0)
{
outtextxy(xx - 25, btn->y + 170, "未装备饰品");
}
else
{
outtextxy(xx - 25, btn->y + 170, "已装备饰品");
}
}
//实现金币以及年龄的显示
void UpdateCoin_Age(Button* btn, int Age, int Coin) {
char AgeText[10], CoinText[10];
sprintf(AgeText, "%d", Age);
sprintf(CoinText, "%d", Coin);
settextcolor(BLACK);
setbkmode(TRANSPARENT);
settextstyle(15, 0, "宋体");
int textw = textwidth(AgeText);
int texth = textheight(AgeText);
int xx = btn->x + (btn->w - textw) / 2;
outtextxy(xx - 30, btn->y + btn->h / 3 - 5, "修炼:");
outtextxy(xx + 10, btn->y + btn->h / 3 - 5, AgeText);
outtextxy(xx + textw + textwidth(AgeText), btn->y + btn->h / 3 - 5, "年");
outtextxy(xx - 30, btn->y + btn->h / 3 * 2 - 5, "灵石:");
outtextxy(xx + 10, btn->y + btn->h / 3 * 2 - 5, CoinText);
outtextxy(xx + textw + textwidth(CoinText), btn->y + btn->h / 3 * 2 - 5, "枚");
}
//Button* LvlButton = MakeButton(512 - 100, 800, 250, 50, "", RGB(137, 207, 240), RGB(255, 222, 146), RGB(30, 144, 255), false);
//经验即经验条的显示
void UpdateExp_Lvl(Button* LvlButton, int CurExp, int MaxExp) {
//文字
DrawButton(LvlButton);
settextcolor(BLACK);
settextstyle(30, 0, "宋体");
char textCur[10], textMax[10];
sprintf(textCur, "%d", CurExp);
sprintf(textMax, "%d", MaxExp);
outtextxy(512 - (textwidth(textCur) / 2) - 100, 810, "经验值:");
settextcolor(BLACK);
outtextxy(512, 810, textCur);
outtextxy(512 + (textwidth(textCur)) + 20, 810, "/");
outtextxy(512 + (textwidth(textCur)) + 45, 810, textMax);
//经验条
setfillcolor(RGB(255, 222, 146));
float rate = (CurExp + 0.001) / MaxExp;
//解决超出问题
if (rate > 1)
{
rate = 1.0;
}
int right = 200 + (rate * 622);
//int right = 512;
fillroundrect(202, 767, right, 783, 20, 10);
}
//新手教程指导
void Instruction(ExMessage m, IMAGE imgbk) {
if (Player->IsBeginner)
{
settextcolor(WHITE);
outtextxy(200, 150, BeginText[0]);
for (int i = 1; i < 11;)
{
peekmessage(&m, EX_MOUSE);
if (m.message == WM_LBUTTONDOWN)
{
peekmessage(&m, EX_MOUSE);
if (m.message == WM_LBUTTONUP)
{
setbkmode(OPAQUE);
setbkcolor(BLACK);
settextcolor(WHITE);
outtextxy(200, 150 + (50 * i), BeginText[i]);
if (i < 4 || i == 10)
{
i++;
}
//教用户点击
else if (i == 3)
{
i++;
DrawButton(XiuXing);
}
//突破按钮
else if (i == 4)
{
DrawButton(LvlUpButton);
i++;
}
//历练按钮
else if (i == 5)
{
DrawButton(Adventure);
i++;
}
//商城按钮
else if (i == 6)
{
DrawButton(ShoppingMall);
i++;
}
//背包按钮
else if (i == 7)
{
DrawButton(BagButton);
i++;
}
//左上
else if (i == 8)
{
DrawButton(DataButton);
UpdateData(DataButton, Player->HP, Player->ATK, Player->DF, Player->Lvl, Player->Name);
i++;
}
//右上
else if (i == 9)
{
DrawButton(AgeCoinButton);
UpdateCoin_Age(AgeCoinButton, Player->Age, Player->Coin);
i++;
}
}
}
}
Player->IsBeginner = false;
putimage(0, 0, &imgbk);
}
return;
}
//突破界面显示
void LvlUpScreen(int rate) {
IMAGE LvlUpUI;
loadimage(&LvlUpUI, "LvlUpUI.png");
putimage(512 - LvlUpUI.getwidth() / 2, 650, &LvlUpUI);
settextcolor(RGB(0, 0, 0));
settextstyle(15, 0, "宋体");
char text[50];
sprintf(text, "%d", rate);
outtextxy(512 - 60, 650 + textheight(text), "突破概率:");
outtextxy(512 + 10, 650 + textheight(text), text);
outtextxy(512 + textwidth(text) + 10, 650 + textheight(text), "%");
}
//背包装备显示
void OpenBag(IMAGE imgBag, Node* HeadNode) {
//主体框架
int h = imgBag.getheight();
int w = imgBag.getwidth();
putimage(512 - (w / 2), 512 - (h / 2) - 170, &imgBag);
DrawButton(CloseButton_Bag);
//文字
//1.标题
settextcolor(BLACK);
setbkmode(TRANSPARENT);
settextstyle(40, 0, "宋体");
const char* text = "背包";
int textw = textwidth(text);
int xx = 512 - (textw / 2);
outtextxy(xx, 512 - 470, text);
for (int i = 0; i < 4; i++)
{
DrawButton(BagButtons[i]);
}
for (int i = 0; i < 2; i++)
{
DrawButton(NextButtons[i]);
}
ShowItemInBag(HeadNode);
}
//显示装备
void ShowItemInBag(Node* HeadNode) {
for (int i = 0 + (Page * 4); i < (Page + 1) * 4; i++)
{
Node* Cur = HeadNode->next;
for (int j = 0; j < i; j++)
{
Cur = Cur->next;
}
int x, y;
if (i % 4 == 0)
{
x = 312;
y = 230;
}
else if (i % 4 == 1)
{
x = 562;
y = 230;
}
else if (i % 4 == 2)
{
x = 312;
y = 430;
}
else
{
x = 562;
y = 430;
}
if (Cur == NULL)
{
return;
}
switch (Cur->Type)
{
case TYPE_WEAPON:
outtextxy(x + 75 - 7, y - 30, "武器");//中点-7
char text1[20];
sprintf(text1, "%d", (int)Cur->item.weapon.ATK);
outtextxy(x + 30, y, "攻击:");
outtextxy(x + 30 + textwidth("攻击:"), y, text1);
break;
case TYPE_ARMOR:
outtextxy(x + 68, y - 30, "防具");
char text3[20];
sprintf(text3, "%d", (int)Cur->item.armor.HP);
outtextxy(x + 30, y, "血量:");
outtextxy(x + 30 + textwidth("血量:"), y, text3);
char text4[20];
sprintf(text4, "%d", (int)Cur->item.armor.DF);
outtextxy(x + 30, y + 30, "防御:");
outtextxy(x + 30 + textwidth("防御:"), y + 30, text4);
break;
case TYPE_DECORATION:
outtextxy(x + 68, y - 30, "饰品");//中点-7
char text6[20];
sprintf(text6, "%d", (int)Cur->item.decoration.ATK);
outtextxy(x + 30, y, "攻击:");
outtextxy(x + 30 + textwidth("攻击:"), y, text6);
char text7[20];
sprintf(text7, "%d", (int)Cur->item.decoration.HP);
outtextxy(x + 30, y + 30, "血量:");
outtextxy(x + 30 + textwidth("血量:"), y + 30, text7);
char text8[20];
sprintf(text8, "%d", (int)Cur->item.decoration.DF);
outtextxy(x + 30, y + 60, "防御:");
outtextxy(x + 30 + textwidth("防御:"), y + 60, text8);
break;
case TYPE_ELIXIR:
outtextxy(x + 68, y - 30, "丹药");//中点-7
char text10[20];
sprintf(text10, "%d", (int)Cur->item.elixir.rate);
outtextxy(x + 30, y, "增加突破概率:");
outtextxy(x + 30 + textwidth("增加突破概率:"), y, text10);
break;
default:
break;
}
}
}
//商城界面
void ShowMall(IMAGE imgBag) {
int h = imgBag.getheight();
int w = imgBag.getwidth();
putimage(512 - (w / 2), 512 - (h / 2) - 170, &imgBag);
settextcolor(BLACK);
setbkmode(TRANSPARENT);
settextstyle(40, 0, "宋体");
const char* text = "商城";
int textw = textwidth(text);
int xx = 512 - (textw / 2);
outtextxy(xx, 512 - 470, text);
DrawButton(CloseButton_Shop);
ShowitemInMall();
}
//Button* MallItemButton[4] = {
// MakeButton(512 - 200, 200, 150, 90, "1", RGB(137, 207, 240), RGB(255, 166, 87), RGB(30, 144, 255),false,0),//武器
// MakeButton(512 + 50, 200, 150, 90, "2", RGB(137, 207, 240), RGB(255, 166, 87), RGB(30, 144, 255),false,1),//防具
// MakeButton(512 - 200, 350, 150, 90, "3", RGB(137, 207, 240), RGB(255, 166, 87), RGB(30, 144, 255),false,2),//饰品
// MakeButton(512 + 50, 350, 150, 90, "4", RGB(137, 207, 240), RGB(255, 166, 87), RGB(30, 144, 255),false,3),//丹药
//};
void ShowitemInMall() {
for (int i = 0; i < 4; i++)
{
DrawButton(MallItemButton[i]);
switch (i)
{
case TYPE_WEAPON:
outtextxy(380, 200, "武器");//中点-7
char text1[20];
sprintf(text1, "%d", (int)WeaponInMall->ATK);
outtextxy(312 + 30, 230, "攻击:");
outtextxy(312 + 30 + textwidth("攻击:"), 230, text1);
char text2[20];
sprintf(text2, "%d", WeaponInMall->Coin);
outtextxy(312 + 30, 260, "价格:");
outtextxy(312 + 30 + textwidth("价格:"), 260, text2);
break;
case TYPE_ARMOR:
outtextxy(630, 200, "防具");
char text3[20];
sprintf(text3, "%d", (int)ArmorInMall->HP);
outtextxy(562 + 30, 230, "血量:");
outtextxy(562 + 30 + textwidth("血量:"), 230, text3);
char text4[20];
sprintf(text4, "%d", (int)ArmorInMall->DF);
outtextxy(562 + 30, 260, "防御:");
outtextxy(562 + 30 + textwidth("防御:"), 260, text4);
char text5[20];
sprintf(text5, "%d", ArmorInMall->Coin);
outtextxy(562 + 30, 290, "价格:");
outtextxy(562 + 30 + textwidth("价格:"), 290, text5);
break;
case TYPE_DECORATION:
outtextxy(380, 400, "饰品");//中点-7
char text6[20];
sprintf(text6, "%d", (int)DecorationInMall->ATK);
outtextxy(312 + 30, 430, "攻击:");
outtextxy(312 + 30 + textwidth("攻击:"), 430, text6);
char text7[20];
sprintf(text7, "%d", (int)DecorationInMall->HP);
outtextxy(312 + 30, 460, "血量:");
outtextxy(312 + 30 + textwidth("血量:"), 460, text7);
char text8[20];
sprintf(text8, "%d", (int)DecorationInMall->DF);
outtextxy(312 + 30, 490, "防御:");
outtextxy(312 + 30 + textwidth("防御:"), 490, text8);
char text9[20];
sprintf(text9, "%d", DecorationInMall->Coin);
outtextxy(312 + 30, 520, "价格:");
outtextxy(312 + 30 + textwidth("价格:"), 520, text9);
break;
case TYPE_ELIXIR:
outtextxy(630, 400, "丹药");//中点-7
char text10[20];
sprintf(text10, "%d", (int)ELIXIRInMall->rate);
outtextxy(562 + 30, 430, "增加突破概率:");
outtextxy(562 + 30 + textwidth("增加突破概率:"), 430, text10);
char text11[20];
sprintf(text11, "%d", ELIXIRInMall->Coin);
outtextxy(562 + 30, 460, "价格:");
outtextxy(562 + 30 + textwidth("价格:"), 460, text11);
break;
}
}
}
//历练框
void GoAdventure(IMAGE imgBag, Player_* Player) {
putimage(0, 0, &imgBK);
int h = imgBag.getheight();//600
int w = imgBag.getwidth();//508
putimage(512 - (w / 2), 512 - (h / 2) - 170, &imgBag);//34
//printf("%d\n%d\n", 512 - (w / 2), 512 - (h / 2) - 170);
DrawButton(CloseButton_Adven);
DrawButton(ContinueButton);
AdventureMain(Player);
}
void TuPo(int rate, IMAGE imgBK, Player_* Player_1)//突破
{
int A = RandomDigit(100, 1);//生成随机数
Player_1->CurExp = Player_1->CurExp - Player_1->MaxExp;//点击突破消耗经验
if (A <= Player_1->rate)//随机数与成功率比较
{
Player_1->Lvl++;//升级
Player_1->MaxExp = Player_1->MaxExp * 1.5 + 5;//经验上限增加
Player_1->HP = (Player_1->HP + 2) * 1.2;//血量增加
Player_1->ATK = (Player_1->ATK + 2) * 1.2;//攻击增加
Player_1->DF = (Player_1->DF + 2) * 1.2;//防御增加
Player_1->rate = Player_1->rate - 1.4;//突破成功率减少
Player_1->ExpSpeed = 1 + Player_1->Lvl * 1.3;//经验增长速度增加
putimage(0, 0, &imgBK);
}
else
{
Update(Player_1);
}
}
//保存
//保存是否是新手,三维,概率,等级,经验值,最大经验值,年龄,金币,姓名,
// 装备信息
void Save_All(Player_* Player, Node* HeadNode) {
FILE* file = fopen("data.txt", "w");
fprintf(file, "%d %f %f %f %d %d %d %d %d %d %d %d %s\n",
Player->IsBeginner, Player->HP, Player->ATK, Player->DF,
Player->rate, Player->Lvl, Player->CurExp, Player->MaxExp, Player->ExpSpeed,
Player->Age, Player->Coin, Player->Recovery, Player->Name);
fprintf(file, "%d %f %d\n", Player->WearingWeapon->Flag, Player->WearingWeapon->ATK, Player->WearingWeapon->Coin);
fprintf(file, "%d %f %f %d\n", Player->WearingArmor->Flag, Player->WearingArmor->HP, Player->WearingArmor->DF, Player->WearingArmor->Coin);
fprintf(file, "%d %f %f %f %d", Player->WearingDecoration->Flag, Player->WearingDecoration->ATK, Player->WearingDecoration->HP, Player->WearingDecoration->DF, Player->WearingDecoration->Coin);
fclose(file);
Save_NodeList(HeadNode);
//以及装备背包保存
/////
//
/////
}
//读取数据
//装备信息
void Load_All(Player_* Player, Node** HeadNode) {
FILE* file = fopen("data.txt", "r");
fscanf(file, "%d ", &Player->IsBeginner);
if (Player->IsBeginner == 0)
{
fscanf(file, "%f %f %f %d %d %d %d %d %d %d %d %s\n",
&Player->HP, &Player->ATK, &Player->DF,
&Player->rate, &Player->Lvl, &Player->CurExp, &Player->MaxExp, &Player->ExpSpeed,
&Player->Age, &Player->Coin, &Player->Recovery, &Player->Name);
Player->WearingWeapon = (Weapon*)malloc(sizeof(Weapon));
fscanf(file, "%d %f %d\n",
&Player->WearingWeapon->Flag, &Player->WearingWeapon->ATK, &Player->WearingWeapon->Coin);
Player->WearingArmor = (Armor*)malloc(sizeof(Armor));
fscanf(file, "%d %f %f %d\n",
&Player->WearingArmor->Flag, &Player->WearingArmor->HP, &Player->WearingArmor->DF, &Player->WearingArmor->Coin);
Player->WearingDecoration = (Decoration*)malloc(sizeof(Decoration));
fscanf(file, "%d %f %f %f %d",
&Player->WearingDecoration->Flag, &Player->WearingDecoration->ATK, &Player->WearingDecoration->HP,
&Player->WearingDecoration->DF, &Player->WearingDecoration->Coin);
}
else
{
Player->IsBeginner = 1;
Player->HP = 10.0;
Player->ATK = 5.0;
Player->DF = 1.0;
Player->Recovery = 1;
Player->rate = 100;
Player->Lvl = 0;
Player->CurExp = 0;
Player->MaxExp = 10;
Player->ExpSpeed = 1;
Player->Age = 18;
Player->Coin = 5;
Player->WearingWeapon = (Weapon*)malloc(sizeof(Weapon));
Player->WearingWeapon->ATK = 0;
Player->WearingWeapon->Coin = 0;
Player->WearingWeapon->Flag = 0;
Player->WearingArmor = (Armor*)malloc(sizeof(Armor));
Player->WearingArmor->HP = 0;
Player->WearingArmor->DF = 0;
Player->WearingArmor->Coin = 0;
Player->WearingArmor->Flag = 0;
Player->WearingDecoration = (Decoration*)malloc(sizeof(Decoration));
Player->WearingDecoration->ATK = 0;
Player->WearingDecoration->HP = 0;
Player->WearingDecoration->DF = 0;
Player->WearingDecoration->Coin = 0;
Player->WearingDecoration->Flag = 0;
GetName(Player);
FILE* fp = fopen("Bag.txt", "w");
fprintf(fp,"0 0 3.000000 10\n");
fclose(fp);
}
Num = Load_Nodes(HeadNode);
initMall();
}
void initMall()
{
WeaponInMall = CreateWeapon(Player);
ArmorInMall = CreatArmor(Player);
DecorationInMall = CreateDecoration(Player);
ELIXIRInMall = CreateElixir(Player);
}
void Update(Player_* Player) {
UpdateExp_Lvl(LvlButton, Player->CurExp, Player->MaxExp);
UpdateData(DataButton, Player->HP, Player->ATK, Player->DF, Player->Lvl, Player->Name);
CanLvlUp(LvlUpButton, Player->CurExp, Player->MaxExp, Player);
UpdateCoin_Age(AgeCoinButton, Player->Age, Player->Coin);
LvlUpScreen(Player->rate);
if (Player->rate >= 100)
{
Player->rate = 100;
}
}
// 支付函数:尝试购买商品并从玩家的钱包中扣款
void buyItem(Player_* player, int Type) {
// 根据节点类型打印不同格式的信息
switch (Type)
{
case TYPE_WEAPON:
// 检查玩家是否有足够的金币来购买此物品
if (player->Coin < WeaponInMall->Coin) {
}
else
{
// 从玩家的金币中扣除相应的金额
player->Coin -= WeaponInMall->Coin;
Node* TempNode = createNode(TYPE_WEAPON);
TempNode->item.weapon = *WeaponInMall;
TempNode->Type = TYPE_WEAPON;
insertAtHead(&HeadNode, TempNode);
DrawButton(MallItemButton[Type]);
WeaponInMall = CreateWeapon(Player);
}
break;
case TYPE_ARMOR:
// 检查玩家是否有足够的金币来购买此物品
if (player->Coin < ArmorInMall->Coin) {
}
else
{
// 从玩家的金币中扣除相应的金额
player->Coin -= ArmorInMall->Coin;
Node* TempNode = createNode(TYPE_ARMOR);
TempNode->item.armor = *ArmorInMall;
TempNode->Type = TYPE_ARMOR;
insertAtHead(&HeadNode, TempNode);
DrawButton(MallItemButton[Type]);
ArmorInMall = CreatArmor(Player);
}
break;
case TYPE_DECORATION:
// 检查玩家是否有足够的金币来购买此物品
if (player->Coin < DecorationInMall->Coin) {
}
else
{
// 从玩家的金币中扣除相应的金额
player->Coin -= DecorationInMall->Coin;
Node* TempNode = createNode(TYPE_DECORATION);
TempNode->item.decoration = *DecorationInMall;
TempNode->Type = TYPE_DECORATION;
insertAtHead(&HeadNode, TempNode);
DrawButton(MallItemButton[Type]);
DecorationInMall = CreateDecoration(Player);
}
break;
case TYPE_ELIXIR:
// 检查玩家是否有足够的金币来购买此物品
if (player->Coin < ELIXIRInMall->Coin) {