-
Notifications
You must be signed in to change notification settings - Fork 0
/
annexe.cpp
116 lines (89 loc) · 2.75 KB
/
annexe.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
//
// Created by Athena on 13.12.2022.
//
#include "annexe.h"
#include <random>
#include <iostream>
using namespace std;
int aleatoire(int min, int max){
std::random_device aleatoire_mac;
std::default_random_engine generateur(aleatoire_mac());
std::uniform_int_distribution<int> distr(min, max);
return(distr(generateur));
}
void cleanCin(){
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "Please enter a correct value : " << endl;
}
void Terrain::classUserEntry() {
int X, Y, nbRobotInput;
const int VALMIN = 10;
const int VALMAX = 10000;
const int ROBOTSMIN = 1;
const int ROBOTSMAX = 10;
X = userEntry(VALMIN,VALMAX,"width [10..1000] :");
Y = userEntry(VALMIN,VALMAX,"height [10..1000] :");
nbRobotInput = userEntry(ROBOTSMIN, ROBOTSMAX, "nbr of objects [1..10] :");
width = X+1;
height = Y+1;
nbrRobots = size_t(nbRobotInput);
}
int Terrain::getHeight() const {
return height;
}
int Terrain::getWidth() const {
return width;
}
size_t Terrain::getnbrRobots() const {
return nbrRobots;
}
void display(int terrainHeight, int terrainWidth, std::vector<Robot>& vecRobot){
bool robotPrint = false;
system("cls");
for (int h = 0; h <= terrainHeight; ++h) {
for (int l = 0; l <= terrainWidth; ++l) {
if(h==0 or h == terrainHeight){
cout << "-";
}
else if (l==0 or l == terrainWidth){
cout << "|";
}
else{
for (Robot& robot : vecRobot) {
if (robot.getCoordX() == l and robot.getCoordY() == h) {
cout << robot.getID();
robotPrint = true;
}
}
if(!robotPrint) {
cout << " ";
}
else{
robotPrint = false;
}
}
}
cout << endl;
}
sort( vecRobot.begin(), vecRobot.end(), [](const Robot &a, const Robot &b){ return (a.getID() < b.getID());});
cout << endl;
for (Robot& robot : vecRobot) {
if(robot.isDead())
cout << "The robot " << robot.getKiller() << " killed robot " << robot.getID() << endl;
}
}
int userEntry(const int min, const int max, std::string message){
cout << message << endl;
int x;
bool flxError = false;
do{
cin >> x;
if (cin.fail() or x < min or x > max) {
cleanCin();
flxError = true;
continue;
}
}while(flxError);
return x;
}