define display_context interface, implement in game_board

This commit is contained in:
Chris Beck 2014-06-10 14:50:04 -04:00
parent 13fca9a358
commit d9b3289355
2 changed files with 47 additions and 5 deletions

40
src/display_context.hpp Normal file
View File

@ -0,0 +1,40 @@
/*
Copyright (C) 2014 by Chris Beck <render787@gmail.com>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
/**
*
* This class is an abstract base class designed to simplify the use
* of the display object.
*
**/
#ifndef DISPLAY_CONTEXT_HPP_INCLUDED
#define DISPLAY_CONTEXT_HPP_INCLUDED
#include<vector>
class team;
class gamemap;
class unit_map;
class display_context {
public:
virtual const std::vector<team> & teams() const = 0;
virtual const gamemap & map() const = 0;
virtual const unit_map & units() const = 0;
virtual ~display_context() {}
};
#endif

View File

@ -17,6 +17,7 @@
#include "global.hpp"
#include "display_context.hpp"
#include "map.hpp"
#include "team.hpp"
#include "unit_map.hpp"
@ -46,7 +47,7 @@ namespace events {
*
**/
class game_board {
class game_board : public display_context {
std::vector<team> teams_;
@ -82,13 +83,14 @@ class game_board {
public:
// Constructors and const accessors
// Constructors, trivial dtor, and const accessors
game_board(const config & game_config, const config & level) : teams_(), map_(game_config, level), units_() {}
virtual ~game_board() {}
const std::vector<team> & teams() const { return teams_; }
const gamemap & map() const { return map_; }
const unit_map & units() const { return units_; }
virtual const std::vector<team> & teams() const { return teams_; }
virtual const gamemap & map() const { return map_; }
virtual const unit_map & units() const { return units_; }
// Saving