Classroom.cpp 2.38 KB
Newer Older
1
2
3
4
5
#include <cstring>
#include <iostream>

#include <SFML/OpenGL.hpp>

6
7
8
#include "imgui/imgui-SFML.h"
#include "imgui/imgui.h"

9
#include "controller/StudentFactory.h"
10
11
#include "model/Classroom.h"
#include "model/Student.h"
matthieu.berg's avatar
matthieu.berg committed
12
#include "model/Subject.h"
13
#include "model/Teacher.h"
14

15
16
#define NB_STUDENTS 5

Elias Leinenweber's avatar
Elias Leinenweber committed
17
18
19
20
21
22
23
24
static ImTextureID
convertGLTextureHandleToImTextureID(GLuint glTextureHandle)
{
    ImTextureID textureID = (ImTextureID)NULL;
    std::memcpy(&textureID, &glTextureHandle, sizeof(GLuint));
    return textureID;
}

25
26
ImGuiID Classroom::lastID = 0;

Elias Leinenweber's avatar
Elias Leinenweber committed
27
28
29
30
Classroom::Classroom(int n, Teacher *teacher)
  : Texturable("resources/images/salles/salle" + std::to_string(n) + ".png")
  , teacher(teacher)
{
31
32
    for (int i = 1; i <= NB_STUDENTS; ++i)
        addStudent(StudentFactory::getRandomStudent());
Elias Leinenweber's avatar
Elias Leinenweber committed
33
34
}

35
void
36
Classroom::render()
37
{
38
39
40
41
    ImVec2 size(ImGui::GetIO().DisplaySize.x / 2.25,
                ImGui::GetIO().DisplaySize.y / 2.25);
    if (ImGui::BeginChild(Game::getComponentID(), size, true,
                          ImGuiWindowFlags_NoBackground)) {
42
43
44
45
46
        ImGui::GetBackgroundDrawList()->AddImage(
          convertGLTextureHandleToImTextureID(texture.getNativeHandle()),
          ImGui::GetWindowPos(),
          ImVec2(ImGui::GetWindowPos().x + ImGui::GetContentRegionAvail().x,
                 ImGui::GetWindowPos().y + ImGui::GetContentRegionAvail().y));
47
        if (ImGui::Button("Examen")) {
matthieu.berg's avatar
matthieu.berg committed
48
49
            examen();
        }
50
        ImGui::SameLine();
51
        ImGui::Dummy(ImVec2(0., 120.));
52
        teacher->render();
53
54
        ImGui::SameLine();
        ImGui::Dummy(ImVec2(100., 20.));
55
        for (Student *student : students) {
56
            ImGui::SameLine();
57
            student->render();
58
        }
59
60
    }
    ImGui::EndChild();
61
62
63
64
65
66
67
68
69
70
}

Classroom::~Classroom()
{
    while (!students.empty()) {
        delete students.back();
        students.pop_back();
    }
    delete teacher;
}
matthieu.berg's avatar
matthieu.berg committed
71
72
73
74
75

void
Classroom::examen() const
{
    double grade;
76
77
78
79
80
81
82
83
    for (Student *s : students) {
        grade = (teacher->getMeritocratic() * s->getSkill()) / 10 +
                (teacher->getPedagogue() * s->getMotivation()) /
                  10; // note sur 20 en fonction du skill et de la motivation de
                      // l'élève et du type d'enseignement du prof
        grade +=
          s->getMood() *
          0.2; // entre 0 et 2 points bonus en fonction du mood de l'élève
Elias Leinenweber's avatar
Elias Leinenweber committed
84
        s->addGrades(Subject::getMaths(), grade);
matthieu.berg's avatar
matthieu.berg committed
85
    }
86
}