Rally X
ELEN3009 Project by Justin Wernick and David Schneider
Public Member Functions | Private Member Functions | Private Attributes
Screen Class Reference

Class for creating a window on the screen. More...

#include <Screen.h>

List of all members.

Public Member Functions

 Screen (unsigned int screenWidth, unsigned int screenHeight, bool fullscreen)
 Creates a Screen with the given width and height in pixels, and the given fullscreen setting.
 ~Screen ()
 Destructor to ensure that the display and any ScreenPanels are destroyed properly.
string getLevel ()
 Presents the player with a file dialog, requesting a level file to be selected.
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)
 Draws the given objects on the screen.
bool exitClicked ()
 Function to find if the player has chosen to exit the game.
void drawWin ()
 Draws a splash screen when the level has been won.
void drawLoss ()
 Draws a splash screen when the level has been lost.

Private Member Functions

 Screen (const Screen &ref)
 Unimplemented copy constructor, prevents copying of Screen objects.
Screenoperator= (const Screen &rhs)
 Unimplemented assignment operator.
void flip ()
 Flips the display's buffers, as well as those for all of the ScreenPanels.
bool resolutionSupported ()
 Checks the current resolution (_screenWidth and _screenHeight) against the screen's supported resolutions.

Private Attributes

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.
vector< ScreenPanel * > _panels
 Polymorphic container used to encapsulate the different types of drawing to the screen.

Detailed Description

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
David Schneider

Definition at line 44 of file Screen.h.


Constructor & Destructor Documentation

Screen::Screen ( unsigned int  screenWidth,
unsigned int  screenHeight,
bool  fullscreen 
)

Creates a Screen with the given width and height in pixels, and the given fullscreen setting.

Parameters:
[in]screenWidthThe width of the display that will be created in pixels.
[in]screenHeightThe height of the display that will be created in pixels.
[in]fullscreenTrue if the game should be in fullscreen mode. False otherwise.

Definition at line 3 of file Screen.cpp.

Screen::~Screen ( )

Destructor to ensure that the display and any ScreenPanels are destroyed properly.

Definition at line 52 of file Screen.cpp.

Screen::Screen ( const Screen ref) [private]

Unimplemented copy constructor, prevents copying of Screen objects.

Copying a Screen is unneccesary as there should only be a single Screen object.


Member Function Documentation

void Screen::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 
)

Draws the given objects on the screen.

The objects are passed to each of the ScreenPanels in turn, and then the buffers are flipped.

Parameters:
[in]mazeThe Maze that all of the objects are in.
[in]playersThe list of PlayerCars to be drawn.
[in]enemiesThe list of EnemyCars to be drawn.
[in]checkpointsThe list of Checkpoints to be drawn.
[in]rocksThe list of Rocks to be drawn.
[in]smokescreensThe list of Smokescreens to be drawn.
[in]popupsThe list of DestroyedObjectPopups to be drawn.

Definition at line 83 of file Screen.cpp.

void Screen::drawLoss ( )

Draws a splash screen when the level has been lost.

Definition at line 114 of file Screen.cpp.

void Screen::drawWin ( )

Draws a splash screen when the level has been won.

Definition at line 101 of file Screen.cpp.

bool Screen::exitClicked ( )

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.

Returns:
True if the game should be quit.

Definition at line 127 of file Screen.cpp.

void Screen::flip ( ) [private]

Flips the display's buffers, as well as those for all of the ScreenPanels.

Definition at line 92 of file Screen.cpp.

string Screen::getLevel ( )

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.

Returns:
The path of the level file, or an empty string if no file was selected.

Definition at line 65 of file Screen.cpp.

Screen& Screen::operator= ( const Screen rhs) [private]

Unimplemented assignment operator.

See also:
Screen(const Screen& ref)
bool Screen::resolutionSupported ( ) [private]

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.

Returns:
True if the current resolution is supported.

Definition at line 145 of file Screen.cpp.


Member Data Documentation

Ensures that Allegro has been installed, for event queues and creating the display.

Definition at line 134 of file Screen.h.

ALLEGRO_DISPLAY* Screen::_display [private]

The window created on the player's monitor to see the game.

Definition at line 146 of file Screen.h.

Ensures that drawing operations have been installed, for drawing splash screens.

Definition at line 136 of file Screen.h.

bool Screen::_exitClicked [private]

Set to true when the user chooses to quit the game.

Definition at line 138 of file Screen.h.

ALLEGRO_FONT* Screen::_font [private]

Font used in drawing splash screens.

Definition at line 148 of file Screen.h.

unsigned int Screen::_gameAreaWidth [private]

Width of the GamePanel created.

Definition at line 143 of file Screen.h.

unsigned int Screen::_infoPanelWidth [private]

Width of the InfoPanel created. The InfoPanel is placed directly to the right of the GamePanel.

Definition at line 144 of file Screen.h.

Ensures that the keyboard has been installed, for checking for the ESC key.

Definition at line 135 of file Screen.h.

vector<ScreenPanel*> Screen::_panels [private]

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.

Definition at line 156 of file Screen.h.

unsigned int Screen::_screenHeight [private]

Vertical number of pixels per column on the screen.

Definition at line 141 of file Screen.h.

unsigned int Screen::_screenWidth [private]

Horizontal number of pixels per row on the screen.

Definition at line 140 of file Screen.h.

ALLEGRO_EVENT_QUEUE* Screen::_windowEvents [private]

Events caught by the screen, checked for an exit command.

Definition at line 147 of file Screen.h.


The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator