Little visibility issue in my game

Alright, so I got bored at work and started writing this game, and I grasp the concept of polymorphism, and inheritance, but the implimentation eludes me a bit.
Anyway the run down is, I have a super class called Mob, from that two classes are extended, human, and monster. from those, more classes are extended, such as Paladin (human) Dragon(monster) and so forth.
Both monsters, and humans have a common method of Attack(mob temp) which I put in the Mob class. This is fine and dandy up to this point.
In the Attack() method, Humans and monsters both have some different chararistics, such as humans can drink health/mana potions, and monsters can frenzy() etc. So, in the Attack() method, I have some logic to determine if it's a monster/human, and they are able to perform their unique actions.
Since however, that DrinkPotion() is in class human, Frenzy() is in class Monster etc, The compiler is telling me it cannot see those methods.
I may be going about them wrong, i'm just not sure though.
Also, in the class with Main, I have them declaired as
mob player;
mob CPU;
Then later, when the player chooses the class, I set the base class reference to the new derived class object,
Warrior warrior = new Warrior();
player = warrior;
I just don't know why class Mob can't see the methods in grandchildren classes such as Warrior. It is afterall a warrior object i'm performing the dot operator on, is it not? ( such as player.GetHeathPotionsLeft(); )
Any help is apreciated!

