Commit a3df0af1 authored by Francois Foltete's avatar Francois Foltete
Browse files

Student Factory

parent c3e26299
#ifndef STUDENTFACTORY
#define STUDENTFACTORY
#include <istream>
#include <map>
#include <string>
#include <vector>
#include "Game.h"
#include "model/Student.h"
/** @brief Classe permettant de génerer des noms pour les élèves */
class StudentFactory{
private:
/**
* @brief liste de élèves
*
*/
static std::vector<Student *> studentFactory;
/**
* @brief nom du fichier
*
*/
static std::string filename;
/**
* @brief Get the Next Line And Split Into Tokens object
*
* @param str input stream
* @return std::vector<std::string> ligne de string contenant les infos
*/
static std::vector<std::string> getNextLineAndSplitIntoTokens(std::istream& stream);
public:
StudentFactory() = delete;
~StudentFactory();
static void loadStudentFactory();
static Student * getRandomStudent();
};
#endif /* STUDENTFACTORY_H */
\ No newline at end of file
......@@ -7,18 +7,18 @@
class Actor : public Texturable {
private:
std::string name;
std::string firstname;
std::string surname;
public:
/**
* @brief Crée un personnage.
*
* @param name le prénom du personnage
* @param firstname le prénom du personnage
* @param surname le nom de famille du personnage
* @param texturePath le chemin du fichier de texture
*/
Actor(const std::string &name, const std::string &surname,
Actor(const std::string &firstname, const std::string &surname,
const std::string &texturePath);
/**
......@@ -26,14 +26,14 @@ class Actor : public Texturable {
*
* @return std::string le prénom du personnage
*/
const std::string &getName() const { return name; }
const std::string &getFirstName() const { return firstname; }
/**
* @brief Modifie le prénom du personnage.
*
* @param name le nouveau prénom du personnage
*/
void setName(const std::string &name) { this->name = name; }
void setFirstName(const std::string &firstname) { this->firstname = firstname; }
/**
* @brief Renvoie le nom de famille du personnage
......
......@@ -31,13 +31,13 @@ class Student : public Actor {
/**
* @brief Construct a new Student object
*
* @param name prénom de l'élève
* @param firstname prénom de l'élève
* @param surname nom de famille de l'élève
* @param mood Humeur de l'élève
* @param motivation Motivation de l'élève
* @param skill Qualité de l'élève
*/
Student(const std::string &name, const std::string &surname, double mood,
Student(const std::string &firstname, const std::string &surname, double mood,
double motivation, double skill);
~Student();
......
......@@ -24,12 +24,12 @@ class Teacher : public Actor {
/**
* @brief Construct un nouveau Professeur
*
* @param name Prénom du professeur
* @param firstname Prénom du professeur
* @param surname Nom de famille du professeur
* @param pedagogie Niveau de pédagogie du professeur
* @param meritocratic Niveau de méritocratie du professeur
*/
Teacher(const std::string &name, const std::string &surname,
Teacher(const std::string &firstname, const std::string &surname,
double pedagogie, double meritocratic);
/**
......
---,ID,Name,Surname,Mood,Skill,Motivation
Eleve_0,0,Knutur,Arthur,5,6,7
Eleve_1,1,Dodeman,Amorgen,3,8,3
Eleve_2,2,Gounouf,Cathal,2,2,2
Eleve_3,3,Juleson,Cesar,4,4,6
Eleve_4,4,Helgi,Felix,7,3,7
Eleve_5,5,Hjalmarsson,Kane,9,7,7
Eleve_6,6,Bjarnason,Lucan,10,3,9
Eleve_7,7,Arnason,Agate,7,5,5
Eleve_8,8,Kristoffersen,Aveleen,4,7,4
Eleve_9,9,Helguson ,Cordelia,3,5,2
Eleve_10,10,Osmond,Cleena,6,6,6
Eleve_11,11,Hansen,Cleophee,4,2,9
Eleve_12,12,Toeframathurinn,Merlin,8,4,5
Eleve_13,13,Bryndisarson ,Sachka,7,3,7
Eleve_14,14,Turrou,Audric,3,8,2
Eleve_15,15,Renouf,Arwen,5,5,5
Eleve_16,16,Alfur,Gauvain,4,8,6
Eleve_17,17,Asgrimsson,Arya,1,1,1
Eleve_18,18,Inguier,Cirdan,2,3,2
Eleve_19,19,Eriksson,Valar,6,5,4
Eleve_20,20,Yngouf,Matan,7,6,7
Eleve_21,21,Varangot,Olaf,2,6,2
Eleve_22,22,Aze,Leif,5,4,9
Eleve_23,23,Ernouf,Bjarne,2,4,5
Eleve_24,24,Kirkegaard,Gandalf,10,6,4
Eleve_25,25,Persson,Markus,4,5,6
Eleve_26,26,Foutete,Franco,3,5,10
Eleve_27,27,Ovenn,Piro,6,4,7
Eleve_28,28,Leinfebr,Lias,5,4,7
Eleve_29,29,Miglagla,Yonn,4,3,5
Eleve_30,30,Voyaar,Mateu,3,7,5
Eleve_31,31,Gulbrandsen,Egill,4,3,5
Eleve_32,32,Jespersen,Marcus,10,9,10
Eleve_33,33,Jakobsen,Frederik,4,6,5
Eleve_34,34,Mortensen,Alexander,6,5,8
Eleve_35,35,Norgaard,Rasmus,4,5,6
Eleve_36,36,Gregersen,Nicolai,8,5,6
Eleve_37,37,Andersen,Alberte,4,6,8
Eleve_38,38,Johansen,Oskar,6,5,3
Eleve_39,39,Kristensen,Mark,7,5,5
Eleve_40,40,Jespersen,Rosa,8,5,6
0,Knutur,Arthur,5,6,7
1,Dodeman,Amorgen,3,8,3
2,Gounouf,Cathal,2,2,2
3,Juleson,Cesar,4,4,6
4,Helgi,Felix,7,3,7
5,Hjalmarsson,Kane,9,7,7
6,Bjarnason,Lucan,10,3,9
7,Arnason,Agate,7,5,5
8,Kristoffersen,Aveleen,4,7,4
9,Helguson,Cordelia,3,5,2
10,Osmond,Cleena,6,6,6
11,Hansen,Cleophee,4,2,9
12,Toeframathurinn,Merlin,8,4,5
13,Bryndisarson,Sachka,7,3,7
14,Turrou,Audric,3,8,2
15,Renouf,Arwen,5,5,5
16,Alfur,Gauvain,4,8,6
17,Asgrimsson,Arya,1,1,1
18,Inguier,Cirdan,2,3,2
19,Eriksson,Valar,6,5,4
20,Yngouf,Matan,7,6,7
21,Varangot,Olaf,2,6,2
22,Aze,Leif,5,4,9
23,Ernouf,Bjarne,2,4,5
24,Kirkegaard,Gandalf,10,6,4
25,Persson,Markus,4,5,6
26,Foutete,Franco,3,5,10
27,Ovenn,Piro,6,4,7
28,Leinfebr,Lias,5,4,7
29,Miglagla,Yonn,4,3,5
30,Voyaar,Mateu,3,7,5
31,Gulbrandsen,Egill,4,3,5
32,Jespersen,Marcus,10,9,10
33,Jakobsen,Frederik,4,6,5
34,Mortensen,Alexander,6,5,8
35,Norgaard,Rasmus,4,5,6
36,Gregersen,Nicolai,8,5,6
37,Andersen,Alberte,4,6,8
38,Johansen,Oskar,6,5,3
39,Kristensen,Mark,7,5,5
40,Jespersen,Rosa,8,5,6
#include <algorithm>
#include <assert.h>
#include <fstream>
#include <random>
#include <sstream>
#include <stdlib.h>
#include "controller/StudentFactory.h"
#include "model/Student.h"
std::vector<Student *> StudentFactory::studentFactory;
std::string StudentFactory::filename(RESOURCES_FOLDER "actors/DataStudents.csv");
std::vector<std::string> StudentFactory::getNextLineAndSplitIntoTokens(std::istream& stream){
std::vector<std::string> result;
std::string line;
std::getline(stream,line);
std::stringstream lineStream(line);
std::string cell;
while(std::getline(lineStream,cell, ','))
{
result.push_back(cell);
}
// This checks for a trailing comma with no data after it.
if (!lineStream && cell.empty())
{
// If there was a trailing comma then add an empty element.
result.push_back("");
}
return result;
}
void StudentFactory::loadStudentFactory(){
// ouvre le fichier
std::ifstream ifs (filename,std::ifstream::in);
std::vector<std::string> studentline;
while( ifs.good()){
studentline = getNextLineAndSplitIntoTokens(ifs);
if( studentline.size() == 6)
studentFactory.push_back(new Student(studentline[1],studentline[2],atof(studentline[3].c_str()),atof(studentline[4].c_str()),atof(studentline[5].c_str())));
}
ifs.close();
auto rng = std::default_random_engine{};
std::shuffle(std::begin(studentFactory), std::end(studentFactory),rng);
}
Student * StudentFactory::getRandomStudent(){
assert(!studentFactory.empty());
Student * rndstudent = studentFactory.back(); // la liste est mélangé point
studentFactory.pop_back();
return rndstudent;
}
StudentFactory::~StudentFactory(){
while (!studentFactory.empty()) {
delete studentFactory.back();
studentFactory.pop_back();
}
}
\ No newline at end of file
......@@ -2,10 +2,10 @@
#include "model/Actor.h"
Actor::Actor(const std::string &name, const std::string &surname,
Actor::Actor(const std::string &firstname, const std::string &surname,
const std::string &texturePath)
: Texturable(texturePath)
, name(name)
, firstname(firstname)
, surname(surname)
{
}
......@@ -4,9 +4,9 @@
#include "model/Actor.h"
#include "model/Student.h"
Student::Student(const std::string &name, const std::string &surname,
Student::Student(const std::string &firstname, const std::string &surname,
double mood, double motivation, double skill)
: Actor(name, surname, "resources/images/eleves/eleve_garcon1.png")
: Actor(firstname, surname, "resources/images/eleves/eleve_garcon1.png")
, mood(mood)
, motivation(motivation)
, skill(skill)
......
......@@ -3,9 +3,9 @@
#include "model/Actor.h"
#include "model/Teacher.h"
Teacher::Teacher(const std::string &name, const std::string &surname,
Teacher::Teacher(const std::string &firstname, const std::string &surname,
double pedagogie, double meritocratic)
: Actor(name, surname, "resources/images/profs/prof1.png")
: Actor(firstname, surname, "resources/images/profs/prof1.png")
, pedagogue(pedagogie)
, meritocratic(meritocratic)
{
......
......@@ -8,15 +8,24 @@
#include "imgui/imgui.h"
#include "controller/Game.h"
#include "controller/StudentFactory.h"
#include "view/MainView.h"
#include "view/Utils.h"
#define NB_STUDENT 10
MainView::MainView()
: school(new School("L'école infernale"))
{
Classroom *g12 = new Classroom(1, new Teacher("H.", "Julien", 70, 40));
g12->addStudent(new Student("de Noel", "Golden", 80, 70, 70));
Classroom *g12 = new Classroom(1, new Teacher("Julien", "H.", 70, 40));
g12->addStudent(new Student("Golden", "de Noel", 80, 70, 70));
school->addClass(g12);
// ajout élèves
StudentFactory::loadStudentFactory();
for(int i(0);i< NB_STUDENT;i++){
g12->addStudent(StudentFactory::getRandomStudent());
std::cout << g12->getStudents().back()->getFirstName() << std::endl;
}
}
MainView::~MainView()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment