Okay, I'm trying to streamline my different ores by making a parent class called ore with all the common functions. I'm testing it using my copper class so I can revert it back if things don't go well.
How can I call two+ different classes from the same function in the parent class of ore? If any of that did not make any sense, I apologize. If you need clarification feel free to ask, I'd be more than happy to further explain.
Ore
Copper
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | /** * Tell us how much ore is left in this vein. */ public void checkAmount(String oreType, Object oreType2) { MouseInfo mouse = Greenfoot.getMouseInfo(); if (ore > 999 ){ oreDisp = String.format( "%.02f" ,(ore/ 1000 )) + "k" ; } else { oreDisp = Integer.toString(( int ) ore); } if (checkHitBox(oreType2) && info == null ) { info = new Label( "\n " + oreType + ": " + oreDisp + " \n " , 24 ); getWorld().addObject(info, mouse.getX(), mouse.getY()- 20 ); } else if (checkHitBox(oreType2) == false ) { getWorld().removeObject(info); info = null ; } else if (Greenfoot.isKeyDown( "f" ) && checkHitBox(oreType2)) { getWorld().removeObject(info); info = null ; info = new Label( "\n " + oreType + ": " + oreDisp + " \n " , 24 ); getWorld().addObject(info, mouse.getX(), mouse.getY()- 20 ); } } /** * Making sure the mouse is within the bounds of the ore. */ private boolean checkHitBox(Object oreType2){ MouseInfo mouse = Greenfoot.getMouseInfo(); if (mouse == null ){ return false ; } if (ore < 11 ){ return false ; } if ( mouse.getX() >= iron.getX()-(SIZE/ 2 ) && mouse.getY() >= iron.getY()-(SIZE/ 2 ) && mouse.getX() <= iron.getX()+(SIZE/ 2 ) && mouse.getY() <= iron.getY()+(SIZE/ 2 ) ){ return true ; } else { return false ; } } |
1 2 3 4 5 6 | /** * Tell us how much ore is left in this vein. */ public void act(){ super .checkAmount( "Copper" , this ); } |