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>
|
||||
|
|
|
@ -61,31 +61,30 @@ void Lvl_menu::frame(){
|
|||
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::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("./levels/level1.dat", std::ios::binary | std::ios::in);
|
||||
editor->load(file);
|
||||
file.open(path, std::ios::binary | std::ios::in);
|
||||
game->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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(int i=0; i<NB_LVL_CHOICES; i++)
|
||||
{
|
||||
|
@ -94,4 +93,3 @@ void Lvl_menu::frame(){
|
|||
window.display();
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue