2 /****************************************************************************
3 * Copyright (C) 2002 by Leo Khramov
4 * email: leo@xnc.dubna.su
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 ****************************************************************************/
16 // $Id: wellengine.cxx,v 1.2 2003/02/18 17:01:30 leo Exp $
18 /// module description
19 /// WellEngine is a game engine that contains basic game routins for drawing,
20 /// processing events, makeing queues of object, delivering events to them,
21 /// timeouting with given threshold, loading images needed for the game
24 #include "wellengine.h"
25 #include "wellclass.h"
27 WellEngine
*default_well_engine
=0;
29 //===========================================================================
30 /// global WellEngine()
31 /// Constructor of the class - init display size
33 WellEngine::WellEngine(int argc
, char** argv
)
39 WellEngine::~WellEngine()
43 //===========================================================================
44 /// global process_time_event()
45 /// go throuht the list of time objects, decsrease ticks_left and call
46 /// objects on timeout
48 bool WellEngine::process_time_event()
51 TimeList
* ptimelist
=timelist
.get_next();
54 TimeObject
& obj
=ptimelist
->get_object();
60 if(!obj
.obj
->process_event(wEvent(eTimeOut
)))
61 //if we return false -> don't process any objects
64 ptimelist
=ptimelist
->get_next();
69 //===========================================================================
70 /// global add_timer(WellObject*, int N_ticks)
71 /// add object to time list for ticking every N_ticks
73 bool WellEngine::add_timer(WellObject
* wo
, int ticks
)
75 TimeObject
obj(wo
,ticks
);
76 TimeList
*ptobject
=new TimeList(obj
);
77 timelist
.add(ptobject
);
81 //===========================================================================
82 /// global del_timer(WellObject*)
83 /// delete object from time list
85 bool WellEngine::del_timer(WellObject
* wo
)
88 TimeList
*plist
=timelist
.del(obj
);
97 //===========================================================================
98 /// global new_well_drawing_engine()
99 /// creates drawing engine for well board - must be overloaded in childs
101 WellDrawingEngine
* WellEngine::new_well_drawing_engine()
107 //===========================================================================
108 /// global process_event_for_all(wEvent)
109 /// go throuht the list of objects, and call process_event for each
110 /// if object return false -> break the loop
112 bool WellEngine::process_event_for_all(wEvent ev
)
115 ObjectList
* plist
=objectlist
.get_next();
118 if(!plist
->get_object()->process_event(ev
))
119 //if we return false -> don't process any objects
121 plist
=plist
->get_next();
126 //===========================================================================
127 /// global add_object(WellObject*)
128 /// add object to list of objects that want events
130 bool WellEngine::add_object(WellObject
* wo
)
132 ObjectList
*ptobject
=new ObjectList(wo
);
133 objectlist
.add(ptobject
);
137 //===========================================================================
138 /// global del_object(WellObject*, int N_ticks)
139 /// delete object from list of objects that want events
141 bool WellEngine::del_object(WellObject
* wo
)
143 ObjectList
*plist
=objectlist
.del(wo
);
152 //===========================================================================
153 /// global clear_objectlist()
154 /// clear all list of objects
156 void WellEngine::clear_objectlist()
161 plist
=objectlist
.get_next();
170 //===========================================================================
171 /// global load_images()
172 /// load all images for the game
174 void WellEngine::load_images()
176 fprintf(stderr
, "Loading resources..");
177 load_image(imBoardBG
, "board2.gif");
178 fprintf(stderr
, "..");
179 load_image(imFont1
, "font2.gif");
180 fprintf(stderr
, "..");
181 load_image(imIntroBG
, "wellintro.gif");
182 fprintf(stderr
, "..");
183 load_image(imScoreBG
, "topnine.gif");
184 fprintf(stderr
, "..");
185 load_image(imCuts
, "wellcuts.gif");
186 fprintf(stderr
, "..done\n");
189 //===========================================================================
190 /// global new_well_intro()
191 /// creates new introduction object - version for SDL Window
193 WellIntro
* WellEngine::new_well_intro()
195 return new WellIntro
;
198 //===========================================================================
199 /// global new_well_top_nine()
200 /// creates new top nine object
202 WellTopNine
* WellEngine::new_well_top_nine()
204 return new WellTopNine
;
208 //===========================================================================
209 /// global new_well_key(char*)
210 /// creates new key object
212 WellKey
* WellEngine::new_well_key(char* name
)
214 return new WellKey(name
);
217 //===========================================================================
218 /// global new_well_switch(char*)
219 /// creates new switch object
221 WellSwitch
* WellEngine::new_well_switch(char* name
)
223 return new WellSwitch(name
);
227 //===========================================================================
228 /// global new_well_base()
229 /// creates new game object
231 WellBase
* WellEngine::new_well_base()