Go to the documentation of this file.00001
00002 #include <string.h>
00003 #include <stdio.h>
00004 #include <stdlib.h>
00005
00006 #include "Box.h"
00007 #include "Ball.h"
00008 #include "Bongo.h"
00009 #include "Engine.h"
00010 #include "XRes.h"
00011 #include "Controllers.h"
00012
00013 class Quad;
00014 class XCongo;
00015
00016 #include "Factory.h"
00017
00018
00019 Controller* Factory::CreateQuadMover(XRes *resource, XCongo *xcongo, Engine* eng, Quad* quad)
00020 {
00021 Controller* pquad = 0;
00022 char *class_name = 0;
00023
00024 if (!resource->StringValue("mClass", &class_name) )
00025 {
00026 fprintf(stderr, "error: XRes::StringValue(\"mClass\")\n");
00027 free(class_name);
00028 return 0;
00029 }
00030
00031 if (0 == strcmp(class_name, "BongoOrthoMover") )
00032 {
00033 pquad = new BongoOrthoMover(eng, dynamic_cast<Bongo*>(quad) );
00034 }
00035 else if (0 == strcmp(class_name, "BongoRealMover") )
00036 {
00037 pquad = new BongoRealMover(eng, dynamic_cast<Bongo*>(quad) );
00038 }
00039
00040 if (pquad && !pquad->Init(resource, xcongo) )
00041 {
00042 fprintf(stderr, "error: Quad::Init(XRes*)\n");
00043 delete pquad;
00044 pquad = 0;
00045 }
00046
00047 free(class_name);
00048 return pquad;
00049 }
00050 Quad* Factory::CreateQuad(XRes *resource, XCongo *xcongo)
00051 {
00052 Quad *pquad = 0;
00053 char *class_name = 0;
00054
00055 if (!resource->StringValue("mClass", &class_name) )
00056 {
00057 fprintf(stderr, "error: XRes::StringValue(\"mClass\")\n");
00058 free(class_name);
00059 return 0;
00060 }
00061
00062 if (0 == strcmp(class_name, "Ball") )
00063 {
00064 pquad = new Ball();
00065 }
00066 else if (0 == strcmp(class_name, "Box") )
00067 {
00068 pquad = new Box();
00069 }
00070 else if (0 == strcmp(class_name, "Bongo") )
00071 {
00072 pquad = new Bongo();
00073 }
00074 else
00075 fprintf(stderr, "unknow class name: %s\n", class_name);
00076
00077 if (pquad && !pquad->Init(resource, xcongo) )
00078 {
00079 fprintf(stderr, "error: Quad::Init(XRes*)\n");
00080 delete pquad;
00081 pquad = 0;
00082 }
00083 free(class_name);
00084 return pquad;
00085 }
00086