commit
						22c2ea9d8b
					
				|  | @ -0,0 +1,49 @@ | ||||||
|  | #ifndef __PTF_LVL_MENU_HPP__ | ||||||
|  | #define __PTF_LVL_MENU_HPP__ | ||||||
|  | 
 | ||||||
|  | #include <SFML/Audio.hpp> | ||||||
|  | #include <iostream> | ||||||
|  | #include "manager.hpp" | ||||||
|  | #include "game.hpp" | ||||||
|  | #include "editor.hpp" | ||||||
|  | #include "view.hpp" | ||||||
|  | #include "resource_manager.hpp" | ||||||
|  | #include <vector> | ||||||
|  | 
 | ||||||
|  | #define NB_LVL_CHOICES 3 | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  |  * La classe Lvl_menu charge le menu permettant de | ||||||
|  |  * choisir le niveau auquel l'utilisateur souhaite | ||||||
|  |  * jouer. | ||||||
|  |  */ | ||||||
|  | class Lvl_menu : public View { | ||||||
|  | 
 | ||||||
|  | public: | ||||||
|  |     Lvl_menu(Manager& manager); | ||||||
|  |     virtual ~Lvl_menu(); | ||||||
|  | 
 | ||||||
|  |     /**
 | ||||||
|  |      * Dessine le menu de niveaux | ||||||
|  |      */ | ||||||
|  |     void frame(); | ||||||
|  | 
 | ||||||
|  |     /**
 | ||||||
|  |      * Permet de changer le choix sélectionné | ||||||
|  |      */ | ||||||
|  |     void MoveUp(); | ||||||
|  |     void MoveDown(); | ||||||
|  | 
 | ||||||
|  | private: | ||||||
|  |     //repère le choix sélectionné
 | ||||||
|  |     int selection; | ||||||
|  | 
 | ||||||
|  |     sf::Font font; | ||||||
|  | 
 | ||||||
|  |     //tableau de textes modélisant les différents
 | ||||||
|  |     //choix dans le menu
 | ||||||
|  |     sf::Text choice[NB_LVL_CHOICES]; | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | #endif | ||||||
|  | @ -0,0 +1,50 @@ | ||||||
|  | #ifndef __PTF_MENU_HPP__ | ||||||
|  | #define __PTF_MENU_HPP__ | ||||||
|  | 
 | ||||||
|  | #include <SFML/Audio.hpp> | ||||||
|  | #include <iostream> | ||||||
|  | #include "manager.hpp" | ||||||
|  | #include "game.hpp" | ||||||
|  | #include "editor.hpp" | ||||||
|  | #include "view.hpp" | ||||||
|  | #include "lvl_menu.hpp" | ||||||
|  | #include "resource_manager.hpp" | ||||||
|  | #include <vector> | ||||||
|  | 
 | ||||||
|  | #define NB_CHOICES 4 | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  |  * La classe Menu charge le menu du jeu | ||||||
|  |  * et permet de choisir entre jouer, lire les règles | ||||||
|  |  * et quitter. | ||||||
|  |  */ | ||||||
|  | class Menu : public View { | ||||||
|  | 
 | ||||||
|  | public: | ||||||
|  |     Menu(Manager& manager); | ||||||
|  |     virtual ~Menu(); | ||||||
|  | 
 | ||||||
|  |     /**
 | ||||||
|  |      * Dessine le menu | ||||||
|  |      */   | ||||||
|  |     void frame(); | ||||||
|  | 
 | ||||||
|  |     /**
 | ||||||
|  |      * Permet de changer le choix sélectionné  | ||||||
|  |      */ | ||||||
|  |     void MoveUp(); | ||||||
|  |     void MoveDown(); | ||||||
|  | 
 | ||||||
|  | private: | ||||||
|  |     //repère le choix sélectionné
 | ||||||
|  |     int selection; | ||||||
|  | 
 | ||||||
|  |     sf::Font font; | ||||||
|  | 
 | ||||||
|  |     //tableau de textes modélisant les différents
 | ||||||
|  |     //choix dans le menu
 | ||||||
|  |     sf::Text choice[NB_CHOICES]; | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | #endif | ||||||
										
											Binary file not shown.
										
									
								
							|  | @ -0,0 +1,95 @@ | ||||||
|  | #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); | ||||||
|  |     choice[0].setPosition(sf::Vector2f(300, 400/(NB_LVL_CHOICES + 1))); | ||||||
|  | 
 | ||||||
|  |     for(int i=1; i < NB_LVL_CHOICES; i++) | ||||||
|  |     { | ||||||
|  |         choice[i].setFont(manager.getResourceManager().getFont("Raleway-Regular.ttf")); | ||||||
|  |         choice[i].setColor(sf::Color::White); | ||||||
|  |         choice[i].setPosition(sf::Vector2f(300, 400/((NB_LVL_CHOICES + 1))*(i+1))); | ||||||
|  |     } | ||||||
|  |     choice[0].setString("Tutoriel"); | ||||||
|  |     choice[1].setString("Niveau 1"); | ||||||
|  |     choice[2].setString("Niveau 2"); | ||||||
|  | 
 | ||||||
|  |     //choix sélectionné à l'ouverture du menu
 | ||||||
|  |     selection = 0; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | Lvl_menu::~Lvl_menu(){ | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | void Lvl_menu::MoveUp() | ||||||
|  | { | ||||||
|  |     //change la couleur du choix sélectionné
 | ||||||
|  |     if(selection-1 >= 0) | ||||||
|  |     { | ||||||
|  |         choice[selection].setColor(sf::Color::White); | ||||||
|  |         selection--; | ||||||
|  |         choice[selection].setColor(sf::Color::Red); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void Lvl_menu::MoveDown() | ||||||
|  | { | ||||||
|  |     //change la couleur du choix sélectionné
 | ||||||
|  |     if(selection+1 < NB_LVL_CHOICES) | ||||||
|  |     { | ||||||
|  |         choice[selection].setColor(sf::Color::White); | ||||||
|  |         selection++; | ||||||
|  |         choice[selection].setColor(sf::Color::Red); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void Lvl_menu::frame(){ | ||||||
|  |     sf::RenderWindow& window = manager.getWindow(); | ||||||
|  |     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) { | ||||||
|  |                 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); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     for(int i=0; i<NB_LVL_CHOICES; i++) | ||||||
|  |     { | ||||||
|  |         window.draw(choice[i]); | ||||||
|  |     } | ||||||
|  |     window.display(); | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | @ -1,11 +1,14 @@ | ||||||
| #include "manager.hpp" | #include "manager.hpp" | ||||||
| #include "editor.hpp" | #include "editor.hpp" | ||||||
|  | #include "menu.hpp" | ||||||
|  | #include "game.hpp" | ||||||
| #include <iostream> | #include <iostream> | ||||||
| #include <memory> | #include <memory> | ||||||
| #include <fstream> | #include <fstream> | ||||||
| 
 | 
 | ||||||
| int main() { | int main() { | ||||||
|     Manager manager; |     Manager manager; | ||||||
|  |     std::shared_ptr<Menu> menu = std::shared_ptr<Menu>(new Menu(manager)); | ||||||
|     std::shared_ptr<Editor> editor = std::shared_ptr<Editor>(new Editor(manager)); |     std::shared_ptr<Editor> editor = std::shared_ptr<Editor>(new Editor(manager)); | ||||||
| 
 | 
 | ||||||
|     try { |     try { | ||||||
|  | @ -15,7 +18,7 @@ int main() { | ||||||
|         editor->load(file); |         editor->load(file); | ||||||
|         file.close(); |         file.close(); | ||||||
| 
 | 
 | ||||||
|         manager.setView(editor); |         manager.setView(menu); | ||||||
|         manager.start(); |         manager.start(); | ||||||
|     } catch (const std::exception& exception) { |     } catch (const std::exception& exception) { | ||||||
|         std::cerr << "Le programme a quitté après une erreur d'exécution." << std::endl; |         std::cerr << "Le programme a quitté après une erreur d'exécution." << std::endl; | ||||||
|  |  | ||||||
|  | @ -0,0 +1,92 @@ | ||||||
|  | #include "menu.hpp" | ||||||
|  | 
 | ||||||
|  | Menu::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); | ||||||
|  |     choice[0].setPosition(sf::Vector2f(460, 400/(NB_CHOICES + 1))); | ||||||
|  | 
 | ||||||
|  |     for(int i=1; i < NB_CHOICES; i++) | ||||||
|  |     { | ||||||
|  |         choice[i].setFont(manager.getResourceManager().getFont("Raleway-Regular.ttf")); | ||||||
|  |         choice[i].setColor(sf::Color::White); | ||||||
|  |         choice[i].setPosition(sf::Vector2f(460, 400/((NB_CHOICES + 1))*(i+1))); | ||||||
|  |     } | ||||||
|  |     choice[0].setString("Jouer"); | ||||||
|  |     choice[1].setString("Regles du jeu"); | ||||||
|  |     choice[2].setString("Creer un niveau"); | ||||||
|  |     choice[3].setString("Quitter"); | ||||||
|  | 
 | ||||||
|  |     //choix sélectionné à l'ouverture du menu
 | ||||||
|  |     selection = 0;  | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | Menu::~Menu(){ | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | void Menu::MoveUp() | ||||||
|  | {    | ||||||
|  |     //change la couleur du choix sélectionné
 | ||||||
|  |     if(selection-1 >= 0) | ||||||
|  |     { | ||||||
|  |         choice[selection].setColor(sf::Color::White); | ||||||
|  |         selection--; | ||||||
|  |         choice[selection].setColor(sf::Color::Red); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void Menu::MoveDown() | ||||||
|  | { | ||||||
|  |     //change la couleur du choix sélectionné
 | ||||||
|  |     if(selection+1 < NB_CHOICES) | ||||||
|  |     { | ||||||
|  |         choice[selection].setColor(sf::Color::White); | ||||||
|  |         selection++; | ||||||
|  |         choice[selection].setColor(sf::Color::Red); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void Menu::frame(){ | ||||||
|  |     sf::RenderWindow& window = manager.getWindow(); | ||||||
|  |     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 "jouer", la vue se met sur Lvl_menu
 | ||||||
|  |                 if(selection==0){ | ||||||
|  |                     std::shared_ptr<View> lvl_menu = std::shared_ptr<View>(new Lvl_menu(manager)); | ||||||
|  |                     manager.setView(lvl_menu); | ||||||
|  |                 } | ||||||
|  |                 if(selection==1){ | ||||||
|  |                      | ||||||
|  |                 } | ||||||
|  |                 //si on choisit "créer un niveau", la vue se met sur Editor
 | ||||||
|  |                 if(selection==2){ | ||||||
|  |                     std::shared_ptr<View> editor = std::shared_ptr<View>(new Editor(manager)); | ||||||
|  |                     manager.setView(editor);    | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     for(int i=0; i<NB_CHOICES; i++) | ||||||
|  |     { | ||||||
|  |         window.draw(choice[i]); | ||||||
|  |     } | ||||||
|  |     window.display(); | ||||||
|  | 
 | ||||||
|  | } | ||||||
		Loading…
	
		Reference in New Issue