Look at the code for Nethack. While there are several 'objects', there is very little inheritence, thus, they only need to keep a 'monster' array, a 'object' array, etc. In such a flat OOP system, C is very easy to use to mimic a true OOP language. The benefits of 'switch' become highly apparent here.

Mind you, you *can* rewrite Nethack to use true OOP. As an example, you could easily use Java Interface-equivalent classes to describe all the attrbiutes that monsters may have (say, "class Large", "class Intelligent", etc). Then you can create new monsters by simply creating a new class and 'inheriting' those attributes ("class Tiamat implements Large, Intelligent, Flying, FireBreathing, PitA { ... }" ).

There's even sort of a meta-OOP floating with Nethack; one can define which interface they want at make/build time; this allows the Nethack team to actually do a primative MVC architecture so that those running the game on more 'graphic' terminals can chose an interface that's more suited for that.

But just because you can doesn't mean it will work. I know of numerous attempts to OOP'ive the classic Rogue-like games with no luck.

Just remember, any OOP structure/intherience tree/class diagram can be flatted to a procedural structure. (Initial versions of C++ did just this; they preprocessed code to munge class names and methods to unique C names) In most cases, this will be messy and filled with lots of switch blocks, but it can do the same thing. However, the flatter the object structure starts, the simplier the underlying C code, and this typically can be optimized further to get speed gains.

-----------------------------------------------------
Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
"I can see my house from here!"
It's not what you know, but knowing how to find it if you don't know that's important


In reply to Re: Why dont games use OOP? by Masem
in thread OOP, ".NET", Perl, and all that by John M. Dlugosz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.