-
Notifications
You must be signed in to change notification settings - Fork 0
/
wenming.cpp
164 lines (147 loc) · 3.86 KB
/
wenming.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
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
#include "system.h"
vector<wenming*> suoyouwm;//所有文明
wenming::wenming(string name,int x,int y,int tansuox,int tansuoy,jiaoliu jltezheng,bool tstezheng)
{
wmnum++;
if(wmnum==wuqiong)
{exit(-2);}//异常退出之二,-2为文明数量过多
this->num=wmnum;
//正式开始添加
suoyouwm.push_back(this);
this->x=x;
this->y=y;
this->name=name;
this->tansuox=tansuox;
this->tansuoy=tansuoy;
this->jltezheng=jltezheng;
this->tstezheng=tstezheng;
}
wenming::~wenming()
{suoyouwm[num]=nullptr;}
void wenming::clone()
{
wenming *anewwm=new wenming;
*anewwm=*this;
/*
这块应该是……
决定新文明坐标的代码……
但是……
我自己看不懂了TAT!!
所以略
*/
coutln(getname()+"在"+tostring(this->x)+","+tostring(this->y)+"处发展出了一个分支文明");
}
void wenming::setwmzhi(int wmzhigaibian)
{
wzzlxiajiang(wmzhigaibian);//文明值增加,物质总量就会减少,黑暗森林的基本公理
this->wmzhi+=wmzhigaibian;
}
string wenming::getname()
{
if(this->name!="")
{return this->name;}
return tostring(this->num)+"号文明";
}
string wenming::gettezheng()
{
string texing="文明特性为";
if(this->jltezheng==gongji)
{texing+="攻击";}
if(this->jltezheng==fangyu)
{texing+="防御";}
if(this->jltezheng==youhao)
{texing+="友好";}
if(this->tstezheng)
{texing+="和探索";}
else
{texing+="和保守";}
return texing;
}
void wenming::tozero()//文明归零不是文明值为0,而是彻底被杀死了
{
coutln(getname()+"遭到归零");
delete this;
}
bool wenming::isalive()//此项为假的文明不能行动
{
if(this->wmzhi>0)//文明值大于0为活着
{return true;}
else
{return false;}
}
void wenming::attack(wenming* jieshouwenming)
{launch(-1,jieshouwenming);}
void wenming::help(wenming* jieshouwenming)
{launch(1,jieshouwenming);}
void wenming::launch(int one,wenming* jieshouwenming)
{
if(!fanweipanduan(x,y,jieshouwenming->x,jieshouwenming->y,tansuox,tansuoy))
return;
int gaibianwmz=hudongxishu*one-this->wmzhi;
int sudu=this->wmzhi*suduxishu;
new feixingwu(gaibianwmz,sudu,this,jieshouwenming);
}
void wenming::explore()
{
this->tansuox+=this->wmzhi*tansuoxishu;
this->tansuoy+=this->wmzhi*tansuoxishu;
coutln(getname()+"进行了探索,目前的探索范围是横轴"+tostring(tansuox)+"个长度单位,纵轴"+tostring(tansuoy)+"个长度单位");
}
bool wenming::operator == (const wenming& a)
{return this->num==a.num;}
void wenming::xingdong()
{
if(this->jltezheng==gongji)//如果文明的特征是攻击
{
for(auto a:suoyouwm)
{
if(this==a)
{continue;}
this->attack(a);
}
}
if(this->jltezheng==youhao)
{
for(auto a:suoyouwm)
{
if(this==a)
{continue;}
this->help(a);
}
}
if(this->jltezheng==fangyu) //防御,被帮就帮,被打就打
{
for(auto a:suoyoufxw)
{
if(fanweipanduan(this->x,this->y,a->fashewenming->x,a->fashewenming->y,this->tansuox,this->tansuoy)
&&a->jieshouwenming==this
&&!a->isreplyed)
{
if(a->gettype())
{this->attack(a->fashewenming);}
else
{this->help(a->fashewenming);}
a->isreplyed=true;
}
}
}
//下面是探索
if(this->tstezheng)
{
if(Rand::rand_2_3())
{this->explore();}
else
{this->clone();}
}
else
{
if(Rand::rand_2_3())
{this->explore();}
}
int wmzhigaibian=Rand::random(-1*wuqiong,wuqiong);
setwmzhi(wmzhigaibian);
if(wmzhigaibian>0)
{coutln(getname()+"发展,目前的文明值是"+tostring(wmzhi));}
if(wmzhigaibian<0)
{coutln(getname()+"内战,目前的文明值是"+tostring(wmzhi));}
}