summaryrefslogtreecommitdiff
path: root/source/presentation/Screen.h
diff options
context:
space:
mode:
Diffstat (limited to 'source/presentation/Screen.h')
-rw-r--r--source/presentation/Screen.h159
1 files changed, 159 insertions, 0 deletions
diff --git a/source/presentation/Screen.h b/source/presentation/Screen.h
new file mode 100644
index 0000000..16d8cee
--- /dev/null
+++ b/source/presentation/Screen.h
@@ -0,0 +1,159 @@
+#ifndef SCREEN_H
+#define SCREEN_H
+
+#include <list>
+#include <algorithm>
+#include <sstream>
+using namespace std;
+
+#include <allegro5/allegro.h>
+#include <allegro5/allegro_native_dialog.h>
+
+#include "../logic/Maze.h"
+#include "../logic/GameObject.h"
+#include "../logic/PlayerCar.h"
+#include "../logic/EnemyCar.h"
+#include "../logic/Checkpoint.h"
+#include "../logic/Rock.h"
+#include "../logic/Smokescreen.h"
+#include "../logic/DestroyedObjectPopup.h"
+#include "../logic/AllegroWrappers.h"
+
+#include "../presentation/GamePanel.h"
+#include "../presentation/InfoPanel.h"
+
+/**
+* @brief Exception that is thrown if the Config file requests a resolution that can not work.
+*
+* @author Justin Wernick
+* @author David Schneider
+*/
+class BadResolution{};
+
+/**
+* @brief Class for creating a window on the screen.
+*
+* Anything involving drawing on the screen is the responsibility of this class. Most of these
+* responsibilities are outsourced through creating ScreenPanels with more specialised tasks,
+* such as drawing specifically the area where the gameplay takes place (GamePanel) or the
+* providing the player with information (InfoPanel).
+*
+* @author Justin Wernick
+* @author David Schneider
+*/
+class Screen
+{
+ public:
+ /**
+ * @brief Creates a Screen with the given width and height in pixels, and the given fullscreen setting.
+ *
+ * @param [in] screenWidth The width of the display that will be created in pixels.
+ * @param [in] screenHeight The height of the display that will be created in pixels.
+ * @param [in] fullscreen True if the game should be in fullscreen mode. False otherwise.
+ */
+ Screen(unsigned int screenWidth, unsigned int screenHeight, bool fullscreen);
+
+ /**
+ * @brief Destructor to ensure that the display and any ScreenPanels are destroyed properly.
+ */
+ ~Screen();
+
+ /**
+ * @brief Presents the player with a file dialog, requesting a level file to be selected.
+ *
+ * If the cancel button is clicked, and empty string is returned and exitClicked() will return
+ * true on its next call.
+ *
+ * @return The path of the level file, or an empty string if no file was selected.
+ */
+ string getLevel();
+
+ /**
+ * @brief Draws the given objects on the screen.
+ *
+ * The objects are passed to each of the ScreenPanels in turn, and then the buffers
+ * are flipped.
+ *
+ * @param [in] maze The Maze that all of the objects are in.
+ * @param [in] players The list of PlayerCars to be drawn.
+ * @param [in] enemies The list of EnemyCars to be drawn.
+ * @param [in] checkpoints The list of Checkpoints to be drawn.
+ * @param [in] rocks The list of Rocks to be drawn.
+ * @param [in] smokescreens The list of Smokescreens to be drawn.
+ * @param [in] popups The list of DestroyedObjectPopups to be drawn.
+ */
+ void draw(const Maze& maze, const list<PlayerCar>& players, const list<EnemyCar>& enemies, const list<Checkpoint>& checkpoints, const list<Rock>& rocks, const list<Smokescreen>& smokescreens, const list<DestroyedObjectPopup>& popups);
+
+ /**
+ * @brief Function to find if the player has chosen to exit the game.
+ *
+ * The game can be exited by clicking the x in the corner of the window, pressing the ESC key
+ * during the game, or by clicking 'cancel' on the file selection dialog.
+ *
+ * @return True if the game should be quit.
+ */
+ bool exitClicked();
+
+ /**
+ * @brief Draws a splash screen when the level has been won.
+ */
+ void drawWin();
+ /**
+ * @brief Draws a splash screen when the level has been lost.
+ */
+ void drawLoss();
+
+ private:
+ /**
+ * @brief Unimplemented copy constructor, prevents copying of Screen objects.
+ *
+ * Copying a Screen is unneccesary as there should only be a single Screen object.
+ */
+ Screen(const Screen& ref);
+ /**
+ * @brief Unimplemented assignment operator.
+ *
+ * @see Screen(const Screen& ref)
+ */
+ Screen& operator=(const Screen& rhs);
+
+ /**
+ * @brief Flips the display's buffers, as well as those for all of the ScreenPanels.
+ */
+ void flip();
+
+ /**
+ * @brief Checks the current resolution (_screenWidth and _screenHeight) against the screen's supported resolutions.
+ *
+ * Used to test if a fullscreen mode selection will launch without issue.
+ *
+ * @return True if the current resolution is supported.
+ */
+ bool resolutionSupported();
+
+ AllegroInit _allegro; ///< Ensures that Allegro has been installed, for event queues and creating the display.
+ AllegroKeyboardInit _keyboard; ///< Ensures that the keyboard has been installed, for checking for the ESC key.
+ AllegroDrawingInit _drawing; ///< Ensures that drawing operations have been installed, for drawing splash screens.
+
+ bool _exitClicked; ///< Set to true when the user chooses to quit the game.
+
+ unsigned int _screenWidth; ///< Horizontal number of pixels per row on the screen.
+ unsigned int _screenHeight; ///< Vertical number of pixels per column on the screen.
+
+ unsigned int _gameAreaWidth; ///< Width of the GamePanel created.
+ unsigned int _infoPanelWidth; ///< Width of the InfoPanel created. The InfoPanel is placed directly to the right of the GamePanel.
+
+ ALLEGRO_DISPLAY* _display; ///< The window created on the player's monitor to see the game.
+ ALLEGRO_EVENT_QUEUE* _windowEvents; ///< Events caught by the screen, checked for an exit command.
+ ALLEGRO_FONT* _font; ///< Font used in drawing splash screens.
+
+ /**
+ * @brief Polymorphic container used to encapsulate the different types of drawing to the screen.
+ *
+ * Since the memory of the ScreenPanels in the vector is allocated dynamically, it must be deallocated
+ * in the destructor.
+ */
+ vector<ScreenPanel*> _panels;
+};
+
+#endif // SCREEN_H