Click here to Skip to main content
15,879,535 members
Articles / Programming Languages / C++

Designing a framework for a game engine using C++

Rate me:
Please Sign up or sign in to vote.
4.00/5 (7 votes)
6 Jul 2008CPOL3 min read 47.8K   1.3K   27  
This article describes my work in creating a framework for a generic game engine in C++.
#include "stdafx.h"
#include <iostream>
 
using namespace std;
 
/* Component (interface) */
class Widget {
 
public: 
  virtual void draw() = 0; 
  virtual ~Widget() {}
};  
 
/* ConcreteComponent */
class TextField : public Widget {
 
private:                  
   int width, height;
 
public:
   TextField( int w, int h ){ 
      width  = w;
      height = h; 
   }
 
   void draw() { 
      cout << "TextField: " << width << ", " << height << '\n'; 
   }
};
 
/* Decorator (interface) */                                           
class Decorator : public Widget {
 
private:
   Widget* wid;       // reference to Widget
 
public:
   Decorator( Widget* w )  { 
     wid = w; 
   }
 
   void draw() { 
     wid->draw(); 
   }
 
   ~Decorator() {
     delete wid;
   }
};
 
/* ConcreteDecoratorA */
class BorderDecorator : public Decorator { 
 
public:
   BorderDecorator( Widget* w ) : Decorator( w ) { }
   void draw() { 
      Decorator::draw();    
      cout << "   BorderDecorator" << '\n'; 
   }  
};
 
/* ConcreteDecoratorB */
class ScrollDecorator : public Decorator { 
public:
   ScrollDecorator( Widget* w ) : Decorator( w ) { }
   void draw() {
      Decorator::draw(); 
      cout << "   ScrollDecorator" << '\n';
   }  
};
 
int _tmain(int argc, _TCHAR* argv[]) {
 
   Widget* aWidget = new BorderDecorator(
                     new ScrollDecorator(
                     new TextField( 80, 24 )));
   aWidget->draw();
   delete aWidget;
   return 0;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader
United Kingdom United Kingdom
Nalla has 9+ years of experience in system software development using C++/C# on Windows/Linux platform applied using OOAD/UML. He has good knowledge of x86 and AMD64 architecture.

Comments and Discussions