-
Notifications
You must be signed in to change notification settings - Fork 0
/
unitmaker.cpp
executable file
·163 lines (130 loc) · 4.66 KB
/
unitmaker.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
#include "unitmaker.h"
#include "player.h"
#include "iostream"
#include "map.h"
using namespace std;
UnitMaker::UnitMaker(Map* _map,Player* player, int Type) :Building(_map){
gameObjectType=3;
height=3;
width=4;
switch(Type){
case 0:
this->name=player->information.unitMaker_name;
this->cost=player->information.unitMaker_cost;
this->upgrade_cost=player->information.unitMaker_upgrade_cost;
this->construction_time=player->information.unitMaker_time_constructoin;
this->max_health=player->information.unitMaker_max_health;
this->attack_damage=player->information.unitMaker_attack_damage;
this->attack_range=player->information.unitMaker_attack_range;
this->attack_delay=player->information.unitMaker_attack_delay;
this->unitType=0;
this->training_time=player->information.normal_time_constructoin;
break;
case 1:
this->name=player->information.super_unitMaker_name;
this->cost=player->information.super_unitMaker_cost;
this->upgrade_cost=player->information.super_unitMaker_upgrade_cost;
this->construction_time=player->information.super_unitMaker_time_constructoin;
this->max_health=player->information.super_unitMaker_max_health;
this->attack_damage=player->information.super_unitMaker_attack_damage;
this->attack_range=player->information.super_unitMaker_attack_range;
this->attack_delay=player->information.super_unitMaker_attack_delay;
this->unitType=1;
this->training_time=player->information.super_time_constructoin;
break;
case 2:
this->name=player->information.vehicle_unitMaker_name;
this->cost=player->information.vehicle_unitMaker_cost;
this->upgrade_cost=player->information.vehicle_unitMaker_upgrade_cost;
this->construction_time=player->information.vehicle_unitMaker_time_constructoin;
this->max_health=player->information.vehicle_unitMaker_max_health;
this->attack_damage=player->information.vehicle_unitMaker_attack_damage;
this->attack_range=player->information.vehicle_unitMaker_attack_range;
this->attack_delay=player->information.vehicle_unitMaker_attack_delay;
this->unitType=2;
this->training_time=player->information.vehicle_time_constructoin;
break;
}
health=max_health;
training_progress=0;
queuecount=0;
}
int UnitMaker::getTrainingTime(){
return training_time;
}
bool UnitMaker::trainUnit(QLabel* label){//add unit in queue
if(queuecount>7){
label->show();
label->setText("The unit maker is full");
return false;
}
else{
queuecount++;
int temp_cost=0;
switch (unitType){
case 0:
temp_cost=player->information.normal_cost;
break;
case 1:
temp_cost=player->information.super_cost;
break;
case 2:
temp_cost=player->information.vehicle_cost;
break;
}
if(temp_cost>player->getMoney()){
label->show();
label->setText("Not enough gold");
return false;
}
player->setMoney(-temp_cost);
return true;
}
}
double UnitMaker::getTrainingProgress(){
return training_progress;
}
int UnitMaker::queueCount(){
return queuecount;
}
void UnitMaker::setTrainingTime(int _training_time){
training_time=_training_time;
}
void UnitMaker::setTrainingProgress(double _training_progress){
training_progress+=_training_progress;
}
int UnitMaker::getUnitType(){
return unitType;
}
void UnitMaker::setQueueCount(int n){
queuecount+=n;
}
bool UnitMaker::upgrade(){
if(level >= 3)
return false;
if(unitType==0){
if(player->getMoney() < player->information.unitMaker_upgrade_cost)
return false;
else
player->setMoney( -player->information.unitMaker_upgrade_cost);
}
if(unitType==1){
if(player->getMoney() < player->information.super_unitMaker_upgrade_cost)
return false;
else
player->setMoney( -player->information.super_unitMaker_upgrade_cost);
}
if(unitType==2){
if(player->getMoney() < player->information.vehicle_unitMaker_upgrade_cost)
return false;
else
player->setMoney( -player->information.vehicle_unitMaker_upgrade_cost);
}
level++;
return true;
}
string UnitMaker::getStatus(){
char status[100];
sprintf(status,"this unit Maker have %d unit in queue this time" , queuecount);
return status;
}