-
Notifications
You must be signed in to change notification settings - Fork 0
/
AdvScenario.cpp
110 lines (102 loc) · 3.48 KB
/
AdvScenario.cpp
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
#include "StdAfx.h"
#include "AdvScenario.h"
AdvScenario::AdvScenario(void)
{
rHero = new Hero();
rMonster = nullptr;
}
AdvScenario::~AdvScenario(void)
{
delete rHero;
delete rMonster;
}
void AdvScenario::choice()
{
int optional;
do
{
CLS;
cout <<right << "请选择你要挑战的怪兽:" << endl;
cout << setfill('-') << setw(30) << "" << endl;
cout << "| 1:" << setfill(' ') << setw(26) << "巴尔坦虫怪【lv1】|" << endl;
cout << "| 2:" << setw(26) << "格斯安鱼怪【lv5】|" << endl;
cout << "| 3:" << setw(26) << "泰斯鸟怪【lv10】|" << endl;
cout << "| 4:" << setw(26) << "绿头猿怪【lv30】|" << endl;
cout << "| 5:" << setw(26) << "赤龙怪(BOSS)【lv50】|" << endl;
cout << setfill('-') << setw(30) << "" << endl;
cin >> optional;
} while (optional<1 || optional>5);
if (rMonster!=nullptr)
{
delete rMonster;
}
rMonster = new Monster(optional-1);
return;
}
bool AdvScenario::challenge()
{
while(true)
{
showInfo();
((Hero *)rHero)->choice();
rHero->attack(*rMonster);
showInfo(rHero->name);
if(rMonster->isAlive())
{
rMonster->attack(*rHero);
showInfo(rMonster->name);
if (!rHero->isAlive())
{
((Hero *)rHero)->levelDown();
if (rHero->level<=0)
{
cout << endl << "======游戏失败!======" << endl;
return false;
}
return true;
}
else
{
round++;
for (int i=0;i!=NUM_CRAFTS;i++)
{
((Hero *)rHero)->crafts[i].action = ((Hero *)rHero)->crafts[i].action <= 0 ? 0 : ((Hero *)rHero)->crafts[i].action - 1;
}
PC;
continue;
}
}
else
{
if (rMonster->level == 50)
{
cout << endl << "======恭喜通关!======" << endl;
return false;
}
((Hero *)rHero)->levelUp(rMonster->level);
return true;
}
}
}
void AdvScenario::showInfo()
{
cout << left << setfill('-') << setw(39) << "" << endl; // 表格宽度共计40个半角字符
cout << "|" << setfill(' ') << "第" << setw(3) << round << "轮" <<setw(30) << "" << "|" << endl;
cout << setfill('-') << setw(39) << "" << endl;
cout << "|" << setfill(' ') << setw(6) << "英雄:" << setw(12) << rHero->name << "|" << setw(6) << "怪兽:" << setw(12) << rMonster->name << "|" << endl;
cout << "|" << setw(6) << "级别:" << setw(12) << rHero->level << "|" << setw(6) << "级别:" << setw(12) << rMonster->level << "|" << endl;
cout << "|" << setw(6) << "HP:" << setw(12) << rHero->HP << "|" << setw(6) << "HP:" << setw(12) << rMonster->HP << "|" << endl;
cout << "|" << setw(6) << "MP:" << setw(12) << ((Hero *)rHero)->MP << "|" << setw(18) << "" << "|" << endl;
cout << setfill('-') << setw(39) << "" << endl;
}
void AdvScenario::showInfo(string name)
{
cout << left << setfill('-') << setw(39) << "" << endl; // 表格宽度共计40个半角字符
cout << "|" << setfill(' ') << setw(12) << name << "攻击!" << setw(19) << "" << "|" << endl;
cout << setfill('-') << setw(39) << "" << endl;
cout << "|" << setfill(' ') << setw(6) << "英雄:" << setw(12) << rHero->name << "|" << setw(6) << "怪兽:" << setw(12) << rMonster->name << "|" << endl;
cout << "|" << setw(6) << "级别:" << setw(12) << rHero->level << "|" << setw(6) << "级别:" << setw(12) << rMonster->level << "|" << endl;
cout << "|" << setw(6) << "HP:" << setw(12) << rHero->HP << "|" << setw(6) << "HP:" << setw(12) << rMonster->HP << "|" << endl;
cout << "|" << setw(6) << "MP:" << setw(12) << ((Hero *)rHero)->MP << "|" << setw(18) << "" << "|" << endl;
cout << setfill('-') << setw(39) << "" << endl;
}