Correction du chargement du niveau

This commit is contained in:
Mattéo Delabre 2016-04-06 20:04:28 +02:00
parent 0ea89bdd09
commit 724ba4cf7d
3 changed files with 27 additions and 28 deletions

View File

@ -1,5 +1,5 @@
#ifndef __PTF_GAME_HPP__ #ifndef __PTF_EDITOR_HPP__
#define __PTF_GAME_HPP__ #define __PTF_EDITOR_HPP__
#include "level.hpp" #include "level.hpp"

View File

@ -5,6 +5,7 @@
#include <iostream> #include <iostream>
#include "manager.hpp" #include "manager.hpp"
#include "game.hpp" #include "game.hpp"
#include "editor.hpp"
#include "view.hpp" #include "view.hpp"
#include "resource_manager.hpp" #include "resource_manager.hpp"
#include <vector> #include <vector>

View File

@ -61,31 +61,30 @@ void Lvl_menu::frame(){
if (event.key.code == sf::Keyboard::Up) { if (event.key.code == sf::Keyboard::Up) {
MoveUp(); MoveUp();
} }
if (event.key.code == sf::Keyboard::Down) { if (event.key.code == sf::Keyboard::Down) {
MoveDown(); MoveDown();
} }
if (event.key.code == sf::Keyboard::Return) { if (event.key.code == sf::Keyboard::Return) {
//si on choisit "tutoriel", on charge le niveau std::shared_ptr<Game> game = std::shared_ptr<Game>(new Game(manager));
//tutoriel et la vue se met sur Game std::string path;
if(selection==0){
std::shared_ptr<Editor> editor = std::shared_ptr<Editor>(new Editor(manager)); switch (selection) {
try { case 0:
// ouverture du niveau path = "./levels/level1.dat";
break;
}
std::ifstream file; std::ifstream file;
file.open("./levels/level1.dat", std::ios::binary | std::ios::in); file.open(path, std::ios::binary | std::ios::in);
editor->load(file); game->load(file);
file.close(); 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); manager.setView(game);
} }
} }
} }
}
for(int i=0; i<NB_LVL_CHOICES; i++) for(int i=0; i<NB_LVL_CHOICES; i++)
{ {
@ -94,4 +93,3 @@ void Lvl_menu::frame(){
window.display(); window.display();
} }