Repository navigation
Expand file tree
/
Copy pathCombat.cpp
More file actions
81 lines (66 loc) · 1.53 KB
/
Copy pathCombat.cpp
File metadata and controls
81 lines (66 loc) · 1.53 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
/**
* @file combat.cpp
* @author A.EVOLA N.PROSPERT
* @since
* @brief implémentation des méthodes de la classe Combat
*
**/
#include <iostream>
#include <stdlib.h> /* srand, rand */
#include <cmath> /* abs */
#include "Combat.h"
//---------------------------------------------------------------------
//---------------------------------------------------------------------
Combat::Combat(Jeu jeu, Joueur joueur)
{
Etape::Etape(jeu,joueur);
}
void Combat::finCombat()
{
_jeu.setEtape(_jeu.getEtapeRenforcement());
_jeu.afficher();
}
void Combat::afficher()
{
std::cout << "Etape 2 : Combat\n";
}
void Combat::simulation(Pays att, Pays def)
{
int resDe, maxDeAtt, minDeAtt, maxDeDef, minDeDef, nbLancersDe;
cout << "Selectionner le nombre de lancers de dé pour attaquer\n";
cin >> nbLancersDe;
for (int i = 0; i<nbLancersDe; ++i)
{
resDe = rand()%6;
if (maxDeAtt < resDe)
maxDeAtt = resDe;
if (minDeAtt < resDe)
minDeAtt = resDe;
}
cout << "Selectionner le nombre de lancers de dé pour se défendre\n";
cin >> nbLancersDe;
for (int i = 0; i<nbLancersDe; ++i)
{
resDe = rand()%6;
if (maxDeDef < resDe)
maxDeDef = resDe;
if (minDeDef < resDe)
minDeDef = resDe;
}
int mortsAtt = 0, mortsDef = 0;
if(maxDeAtt>maxDeDef)
++ mortsDef;
else
++ mortsAtt;
if(minDeAtt>minDeDef)
++ mortsDef;
else
++ mortsAtt;
att.perteDeTroupes(mortsAtt);
def.perteDeTroupes(mortDef);
if (def.getNbTroupes() <= 0)
{
def.ChangementControle(joueur_.getId(), 3);
att.perteDeTroupes(3-mortsAtt);
}
}