The thing is you shouldn't put the implementation of the "attack" method in Mob. The idea of polymorphism is that you can treat all "actors" in your game as instances of class Mob (and therefore to have an attack() methods), while leaving the actual implementation of the method up to the various subclasses. Those subclasses will be able to see the methods inside themselves just fine, your Mob class doesn't need to know about them.
So you could have something like this:public interface Mob {
public void attack(Mob target);
}and thenpublic class Monster implements Mob {
public boolean isAngry() { // could also be private
   // put code here to determine if the monster is angry
private void frenzy() { // private, only Monster itself needs to know this
   // put code here to put your monster into a frenzy
public void attack(Mob target) {
   if(isAngry()) {
    frenzy();
   // put code here to actually attack
}andpublic class Human implements Mob {
  public void attack(Mob target) {
    // put some code here to attack
}and last but not least:public class Paladin extends Human {
  private void pray() { // private, only Paladins need to know this
    // put code here that determines if the prayer is heard and what happens then
  public void attack(Mob target) {
    pray();
    super.attack(target); // super.something() means use the implementation of my parent class, in this case the normal Human attack().
}You could then use this from your main game class like so:....
  List<Mob> participants = ... (some list containing the actors, perhaps sorted by initiative)
  public void setup() {
    participants.add(new Human());
    participants.add(new Human());
    participants.add(new Paladin());
    participants.add(new Monster());
    participants.add(new Monster());
  // handle one turn of attacks in the game
  public void handleTurn() {
    for(int attackerIndex = 0; attackerIndex < participants.size(); attackerIndex++) {
      // note: all we need to know is that the attacker is-a Mob, even though it will actually be a monster, human or paladin
      Mob attacker = participants.get(attackerIndex);
      Mob target = getMostLikelyTargetFor(attacker); // somehow determine who gets attacked
      // because of polymorphism, this will use the implementation of the actual subclass with no casting necessary:
      attacker.attack(target);
...Hope this helps.

Similar Messages

  • GE70 issues with launching games

    Hello everyone, hello msi staff.
    I recently bought ( a month ago ) a MSI GE70 intel core i7 4700 hq processor, nvidia gtx 860 m. I really like video games + i needed a laptop to work on when i have to ( using autocad and other conception stuff )
    I get two problems with my laptop on this month.
    Sometimes ( like right now ) when i launch a game, nothing happen. Opening Steam, you see steam checking for any updates, then nothing happend. I used CTRL+ALT+SUP to check if its running, it says Steam client is running but nothing appears. Same thing for League of legend. Launching it, getting on the 1st window that say if the server is available or not, pressing Play, then nothing happend, checking ctrl+alt+sup, i see LoLClient in the " Processus in background ", not in " Application " but the game didnt launch. I 1st though it was coming from my internet connection, or slow or something downloading or someone downloading, then i tried offline game : Outlast, same thing happen. You click to launch the game, nothing happen. For everygames i even tried to launch them as administrator, thats still the same thing. EVEN Pinball wont open. It goes on the loading page then nothing happend. Strange for a Gaming Computer when you cannot even launch the most basic game 
    Second problem i have, when games want to launch :p
    I sometimes ( lets say every minut / 2 minut ) have a FPS Drop on CSGO, my ping is standing @ 35 ms but the game really lag for like 5 seconds.
    Same thing on League of Legend, but  here, my ping goes to 250 ms ( for a second just a little lag spike ) then go back to 40 ms. Never happend on my old laptop. I tried to see if there was no application downloading something on desktop or running but nothing was on, only my game.
    Please help me with these issues ( at least i can deal with the second problem but the first one makes me crazy  )
    Thanks everyone

    Yep, running Growl. I guess it got installed by Adium X i guess I try to uninstall Growl, and se if that helps.
    Tnx!

  • Sound issues when playing games

    The sound works perfectly fine on my laptop when on the internet and even plaing league of legend or some steam games but for some reason i have no sound on certain games such as sims 3 when i play them? i have the volume on and i know it SHOULD be working. Why is it doing this and how do i fix it?

    Hi and welcome to the community! Since you're new please be sure that you have checked out our Discussion guidelines.
    I suggest that you try to repair the phone software using PC Companion..
    Before repairing your device you may want to backup your information first. Check out this topic for more information on how to.
    How to backup?
    If the issue should still remain I think that this needs to be examined and fixed at a repair center. For more information about how to submit your phone for repair and where, contact your local support team.
     - Official Sony Xperia Support Staff
    If you're new to our forums make sure that you have read our Discussion guidelines.
    If you want to get in touch with the local support team for your country please visit our contact page.

  • ACR Dialog Box not fully visible issue CS6

    I've got an issue with the ACR Dialog Box in PhotoshopCS6 when opening RAW files.
    The names various parameters (Temperature, Tint, Exposure, Blacks, Contrast etc.) are not visible, however you can see the sliders.
    It looks like a graphics issue as the background is black, but you cannot aee any text save for that in the WB dropdown.
    I've Googled this but not found any similar issues. It's very odd. Deleting the preferences hasn't made a difference, neither has a fresh install.
    See screen grab below
    Any suggestions welcome!
    Thanks

    Thanks people for your swift solution. I did look in the forums as well as in search engines, but didn't find these posts.
    I'll reinstall (or overwrite) the OS.
    FYI I'm on 10.8.4 on a Mac and do have MacKeeper, so there must be something in it.... grrrr
    Like people say it doesn't effects the 'normal' PS menus/screens, but does the ACR and I just checked the SAVE FOR WEB, and that too has the same issue.... (ACR 8.1 - PS 13)
    Hopefully someone clever will actually work out what it is that's being lost or corrupted.
    Thanks again!

  • New MBP issues with certain games

    I have a new post Feb 08 MBP. I have bought the Diablo and Starcraft Battle Chests, Fallout, Fallout 2, and Knights and Merchants. I have issues with all of them and these issues cannot be duplicated by owners of pre Feb 08 MBPs.
    The Diablo and Starcraft issue has been recognized by Blizzard and they are working with Apple:
    http://www.battle.net/forums/thread.aspx?FN=support&T=535843&P=1
    Reports to MacPlay about Knights and Merchants, Fallout and Fallout 2 have gone unanswered.
    Can any other new MBP owners confirm the Fallout or K&M issue?
    With Fallout I and II I have obvious graphical issues with the palette. K&M loads but I only get sounds, no window at all.
    If you have issues with Diablo II and Starcraft please post on the battle.net site above. Thanks!
    Message was edited by: Ogmios

    Hello all,
    This seems to be a problem! I wonder if it will be similar with the new iMacs that are coming out with this new processor!
    So yeah, when I load up Fallout 2 on my new Macbook Pro I get the weird graphics palette and on only one half of the screen. Seems a little phishy to me! I don't even know if there is a patch that could help! It SHOULD be solved my Rosetta or something . . . but if the new Pentyn architecture is faulty, it would have to be a recall, not a patch!
    Makes me a little nervous to tell you the truth!

  • Protected - visibility issue????

    Hi,
    i have the following classes with the following methods:
    public abstract class JRBaseFiller
    public JasperPrint fill(Map parameterValues, Connection conn)
    throws JRException
    protected JasperPrint fill(Map parameterValues, JRDataSource ds)
    throws JRException
    fillReport();
    protected abstract void fillReport() throws JRException;
    public class JRVerticalFiller extends JRBaseFiller
    protected synchronized void fillReport() throws JRException
    public class JRVerticalFillerStreaming extends JRVerticalFiller
    protected synchronized void fillReport() throws JRException
    In my coding, i create a new instance of JRVerticalFillerStreaming as below :
    Map parameter,Connection con
    JRVerticalFillerStreaming filler = new JRVerticalFillerStreaming();
    filler.fill(parameters, con);
    And it works fine....
    However, changing the Connection type to JRDataSource type
    Map parameter, JRDataSource con
    JRVerticalFillerStreaming filler = new JRVerticalFillerStreaming();
    filler.fill(parameters, con);
    results in:
    Unhandled event loop exception
    Reason:
    Unresolved compilation problem:
         The method fill(Map, JRDataSource) from the type JRBaseFiller is not visible
    I know that the method fill is of type protected but isn't protected means : Is available to all classes in the same package and also available to all subclasses of the class that owns the protected feature.This access is provided even to subclasses that reside in a different package from the class that owns the protected feature.
    In my case, JRVerticalFillerStreaming is a sub sub class of JRBaseFiller.. why it is not visible then? or is it caused by other reasons?
    Please advice..
    cheers,
    ctbozu

    >
    I know that the method fill is of type protected but
    isn't protected means : Is available to all classes
    in the same package and also available to all
    subclasses of the class that owns the protected
    feature.This access is provided even to subclasses
    that reside in a different package from the class
    that owns the protected feature.
    In my case, JRVerticalFillerStreaming is a sub sub
    class of JRBaseFiller.. why it is not visible then?
    or is it caused by other reasons?
    Please advice..
    cheers,
    ctbozuIt all depends on where you instantiate the objects. B4 we go into an example, pls keep the folln things in mind.
    Imagine that you have classes A, B, and C are in three separate packages,
    Let C be the class in which a protected member m is declared. Access is permitted only within the body of a subclass S of C.
    package com.my;
    public class BaseTest
        protected void show(){}
    //and then we have in a diff pkg
    package com.my.child;
    import com.my.BaseTest;
    public class ExtendTest extends BaseTest
        public static void main(String args[])
            ExtendTest t = new ExtendTest();       
            t.show(); //this is ok since we r in the base class method and protected is visible
            BaseTest t1 = t;
            //t1.show(); not visible cannot do this
    if the main method where we instantiate the objects is in a different Class i.e outside the base class,
    package com.my.child;
    import com.my.BaseTest;
    public class Main
        public static void main(String args[])
            ExtendTest t = new ExtendTest();
            t.showMe();
            //t.show(); not visible outside ExtendTest, cannot do this
            BaseTest t1 = t;
            //t1.show(); not visible cannot do this
    }The rule for protected method access is a little bit odd when you first hear it. Look at JLS 6.6.2.1 or go thru this resource http://java.sun.com/docs/books/jls/second_edition/html/names.doc.html#62587
    tx,
    ram.

  • Lumia 925 calendar visibility issue

    I had to make a note by entering a past event into the calendar. The event occurred on Saturday and I saved it normally. However, the event immediately disappeared from sight and I couldn't find it at all. My first thought was that I made a mistake and carefully re-entered the event, looking what happens on the screen. Same thing. Then I checked my work Outlook calendar that syncs with my Lumia and found that both calendar entries were intact and visible on the MS Outlook.
    Further study showed that no weekend events older than 2-3 weeks were visible on Lumia, despite them being OK on MS Outlook.
    Can anyone replicate the problem or advice how to solve it?

    You can use the browser to create entries through http://calendar.live.com ..
    The issue has been acknowledges by MSFT and they are working on a fix..
    Click on the blue Star Icon below if my advice has helped you or press the 'Accept As Solution' link if I solved your problem..

  • Help!  Video card issues- Slow during games

    Hey everyone, so heres my problem. I just got a brand new mbp 13" with 4 gigs ram with the new battery and everything. I have the game monkey island and spore on my mac. I also have windows xp installed on the other partition of my hard drive. I just need windows for one piece of software I use that I accidentally bought for my pc that died so now I'm stuck running it on my mac in windows. I also have modern warfare 2 on the windows side. Up until a couple days ago all the games were running really great, however yesterday something popped up on my windows saying something about malware (ughhh) and then call of duty on the windows side was running completely sluggish and when I restarted the computer in mac and tried to run spore or monkey island both of them are running slow too. What is weird is that it is only sluggish when running these games, never when watching movies or anything else that requires a video card. Could I have got a virus thats also affecting my mac os. Could this be a hardware issue? I'm just not sure. Would appreciate any help

    If you got a virus on your Windows partition, that in itself wouldn't affect Mac OS X partition directly. If you have a Windows partition you should take all the usual Windows related measures to ensure your system is protected against Virus/ Trojans/ Malware etc by installing Anti Virus software.
    Have you reset your PRAM (and/or Permissions)? Did this have any effect?
    Since your MBP is so new, if a PRAM (& permissions) reset didn't help, I'd make an appointment to see a Genius at your local Apple Store and get them to check your MacBook Pro over.

  • Screen issue , mostly playing games

    Hi guys i just bought an ipad 3 ...i 'm confused... When i start playing a game and also when i use viber ... The screen is so small ...it looks like an iphone's screen have been fixed on the ipad ... On the right bottom corner there is 2x when i tap it the screen gets big but it gets blury and when i tap 1x it gets smaller again .... How can i fix it ... I am new to ipad and have no idea about it .... Thank you

    Hello @rpowell55317,
    Welcome to the HP Forums, I hope you enjoy your experience! To help you get the most out of the HP Forums I would like to direct your attention to the HP Forums Guide First Time Here? Learn How to Post and More.
    I understand that you are having issues with your HP TouchSmart 520 while playing games. I would be happy to assist you, but first I would encourage you to post your product number for your computer as there are various versions of the 520. I am linking an HP Support document below that will show you how to find your product number. As well, if you could indicate which operating system you are using. And whether your operating system is 32-bit or 64-bit as with this and the product number I can provide you with accurate information.
    How Do I Find My Model Number or Product Number?
    Which Windows operating system am I running?
    Is the Windows Version on My Computer 32-bit or 64-bit?
    Please re-post with the requested information and I would be happy to provide you with assistance. Thank you for posting on the HP Forums. Have a great day!
    Please click the "Thumbs Up" on the bottom right of this post to say thank you if you appreciate the support I provide!
    Also be sure to mark my post as “Accept as Solution" if you feel my post solved your issue, it will help others who face the same challenge find the same solution.
    Dunidar
    I work on behalf of HP
    Find out a bit more about me by checking out my profile!
    "Customers don’t expect you to be perfect. They do expect you to fix things when they go wrong." ~ Donald Porter

  • Graphics Detection issues on video games

    I'm having issues with my laptop graphics and graphics detection whenever i play videogames. My main issue i am concerned about is the fact that whenver i play something remotely new, the game itself will try to detect my graphics card so it can adjust the graphics of the game accordingly to my system's specs but the game cannot detect graphics settings so i have to manually adjust the graphics on my own. i was wondering is this a problem lying within the operating system or is this hard coded in by hp? i just want to be able to have my games automatically detect optimal graphics settings so i do not have to mess with any settings on my own. any help would be appreciated. thank you

    Hi @mdxfever2011 ,
    Welcome to the HP Forums!
    It is a terrific place to find answers and suggestions!
    For you to have the best experience in the HP forum I would like to direct your attention to the HP Forums Guide Learn How to Post and More
    I grasp that you are experiencing a difficulty when you play games, they are  not auto detecting the  graphics on your system.
    Are you playing online games or from an  installed game.  If it is an installed game please contact the game manufacturer for assistance. 
    If is online it could be a firewall preventing the detection.
    Good Luck!
    Sparkles1
    I work on behalf of HP
    Please click “Accept as Solution ” if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos, Thumbs Up" on the bottom right to say “Thanks” for helping!

  • Verizon internet customers seem to have issues with 1 game - Marvel Puzzle Quest

    There's a game , Marvel Puzzle Quest which had an update yesterday, and since then on load, it loses connection to the server after about 14-15 seconds.  Every single time.
    I have Verizon DSL, and other folks on the game's forum in Steam who have Verizon FIOS are all experiencing the same issues.
    Non-Verizon customers seem to be able to launch the game just fine.
    So I'm guessing the game update introduced something which runs afoul of Verizon's rules or something, and the connections get killed.
    Anyone have any clue?  
    The game seems to talk to these servers:
    23.21.90.83:443
    54.230.206.27:80
    108.168.211.134:80

    I just got off the phone with VZ wireless tech support on a separate issue I was having with my 4620L JetPack. After discussing that issue, I asked about Intranet data usage and whether or not it is considered part of the data plan usage because I had seen both yes and no opinions from online discussions on the subject. She checked with the IT department to be sure and said that no it does NOT count against the data plan as long as it does not use the Internet, i.e.,  the cell tower network. Last month I used my Apple TV to display quite a few photos from my MacBook Pro using the JetPack's wifi network and a couple of days later got a notice that I was about to exceed by monthly 10GB data budget. This hardly ever happens so I'm not entirely convinced there isn't at least some usage of the VZW network when doing local Intranet transfers. I plan to do some testing this month by checking my data plan usage before and after doing a lot of local photo transfers.
    Incidentally, I purchased a separate wireless router a while ago for just this reason and also because it has a stronger wifi signal than the JetPack so it's my backup plan in case local data transfer is in fact incurring any charges against my data plan.

  • Little Snitch Issue

    I have posted a similar question in the installation category as I installed little snitch before reinstallation of my OS. When applications which were net dependant needed to access the internet, it seems that it couldn't. So I my best bet would be little snitch as that was te only app that messed around with the firewall settings and stuff.
    It seems that after reinstallation of 10.5, little snitch malfunctioned or was corrupted and required a redownload. I had the dmg for it anyway and it is up to date i.e. version 2.2.
    So I reinstalled the app and got rid of all the rules and filters. However, this did not work for me. And in addition to that, yes, I have tried uninstalling the files using the uninstaller that came with it and yes, I have manually removed all files that were related to it using the app, Easy Find and Appcleaner.
    Please advice. Thank you.
    Message was edited by: Emoslayer007

    I couldn't contact the developer as I was short on time. Anyway, after finding some time, I've solved the issue by simply restarting my mac after uninstalling it. Works perfectly now. Thanks.

  • Little PowerBook Issues

    Hey. I'm thinking of purchasing a refurbished PowerBook G4 from the online site. First of all, does this sound like a good idea?
    Secondly, I'm wondering if any of you guys who already own a PB, refurbished or not, if there are little things that bug you. For example, on my iBook: The battery hangs a little bit, it rocks about 1 cm, things like that. I'm not trying to be picky, but this is my first PB - and I just wanted to know.
    Thanks in advance and happy new year.
    Mike.

    Yeah, I got three lemons, all in a row. Sounds like the start of like a nursery rhyme.
    I too am curious about San Fran but do we seriously expect any new PowerPC Laptops? I doubt it and I for one will not be investing in the first wave of MacIntel machines. If things go as expected the Apple Refurb Store may soon be the only way to get PPC PowerBooks if that is what you are after.
    The current 12" PB is cute but for nearly £400 less (new prices) you can get a 12" iBook with a 60GB hard drive factory-fitted. What's more, you get twice the memory soldered to the motherboard (saving about 70% on the cost of upgrading to 1GB using third party RAM) and longer battery life. Oh, and it pretty much matches the PowerBook in benchmark testing.
    If you want a Superdrive, get LaCie's slimline Firewire bus-powered 16x Dual Layer DVD±RW for under £120. It is at least twice as fast, has twice the capacity and is not so fussy about media as the Apple SD (see forums for SD burn-speed issues). Need a faster/bigger hard drive? Buy a 60GB LaCie Firewire portable 5400rpm drive for £100 - you can back-up on it, boot from it and hide it in your pocket. Every portable user should have something similar anyway. Look:
    iBook (40GB HD) REFURB + 60GB FW drive + FireWire DVD + 256MB RAM (total 768 MB) = £800 approx
    iBook (60GB HD) NEW + FireWire DVD + 256MB RAM (total 768 MB) = £870 approx
    PBook (60GB HD & combo) REFURB + FireWire DVD + 512MB RAM (total 768 MB) = £950 approx
    PBook (80GB HD & Superdrive) REFURB + 512MB RAM (total 768 MB) = £950 approx
    PBook (80GB HD & Superdrive) NEW + 512MB RAM (total 768 MB) = £1150 approx
    We can all do the maths in £ or $ - so why do I still hesitate to trade my dodgy PB for an iBook???
    12" G4 Powerbook   Mac OS X (10.4.3)   768MB RAM & Superdrive

  • HT4314 Is there a system-wide issue with the Game Center.  I cannot get past the spinning dots/loading part, my game says I'm not signed in, and I am connected to the Internet.

    I have been using the Game Center to track my wins for some time (months).  Suddenly, my game tells me I'm not signed in and I cannot get the Game Center to open.

    I have two yahoo accounts and I know as they 'improved' their servers I had periodic outages. It'd work fine on my webmail on  my computer, webmail on the iPad, but not via the mail app. And it was stuff on their end. It may be a case of wait and see and you may need to eventually remove/readd the account on your iPhone.
    When the issue is on their end, unfortunately there's not much for users to do beyond wait it out or find work arounds.

  • CAXL IM Presence Chat - Presence status visible issue

    Hi ,
    While test the CAXL IM presence Chat application . We have both users , both the users were logged in with  the CUP Server, available status is visible to only one user.
    How to rosolve this issue?
    Thanks
    Felix

    Because they have absolutely nothing to do with each other, the fact that you have LDAP sync working in CUCM is by no means a signal that you'll just magically have LDAP on J4W.
    Either you configure the DNS SRV records, or the jabber-config.xml for LDAP to work.
    LDAP sync on CUCM, and LDAP profile under UC services, are irrelevant for J4W in regards to getting contact name resolution from LDAP.

Maybe you are looking for