Created
March 16, 2016 14:59
-
-
Save shrddr/42539f51a7cbb96d33d9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
class SpriteSet | |
{ | |
public: | |
SpriteSet(int count) { m_count = count; } | |
void render() { std::cout << m_count << " sprites\n"; } | |
private: | |
int m_count; | |
}; | |
class IScreenFactory | |
{ | |
public: | |
virtual SpriteSet* makeSprites() = 0; | |
}; | |
class MenuScreenFactory : public IScreenFactory | |
{ | |
public: | |
MenuScreenFactory(bool full) { m_full = full; } | |
SpriteSet* makeSprites() { return (m_full) ? new SpriteSet(22) : new SpriteSet(11); } | |
private: | |
bool m_full; | |
}; | |
class TunerScreenFactory : public IScreenFactory | |
{ | |
public: | |
TunerScreenFactory(bool bass) { m_bass = bass; } | |
SpriteSet* makeSprites() { return (m_bass) ? new SpriteSet(4) : new SpriteSet(6); } | |
private: | |
bool m_bass; | |
}; | |
int main() | |
{ | |
SpriteSet* sprites; | |
MenuScreenFactory msf(true); | |
sprites = msf.makeSprites(); | |
sprites->render(); | |
TunerScreenFactory tsf(true); | |
delete[] sprites; | |
sprites = tsf.makeSprites(); | |
sprites->render(); | |
delete[] sprites; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment