Results 1 to 13 of 13
Like Tree4Likes
  • 2 Post By JosAH
  • 1 Post By pbrockway2
  • 1 Post By Tolls

Thread: Wasn't my code was genetics while adding the harsh map

  1. #1
    Razorfc is offline Member
    Join Date
    Mar 2012
    Posts
    27
    Rep Power
    0

    Default Wasn't my code was genetics while adding the harsh map

    package model;

    import controller.MyLogger;
    import java.awt.GraphicsConfiguration;
    import java.awt.GraphicsEnvironment;
    import java.awt.Image;
    import java.awt.Transparency;
    import java.awt.image.BufferedImage;
    import java.io.IOException;
    import java.net.URL;
    import java.util.HashMap;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.imageio.ImageIO;

    /**
    * A resource manager for sprites in the game. Its often quite important how and
    * where you get your game resources from. In most cases it makes sense to have
    * a central resource loader that goes away, gets your resources and caches them
    * for future use. <p> [singleton] <p>
    *
    * @author Kevin Glass
    */
    public class SpriteStore {

    protected static String SPRITE_FOLDER = "sprites/";
    /**
    * The single instance of this class
    */
    private static SpriteStore single = new SpriteStore();
    /**
    * The cached sprite map, from reference to sprite instance
    */
    private HashMap<String, Sprite> sprites = new HashMap<String, Sprite>();

    /**
    * Get the single instance of this class
    *
    * @return The single instance of this class
    */
    public static SpriteStore get() {
    return single;
    }

    /**
    * Retrieve a sprite from the store
    *
    * @param ref The reference to the image to use for the sprite
    * @return A sprite instance containing an accelerate image of the request
    * reference
    */
    public Sprite getSprite(String ref) {
    // if we've already got the sprite in the cache
    // then just return the existing version
    if (sprites.get(ref) != null) {
    return sprites.get(ref);
    }

    // otherwise, go away and grab the sprite from the resource
    // loader
    BufferedImage sourceImage = null;

    try {
    // The ClassLoader.getResource() ensures we get the sprite
    // from the appropriate place, this helps with deploying the game
    // with things like webstart. You could equally do a file look
    // up here.


    URL url = getClass().getClassLoader().getResource(SPRITE_FOL DER + ref);

    if (url == null) {
    fail("Can't find ref: " + SPRITE_FOLDER + ref);
    }

    // use ImageIO to read the image in
    sourceImage = ImageIO.read(url);
    } catch (IOException e) {
    e.printStackTrace();
    fail("Failed to load: " + ref);
    }

    // create an accelerated image of the right size to store our sprite in
    //GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().getDefaultConfiguration() ;
    //Image image = gc.createCompatibleImage(sourceImage.getWidth(), sourceImage.getHeight(), Transparency.BITMASK);

    GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().getDefaultConfiguration() ;
    Image image = gc.createCompatibleImage(sourceImage.getWidth(), sourceImage.getHeight(), 2);

    // draw our source image into the accelerated image
    image.getGraphics().drawImage(sourceImage, 0, 0, null);

    // create a sprite, add it the cache then return it
    Sprite sprite = new Sprite(ref, image);
    sprites.put(ref, sprite);

    return sprite;
    }

    /**
    * Utility method to handle resource loading failure
    *
    * @param message The message to display on failure
    */
    private void fail(String message) {
    // we're pretty dramatic here, if a resource isn't available
    // we dump the message and exit the game
    Logger.getLogger("SpaceInvadersLog").log(Level.SEV ERE, message);
    System.exit(0);
    }
    }

    wasn't sure my code is genetics while adding the harshmap including the method

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Wasn't my code was genetics while adding the harsh map

    Your code? You're Kevin Glass?
    http://www.cs.unc.edu/~hedlund/comp1...priteStore.txt

    I can guess why a StackOverflow moderator removed your cross post.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,999
    Blog Entries
    7
    Rep Power
    19

    Default Re: Wasn't my code was genetics while adding the harsh map

    If I had to handle a harsh map I'd violently push those keys and associated values through its throat; that should teach it ;-)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Wasn't my code was genetics while adding the harsh map

    If I had to handle a harsh map...
    The trouble with the Corrections Framework is that these young maps get influenced by the older ones. Someone introduces them to unmodifiableMap() and, basically, they'll never be any good.
    DarrylBurke likes this.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default Re: Wasn't my code was genetics while adding the harsh map

    I blame their genetics.
    DarrylBurke likes this.
    Please do not ask for code as refusal often offends.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,999
    Blog Entries
    7
    Rep Power
    19

    Default Re: Wasn't my code was genetics while adding the harsh map

    Quote Originally Posted by pbrockway2 View Post
    The trouble with the Corrections Framework is that these young maps get influenced by the older ones. Someone introduces them to unmodifiableMap() and, basically, they'll never be any good.
    I'd poke them on the nose until they're even willing to accept duplicate keys; hah!

    kind regards,

    Jos ;-)
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Wasn't my code was genetics while adding the harsh map

    Quote Originally Posted by JosAH View Post
    I'd poke them on the nose until they're even willing to accept duplicate keys; hah!

    kind regards,

    Jos ;-)
    Uh-oh. I've been keeping my duplicate keys in the glove compartment along with my harsh maps, thinking they'd be safe there

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,999
    Blog Entries
    7
    Rep Power
    19

    Default Re: Wasn't my code was genetics while adding the harsh map

    Quote Originally Posted by DarrylBurke View Post
    Uh-oh. I've been keeping my duplicate keys in the glove compartment along with my harsh maps, thinking they'd be safe there
    Don't ever do that; rumours go that harsh maps eat all the gloves in the compartment and when they're bored they break their way to the engine compartment (they have huge fangs you know) and create a total mess out of your engine so don't say I didn't warn you when your car makes it to a shrieking halt on the middle of the highway; they're nasty rascals those harsh maps ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    Join Date
    May 2012
    Posts
    18
    Rep Power
    0

    Default Re: Wasn't my code was genetics while adding the harsh map

    Quote Originally Posted by JosAH View Post
    Don't ever do that; rumours go that harsh maps eat all the gloves in the compartment and when they're bored they break their way to the engine compartment (they have huge fangs you know) and create a total mess out of your engine so don't say I didn't warn you when your car makes it to a shrieking halt on the middle of the highway; they're nasty rascals those harsh maps ...

    kind regards,

    Jos
    I must strongly disagree with this, and I recent the accusation. My father and his father before him were both harsh maps, and they never hurt any gloves unless they are in immediately danger. If anything it is the gloves who are the bad guys here. You have no idea what they try to smuggle in their thumbs; everything from sawn-off fingers to memory sticks containing God knows what.

    You can read more about the poor maps on www.harshmapsarealsopeople.com

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,999
    Blog Entries
    7
    Rep Power
    19

    Default Re: Wasn't my code was genetics while adding the harsh map

    Quote Originally Posted by CustomException View Post
    I must strongly disagree with this, and I recent the accusation. My father – and his father before him – were both harsh maps, and they never hurt any gloves unless they are in immediately danger. If anything it is the gloves who are the bad guys here. You have no idea what they try to smuggle in their thumbs; everything from sawn-off fingers to memory sticks containing God knows what.

    You can read more about the poor maps on www.harshmapsarealsopeople.com
    The SPIGARHM (Society Protecting Innocent Gloves Against Rude Harsh Maps) protests against the previous message in the strongest possible way and have taken the mentioned web site off the air because it contains all just damned lies. Gloves are cute, harshmaps are evil.

    kind regards,

    Jos (founding father of the SPIGARHM)
    cenosillicaphobia: the fear for an empty beer glass

  11. #11
    Join Date
    May 2012
    Posts
    18
    Rep Power
    0

    Default Re: Wasn't my code was genetics while adding the harsh map

    Quote Originally Posted by JosAH View Post
    The SPIGARHM (Society Protecting Innocent Gloves Against Rude Harsh Maps) protests against the previous message in the strongest possible way and have taken the mentioned web site off the air because it contains all just damned lies. Gloves are cute, harshmaps are evil.

    kind regards,

    Jos (founding father of the SPIGARHM)
    I'll be taking this up with my congressman, you haven't heard the last of me. Death to SPIGARHM and its disillusioned members.

  12. #12
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Wasn't my code was genetics while adding the harsh map

    Quote Originally Posted by CustomException View Post
    I must strongly disagree with this, and I recent the accusation. My father – and his father before him – were both harsh maps, and they never hurt any gloves unless they are in immediately danger.
    Yes, but you may well be the Exception that proves the rule.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  13. #13
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,999
    Blog Entries
    7
    Rep Power
    19

    Default Re: Wasn't my code was genetics while adding the harsh map

    Quote Originally Posted by CustomException View Post
    I'll be taking this up with my congressman, you haven't heard the last of me. Death to SPIGARHM and its disillusioned members.
    Well I wiggle my genitals in the general direction of your congressman; *phht!* English pigdog! Burn those harsh maps! Burn!

    kindest regards,

    Jos ;-)
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Class Wasn't Found in Project
    By BrooksyFC in forum NetBeans
    Replies: 14
    Last Post: 05-03-2012, 10:35 AM
  2. Replies: 6
    Last Post: 03-21-2011, 02:27 PM
  3. Adding line numbers to code in output file
    By misterwebb in forum New To Java
    Replies: 2
    Last Post: 02-14-2011, 12:37 AM
  4. adding code to constructor
    By twillders in forum New To Java
    Replies: 5
    Last Post: 12-13-2010, 08:29 PM
  5. Code for adding search function in an application
    By Avdhut in forum Threads and Synchronization
    Replies: 5
    Last Post: 03-03-2009, 10:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •