Correction du chargement du niveau
This commit is contained in:
parent
0ea89bdd09
commit
724ba4cf7d
|
@ -1,5 +1,5 @@
|
|||
#ifndef __PTF_GAME_HPP__
|
||||
#define __PTF_GAME_HPP__
|
||||
#ifndef __PTF_EDITOR_HPP__
|
||||
#define __PTF_EDITOR_HPP__
|
||||
|
||||
#include "level.hpp"
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <iostream>
|
||||
#include "manager.hpp"
|
||||
#include "game.hpp"
|
||||
#include "editor.hpp"
|
||||
#include "view.hpp"
|
||||
#include "resource_manager.hpp"
|
||||
#include <vector>
|
||||
|
@ -12,7 +13,7 @@
|
|||
#define NB_LVL_CHOICES 3
|
||||
|
||||
/**
|
||||
* La classe Lvl_menu charge le menu permettant de
|
||||
* La classe Lvl_menu charge le menu permettant de
|
||||
* choisir le niveau auquel l'utilisateur souhaite
|
||||
* jouer.
|
||||
*/
|
||||
|
@ -24,11 +25,11 @@ public:
|
|||
|
||||
/**
|
||||
* Dessine le menu de niveaux
|
||||
*/
|
||||
*/
|
||||
void frame();
|
||||
|
||||
/**
|
||||
* Permet de changer le choix sélectionné
|
||||
* Permet de changer le choix sélectionné
|
||||
*/
|
||||
void MoveUp();
|
||||
void MoveDown();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "lvl_menu.hpp"
|
||||
|
||||
Lvl_menu::Lvl_menu(Manager& manager) : View(manager){
|
||||
|
||||
|
||||
//mise en place des propriétés des textes affichés dans le menu
|
||||
choice[0].setFont(manager.getResourceManager().getFont("Raleway-Regular.ttf"));
|
||||
choice[0].setColor(sf::Color::Red);
|
||||
|
@ -18,7 +18,7 @@ Lvl_menu::Lvl_menu(Manager& manager) : View(manager){
|
|||
choice[2].setString("Niveau 2");
|
||||
|
||||
//choix sélectionné à l'ouverture du menu
|
||||
selection = 0;
|
||||
selection = 0;
|
||||
}
|
||||
|
||||
Lvl_menu::~Lvl_menu(){
|
||||
|
@ -26,7 +26,7 @@ Lvl_menu::~Lvl_menu(){
|
|||
|
||||
|
||||
void Lvl_menu::MoveUp()
|
||||
{
|
||||
{
|
||||
//change la couleur du choix sélectionné
|
||||
if(selection-1 >= 0)
|
||||
{
|
||||
|
@ -52,37 +52,36 @@ void Lvl_menu::frame(){
|
|||
window.clear(sf::Color(66, 40, 245));
|
||||
|
||||
const std::vector<sf::Event>& events = manager.getEvents();
|
||||
|
||||
|
||||
for (unsigned int i = 0; i < events.size(); i++) {
|
||||
const sf::Event& event = events[i];
|
||||
|
||||
|
||||
// gestion des touches
|
||||
if (event.type == sf::Event::KeyPressed) {
|
||||
if (event.key.code == sf::Keyboard::Up) {
|
||||
MoveUp();
|
||||
}
|
||||
|
||||
if (event.key.code == sf::Keyboard::Down) {
|
||||
MoveDown();
|
||||
}
|
||||
if (event.key.code == sf::Keyboard::Return) {
|
||||
//si on choisit "tutoriel", on charge le niveau
|
||||
//tutoriel et la vue se met sur Game
|
||||
if(selection==0){
|
||||
std::shared_ptr<Editor> editor = std::shared_ptr<Editor>(new Editor(manager));
|
||||
try {
|
||||
// ouverture du niveau
|
||||
std::ifstream file;
|
||||
file.open("./levels/level1.dat", std::ios::binary | std::ios::in);
|
||||
editor->load(file);
|
||||
file.close();
|
||||
|
||||
} catch (const std::exception& exception) {
|
||||
std::cerr << "Le programme a quitté après une erreur d'exécution." << std::endl;
|
||||
std::cerr << exception.what() << std::endl;
|
||||
}
|
||||
std::shared_ptr<View> game = std::shared_ptr<View>(new Game(manager));
|
||||
manager.setView(game);
|
||||
if (event.key.code == sf::Keyboard::Return) {
|
||||
std::shared_ptr<Game> game = std::shared_ptr<Game>(new Game(manager));
|
||||
std::string path;
|
||||
|
||||
switch (selection) {
|
||||
case 0:
|
||||
path = "./levels/level1.dat";
|
||||
break;
|
||||
}
|
||||
|
||||
std::ifstream file;
|
||||
file.open(path, std::ios::binary | std::ios::in);
|
||||
game->load(file);
|
||||
file.close();
|
||||
|
||||
manager.setView(game);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -94,4 +93,3 @@ void Lvl_menu::frame(){
|
|||
window.display();
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue