
![]() |
perkiset
Well here it is – the infamous Missile Command OO lesson.
I regret that I cannot find the syllabus that I did for this, but the code should be pretty readable by anyone with a basic OO knowledge, even though it is in Object Pascal. At the core of the app, there is an object list containing a live object of every element that is currently “in play” in the game ie., there’s an object for each attacking line, each defending line, each explosion, jets etc. The main loop here is called by a timer, and every time it is called it looks at each one of the elements and allows them a single action with the “pulse” function. This is an example of polymorphism and encapsulation all in one – the main routine has no idea what object it just pulled off the stack, nor what the pulse() function does for <that> object. That’s why all classes descend from the TBaseClass which contains the abstract methods that all the game pieces eventually override with real instructions. Here is the most pertinent part of the main routine: { Allow all the other items in the list to process. If we dont see any alive cities we kill the app. Later note - the cities never die - update this later } i := 0; KeepGameGoing := False; while i < ElementList.Count do begin // Note that this is the entire crux of the game operation. The game // framework does not need to know what <kind> of object TempObject // is, but since it decends from the base class, we can call the "Pulse" // member procedure, which has been overridden in each object case to // actuate different functional code. tempObject := TGameObject(ElementList<>); if tempObject.Pulse then begin { TCities pulse True it they are alive } { All we need is one City pulse to keep the game alive... } if tempObject is TCity then KeepGameGoing := True; Inc(i); continue; end else begin if not (tempObject is TCity) then begin if tempObject is TAttackJet then JetIsShowing := False; TrashList.Add(tempObject); ElementList.Delete(i); end; end; end; if not KeepGameGoing then KillApp; Here is an example of the hierarchy:
perkiset
Bonus: I am a MAME fan. Find the MAME version for (your OS), get it running and then:
Here are the actual ROMs for the M!$$le c0mm@nd game (named munged on purpose). Create a directory called missile in your MAME ROMs directory, then unpack the attached tar.gz into it and you're good to go. Have fun! /p jammaster82
sweet!!! Takes me back to Hooters Girls with kegs and
buckets of wings! we should have centOS running tomorrow, we installed it today but space brained it and installed postgresql instead of LAMP and all that jazz... ::doh!:: So rework in the am.. Would love to try to get this going on centOS.. apparently its the most closely compatible to RH 9? 100%binary comp. supposedly. Apparently i have scratched the copy of kylix i own and am still waiting to hear from borland for a backup.. perkiset
Might be able to help you out with that mate... lemmee take a look and get back to you.
|

Thread Categories

![]() |
![]() |
Best of The Cache Home |
![]() |
![]() |
Search The Cache |
- Ajax
- Apache & mod_rewrite
- BlackHat SEO & Web Stuff
- C/++/#, Pascal etc.
- Database Stuff
- General & Non-Technical Discussion
- General programming, learning to code
- Javascript Discussions & Code
- Linux Related
- Mac, iPhone & OS-X Stuff
- Miscellaneous
- MS Windows Related
- PERL & Python Related
- PHP: Questions & Discussion
- PHP: Techniques, Classes & Examples
- Regular Expressions
- Uncategorized Threads