00001 /****************************************************************************** 00002 * Wormux is a convivial mass murder game. 00003 * Copyright (C) 2001-2004 Lawrence Azzoug. 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 00018 ****************************************************************************** 00019 * Affiche un message dans le jeu, puis pose une question dans le jeu ou 00020 * attend au moins la pression d'une touche. 00021 *****************************************************************************/ 00022 00023 #ifndef QUESTION_H 00024 #define QUESTION_H 00025 //----------------------------------------------------------------------------- 00026 #include "../include/base.h" 00027 #include "../graphic/sprite.h" 00028 #include <string> 00029 #include <list> 00030 #include <SDL_events.h> 00031 00032 //----------------------------------------------------------------------------- 00033 00034 class Question 00035 { 00036 Sprite* background; 00037 00038 // A choice = a key return a value 00039 class choice_t 00040 { 00041 private: 00042 int m_key; 00043 int m_val; 00044 public: 00045 choice_t (int key, int value) 00046 { m_key = key; m_val = value; }; 00047 inline const int & key() const { return m_key; }; 00048 inline const int & val() const { return m_val; }; 00049 }; 00050 00051 // Choices list 00052 std::list<choice_t> choices; 00053 typedef std::list<choice_t>::iterator choice_iterator; 00054 // Default choice used when another key is pressed 00055 struct s_default_choice 00056 { 00057 bool active; 00058 int value; 00059 } default_choice; 00060 00061 int TreatsKey (SDL_Event &event); 00062 // Message to display 00063 std::string message; 00064 00065 public: 00066 Question(); 00067 ~Question(); 00068 00069 void Set(const std::string &message, 00070 bool default_active, 00071 int default_value, 00072 const std::string &bg_sprite=""); 00073 int Ask(); 00074 void Draw() const; 00075 00076 inline void add_choice(int key, int value) 00077 { 00078 return this->choices.push_back(choice_t(key,value)); 00079 } 00080 00081 }; 00082 00083 //----------------------------------------------------------------------------- 00084 #endif