-
Notifications
You must be signed in to change notification settings - Fork 1
/
Robot.cpp
105 lines (87 loc) · 1.92 KB
/
Robot.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
#include <exception>
#include "Robot.h"
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
void Robot::avancer(int x, int y) {
std::stringstream sstm;
sstm << "avancer(" << x << ", " << y << ")";
_dernierOrdreRecu = sstm.str();
_etat = _etat->avancer();
_position.setX(x);
_position.setY(y);
afficher();
}
void Robot::tourner(string d) {
std::stringstream sstm;
sstm << "tourner(" << d << ")";
_dernierOrdreRecu = sstm.str();
_etat = _etat->tourner();
_direction = d;
_plot = 0;
afficher();
}
void Robot::saisir(Objet o) {
std::stringstream sstm;
sstm << "saisir(" << o << ")";
_dernierOrdreRecu = sstm.str();
_etat = _etat->saisir();
_objet = &o;
afficher();
}
void Robot::poser() {
_dernierOrdreRecu = "poser()";
_etat = _etat->poser();
_objet = 0;
afficher();
}
int Robot::peser() {
_dernierOrdreRecu = "peser()";
_etat = _etat->peser();
afficher();
return _objet->getPoids();
}
void Robot::rencontrerPlot(Plot p) {
std::stringstream sstm;
sstm << "rencontrerPlot(" << p << ")";
_dernierOrdreRecu = sstm.str();
_etat = _etat->rencontrerPlot();
_plot = &p;
afficher();
}
int Robot::evaluerPlot(){
_dernierOrdreRecu = "evaluerPlot()";
_etat = _etat->evaluerPlot();
afficher();
return _plot->getHauteur();
}
void Robot::figer() {
_dernierOrdreRecu = "figer()";
_etat = _etat->figer();
afficher();
}
void Robot::repartir() {
_dernierOrdreRecu = "repartir()";
_etat = _etat->repartir();
afficher();
}
void Robot::afficher() {
notify();
}
void Robot::notify()
{
for (int i = 0; i < _listObservers.size(); i++)
_listObservers[i]->update();
}
void Robot::attach(Observer* obs)
{
_listObservers.push_back(obs);
}
void Robot::detach(Observer* obs)
{
//NOPE
}
string Robot::getDernierOrdre(){
return _dernierOrdreRecu;
}