parent
9f2ce93716
commit
86004a74a1
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1 +0,0 @@
|
|||||||
#include "1_tp.hpp"
|
|
@ -1,5 +0,0 @@
|
|||||||
class {
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
};
|
|
@ -1,7 +0,0 @@
|
|||||||
#include "1_tp.hpp"
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
Binary file not shown.
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"iostream": "cpp"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
#CC : le compilateur à utiliser
|
||||||
|
CC=g++
|
||||||
|
|
||||||
|
#CFLAGS : les options de compilation
|
||||||
|
CFLAGS= -std=c++17 -Wall
|
||||||
|
|
||||||
|
# les fichiers sources : tous les fichiers présents dans src/
|
||||||
|
SRC=$(wildcard src/*.cpp)
|
||||||
|
|
||||||
|
# les fichiers objets (.o)
|
||||||
|
OBJ=$(patsubst src/%.cpp,obj/%.o,$(SRC))
|
||||||
|
|
||||||
|
|
||||||
|
#edition des liens : génération de l'exécutable à partir des .o
|
||||||
|
bin/exe: $(OBJ)
|
||||||
|
$(CC) $(OBJ) -o $@
|
||||||
|
|
||||||
|
# génération des .o à partir des .cpp et .hpp crrespondants :
|
||||||
|
obj/%.o: src/%.cpp
|
||||||
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
#nettoyage : destruction des .o et de l'exécutable
|
||||||
|
clean:
|
||||||
|
rm obj/*.o bin/exe
|
||||||
|
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,37 @@
|
|||||||
|
#include "de.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
namespace jeu {
|
||||||
|
|
||||||
|
De::De(int nbFaces)
|
||||||
|
:nbFaces{nbFaces}, valeur{0}
|
||||||
|
{
|
||||||
|
srand(time(nullptr));
|
||||||
|
};
|
||||||
|
|
||||||
|
De::De()
|
||||||
|
: De{6}
|
||||||
|
{
|
||||||
|
srand(time(nullptr));
|
||||||
|
};
|
||||||
|
|
||||||
|
int De::getValeur() {
|
||||||
|
if(valeur == 0){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return valeur;
|
||||||
|
};
|
||||||
|
|
||||||
|
int De::lancer() {
|
||||||
|
valeur = rand() % nbFaces + 1;
|
||||||
|
return valeur;
|
||||||
|
};
|
||||||
|
|
||||||
|
void De::effacer() {
|
||||||
|
valeur = 0;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,23 @@
|
|||||||
|
#ifndef DE_HPP
|
||||||
|
#define DE_HPP
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace jeu {
|
||||||
|
|
||||||
|
class De {
|
||||||
|
private:
|
||||||
|
int nbFaces;
|
||||||
|
int valeur;
|
||||||
|
public:
|
||||||
|
De(int nbFaces);
|
||||||
|
De();
|
||||||
|
int getValeur();
|
||||||
|
int lancer();
|
||||||
|
void effacer();
|
||||||
|
};
|
||||||
|
|
||||||
|
} //namespace jeu
|
||||||
|
|
||||||
|
|
||||||
|
#endif // DE_HPP
|
@ -0,0 +1,49 @@
|
|||||||
|
#include "joueur.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace jeu;
|
||||||
|
|
||||||
|
namespace jeu {
|
||||||
|
int Joueur::numJoueur = 0;
|
||||||
|
|
||||||
|
Joueur::Joueur(string nom)
|
||||||
|
:nom{nom}, scoreTotal{0}, scoreCourant{0}
|
||||||
|
{}
|
||||||
|
|
||||||
|
Joueur::Joueur()
|
||||||
|
:Joueur{"Joueur" + numJoueur}
|
||||||
|
{}
|
||||||
|
|
||||||
|
string Joueur::getNom() const {
|
||||||
|
return nom;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Joueur::getScoreCourant() const{
|
||||||
|
return scoreCourant;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Joueur::getScoreTotal() const{
|
||||||
|
return scoreTotal;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Joueur::ajouterAuScoreCourant(int delta) {
|
||||||
|
scoreCourant += delta;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Joueur::effacerScoreCourant() {
|
||||||
|
scoreCourant = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Joueur::ajouterAuScoreTotal(int delta) {
|
||||||
|
scoreTotal += delta;
|
||||||
|
}
|
||||||
|
void Joueur::effacerScores() {
|
||||||
|
scoreTotal = 0;
|
||||||
|
}
|
||||||
|
} // fin du namspace jeu
|
||||||
|
|
||||||
|
ostream &operator<<(ostream &s, const jeu::Joueur &j) {
|
||||||
|
s << "Le joueur " << j.getNom() << " possede un score courant de " << j.getScoreCourant() << " et un score de " << j.getScoreTotal() << endl;
|
||||||
|
return s;
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
#ifndef JOUEUR_HPP
|
||||||
|
#define JOUEUR_HPP
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace jeu {
|
||||||
|
|
||||||
|
class Joueur {
|
||||||
|
private:
|
||||||
|
static int numJoueur;
|
||||||
|
std::string nom;
|
||||||
|
int scoreTotal;
|
||||||
|
int scoreCourant;
|
||||||
|
public:
|
||||||
|
Joueur(std::string nom);
|
||||||
|
Joueur();
|
||||||
|
|
||||||
|
std::string getNom() const;
|
||||||
|
int getScoreCourant() const;
|
||||||
|
int getScoreTotal() const;
|
||||||
|
|
||||||
|
void ajouterAuScoreCourant(int delta);
|
||||||
|
void effacerScoreCourant();
|
||||||
|
void ajouterAuScoreTotal(int delta);
|
||||||
|
void effacerScores();
|
||||||
|
};
|
||||||
|
|
||||||
|
} //namespace jeu
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &s, const jeu::Joueur &j);
|
||||||
|
|
||||||
|
#endif // JOUEUR_HPP
|
@ -0,0 +1,14 @@
|
|||||||
|
#include "de.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
namespace jeu {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // fin du namespace jeu
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,20 @@
|
|||||||
|
#ifndef PARTIE_HPP
|
||||||
|
#define PARTIE_HPP
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace jeu {
|
||||||
|
constexpr int valeurPerte{1};
|
||||||
|
constexpr int scoreVictoire{100};
|
||||||
|
|
||||||
|
class Partie {
|
||||||
|
private:
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} //namespace jeu
|
||||||
|
|
||||||
|
|
||||||
|
#endif // PARTIE_HPP
|
@ -0,0 +1,59 @@
|
|||||||
|
#include "de.hpp"
|
||||||
|
#include "partie.hpp"
|
||||||
|
#include "joueur.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace jeu;
|
||||||
|
|
||||||
|
void testDe(void){
|
||||||
|
De de6faces{};
|
||||||
|
De de12faces{12};
|
||||||
|
cout << "valeur du dé a 6 faces : " << de6faces.getValeur() << endl;
|
||||||
|
cout << "valeur du dé a 12 faces : " << de12faces.getValeur() << endl;
|
||||||
|
de6faces.lancer();
|
||||||
|
de12faces.lancer();
|
||||||
|
cout << "valeur du dé a 6 faces : " << de6faces.getValeur() << endl;
|
||||||
|
cout << "valeur du dé a 12 faces : " << de12faces.getValeur() << endl;
|
||||||
|
de6faces.effacer();
|
||||||
|
de12faces.effacer();
|
||||||
|
cout << "valeur du dé a 6 faces : " << de6faces.getValeur() << endl;
|
||||||
|
cout << "valeur du dé a 12 faces : " << de12faces.getValeur() << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void testJoueur(void){
|
||||||
|
Joueur joueur{};
|
||||||
|
Joueur marc{"marc"};
|
||||||
|
cout << joueur << endl;
|
||||||
|
cout << marc << endl;
|
||||||
|
joueur.ajouterAuScoreCourant(50);
|
||||||
|
marc.ajouterAuScoreCourant(50);
|
||||||
|
cout << joueur << endl;
|
||||||
|
cout << marc << endl;
|
||||||
|
joueur.ajouterAuScoreCourant(150);
|
||||||
|
marc.ajouterAuScoreCourant(150);
|
||||||
|
cout << joueur << endl;
|
||||||
|
cout << marc << endl;
|
||||||
|
joueur.ajouterAuScoreTotal(50);
|
||||||
|
marc.ajouterAuScoreTotal(50);
|
||||||
|
cout << joueur << endl;
|
||||||
|
cout << marc << endl;
|
||||||
|
joueur.ajouterAuScoreTotal(150);
|
||||||
|
marc.ajouterAuScoreTotal(150);
|
||||||
|
cout << joueur << endl;
|
||||||
|
cout << marc << endl;
|
||||||
|
joueur.effacerScoreCourant();
|
||||||
|
marc.effacerScoreCourant();
|
||||||
|
cout << joueur << endl;
|
||||||
|
cout << marc << endl;
|
||||||
|
joueur.effacerScores();
|
||||||
|
marc.effacerScores();
|
||||||
|
cout << joueur << endl;
|
||||||
|
cout << marc << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void){
|
||||||
|
// testDe();
|
||||||
|
testJoueur();
|
||||||
|
return 0;
|
||||||
|
}
|
Binary file not shown.
Loading…
Reference in new issue