Note that there are some explanatory texts on larger screens.

plurals
  1. POWould this be the correct place to use the java keyword "interface"?
    text
    copied!<p>I'm rather new to Java. After just reading some info on path finding, I read about using an empty class as an "<code>interface</code>", for an unknown object type.</p> <p>I'm developing a game in Java based on hospital theme. So far, the user can build a reception desk and a GP's office. They are two different types of object, one is a <code>Building</code> and one is a <code>ReceptionDesk</code>. (In my class structure.)</p> <p>My class structure is this:</p> <pre><code>GridObject--&gt;Building GridObject--&gt;Item--&gt;usableItem--&gt;ReceptionDesk. </code></pre> <p>The problem comes when the usable item can be rotated and the building cannot. The mouse click event is on the grid, so calls the same method. The GP's office is a <code>Building</code> and the reception desk is a <code>ReceptionDesk</code>. Only the <code>ReceptionDesk</code> has the method <code>rotate</code>. When right clicking on the grid, if in building mode, I have to use this "if" statement:</p> <pre><code>if (currentBuilding.getClass.equals(ReceptionDesk.getClass) </code></pre> <p>I then have to create a new <code>ReceptionDesk</code>, use the <code>rotate</code> method, and the put that reception desk back into the <code>currentBuilding GridObject</code>.</p> <p>I'm not sure if I'm explaining myself very well with this question. Sorry. I am still quite new to Java. I will try to answer any questions and I can post more code snippits if need be. I didn't know that there might be a way around the issue of not knowing the class of the object, however I may also be going about it the wrong way.</p> <p>I hadn't planned on looking into this until I saw how fast and helpful the replies on this site were! :)</p> <p>Thanks in advance.</p> <p>Rel</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload