parent
98e585bdc9
commit
9f2ce93716
@ -1,14 +1,26 @@
|
|||||||
exe : monstre.o chevalier.o test.o
|
#CC : le compilateur à utiliser
|
||||||
g++ monstre.o chevalier.o test.o -o exe
|
CC=g++
|
||||||
|
|
||||||
monstre.o : monstre.cpp monstre.hpp
|
#CFLAGS : les options de compilation
|
||||||
g++ -c monstre.cpp
|
CFLAGS= -std=c++17 -Wall
|
||||||
|
|
||||||
chevalier.o : chevalier.cpp chevalier.hpp
|
# les fichiers sources : tous les fichiers présents dans src/
|
||||||
g++ -c chevalier.cpp
|
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
|
||||||
|
|
||||||
test.o : test.cpp
|
|
||||||
g++ -c test.cpp
|
|
||||||
|
|
||||||
clean :
|
|
||||||
rm *.o exe
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,18 +0,0 @@
|
|||||||
#include "monstre.hpp"
|
|
||||||
#include <iostream> // cout, endl
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
Monstre::Monstre(string nom, int nbPtsVie, int force)
|
|
||||||
: nom{nom}, nbPtsVie{nbPtsVie}, force{force}
|
|
||||||
{
|
|
||||||
cout << "Monstre " << nom << " créé" << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Monstre::rugir(string message) {
|
|
||||||
cout << "--" << nom << "(" << nbPtsVie << ")" << "-- : " << message << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
Monstre::~Monstre() {
|
|
||||||
cout << "destruction du Monstre" << nom << endl;
|
|
||||||
}
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,45 @@
|
|||||||
|
#include "monstre.hpp"
|
||||||
|
#include "chevalier.hpp"
|
||||||
|
#include <iostream> // cout, endl
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
Monstre::Monstre(string nom, int nbPtsVie, int force)
|
||||||
|
: nom{nom}, nbPtsVie{nbPtsVie}, force{force}
|
||||||
|
{
|
||||||
|
cout << "Monstre " << nom << " créé" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Monstre::rugir(string message) {
|
||||||
|
cout << "--" << nom << "(" << nbPtsVie << ")" << "-- : " << message << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
Monstre::~Monstre() {
|
||||||
|
cout << "destruction du Monstre" << nom << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Monstre::attaquerSournoisement(Chevalier *chevalier) {
|
||||||
|
rugir("Je vais te tuer !");
|
||||||
|
chevalier->subirAttaque(force);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Monstre::attaquerFranchement(Chevalier *chevalier) {
|
||||||
|
rugir("Prends ça " + chevalier->titre);
|
||||||
|
chevalier->subirEtContreAttaquer(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Monstre::subirContreEtAttaquer(Chevalier *chevalier) {
|
||||||
|
nbPtsVie = nbPtsVie - chevalier->puissArme;
|
||||||
|
rugir("Je subit l'attaque !!! Aie");
|
||||||
|
if(nbPtsVie > 0)
|
||||||
|
{
|
||||||
|
attaquerFranchement(chevalier);
|
||||||
|
}
|
||||||
|
else rugir("Je me meurs !! heurg heurg heurg !");
|
||||||
|
}
|
||||||
|
|
||||||
|
Monstre::Monstre()
|
||||||
|
: Monstre{"Mr Inconnu", 15,18}
|
||||||
|
{
|
||||||
|
cout << "Monstre " << nom << " créé" << endl;
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
#include "monstre.hpp"
|
||||||
|
#include "chevalier.hpp"
|
||||||
|
|
||||||
|
void testMonstre(void) {
|
||||||
|
Monstre globulus{"Globulus", 15, 5};
|
||||||
|
Monstre nemo{"Nemo"};
|
||||||
|
globulus.rugir("Tremblez!");
|
||||||
|
nemo.rugir("Vous allez trépasser!");
|
||||||
|
}
|
||||||
|
|
||||||
|
void testChevalier(void) {
|
||||||
|
Chevalier arthur{"Sir Arthur", 160, 90};
|
||||||
|
Chevalier inconnu{16,50};
|
||||||
|
arthur.parler("Hors de ma vu !!!");
|
||||||
|
inconnu.parler("Je suis un inconnu !!!");
|
||||||
|
}
|
||||||
|
|
||||||
|
void testP4(void)
|
||||||
|
{
|
||||||
|
Chevalier sirArthur{"Sir Arthur",3,5};
|
||||||
|
Monstre megadino{"Megadino",15,5};
|
||||||
|
Monstre darkman{"Darkman",2,2};
|
||||||
|
|
||||||
|
sirArthur.parler("Quelle belle journée");
|
||||||
|
|
||||||
|
megadino.attaquerSournoisement(&sirArthur);
|
||||||
|
sirArthur.parler(" eh bien je ne l'avais pas vu venir");
|
||||||
|
|
||||||
|
darkman.attaquerSournoisement(&sirArthur);
|
||||||
|
sirArthur.parler("décidement ...");
|
||||||
|
}
|
||||||
|
|
||||||
|
void testP5(void)
|
||||||
|
{
|
||||||
|
Chevalier sirArthur{"Sir Arthur",3,5};
|
||||||
|
Monstre megadino{"Megadino",15,5};
|
||||||
|
|
||||||
|
sirArthur.parler("Quelle belle journée");
|
||||||
|
megadino.attaquerFranchement(& sirArthur);
|
||||||
|
if(sirArthur.ptsDeVie > 0){
|
||||||
|
sirArthur.parler("J'ai eu chaud");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void testValgrind(void){
|
||||||
|
int *pt;
|
||||||
|
pt = new int[100];
|
||||||
|
delete[] pt;
|
||||||
|
|
||||||
|
Monstre *monstre[5];
|
||||||
|
monstre[0] = new Monstre();
|
||||||
|
monstre[1] = new Monstre();
|
||||||
|
monstre[2]->rugir("RAOOO pas content !!!");
|
||||||
|
// monstre[10]->rugir("Mais ca va aller");
|
||||||
|
delete[] monstre;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void){
|
||||||
|
// test();
|
||||||
|
// testChevalier();
|
||||||
|
// testP4();
|
||||||
|
// testP5();
|
||||||
|
testValgrind();
|
||||||
|
return 0;
|
||||||
|
}
|
@ -1,22 +0,0 @@
|
|||||||
#include "monstre.hpp"
|
|
||||||
#include "chevalier.hpp"
|
|
||||||
|
|
||||||
void testMonstre(void) {
|
|
||||||
Monstre globulus{"Globulus", 15, 5};
|
|
||||||
Monstre nemo{"Nemo"};
|
|
||||||
globulus.rugir("Tremblez!");
|
|
||||||
nemo.rugir("Vous allez trépasser!");
|
|
||||||
}
|
|
||||||
|
|
||||||
void testChevalier(void) {
|
|
||||||
Chevalier arthur{"Sir Arthur", 160, 90};
|
|
||||||
Chevalier inconnu{16,50};
|
|
||||||
arthur.parler("Hors de ma vu !!!");
|
|
||||||
inconnu.parler("Je suis un inconnu !!!");
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void){
|
|
||||||
// test();
|
|
||||||
testChevalier();
|
|
||||||
return 0;
|
|
||||||
}
|
|
Binary file not shown.
Loading…
Reference in new issue