Jump to content

My players direction


Joseph

Recommended Posts


    public enum Direction    {
        SOUTH(0),
        SOUTH_WEST(256),
        WEST(512),
        NORTH_WEST(768),
        NORTH(1024),
        NORTH_EAST(1280),
        EAST(1536),
        SOUTH_EAST(1792);
        
        private int index;
        
        Direction(int index)    {
            this.index = index;
        }
        
        public static String toString(int index)    {
            for (Direction d: values())    {
                if (index == d.index)
                    return d.name().replace("_", " ").toLowerCase();
            }
            return null;
        }
        
        public static String toString(Direction d)    {
            return d.name().replace("_", " ").toLowerCase();
        }
    }
You simply have to use my players "getRotation()"

 

example:

log("" +Direction.toString(myPlayer().getRotation()));

pictures example: it wont let me add picture sad.png

 

http://puu.sh/7nqGB

 

http://puu.sh/7nqHw

 

http://puu.sh/7nqI6

 

Edited by josedpay
Link to comment
Share on other sites

I'm not sure if your using the toString() correctly, I don't believe you should have a input in the constructor. Shouldn't it be something like:

   @Override
    public String toString() {
        final String s = super.toString().replace('_', ' ');
        return s.charAt(0) + s.substring(1,s.length()).toLowerCase();
    }

And to call toString you would simply call:

log(Direction.NORTH.toString());
//Outputs: North 
Edited by NotoriousPP
Link to comment
Share on other sites

 

I'm not sure if your using the toString() correctly, I don't believe you should have a input in the constructor. Shouldn't it be something like:

   @Override
    public String toString() {
        final String s = super.toString().replace('_', ' ');
        return s.charAt(0) + s.substring(1,s.length()).toLowerCase();
    }

And to call toString you would simply call:

log(Direction.NORTH.toString());
//Outputs: North 

if you want to be all fancy you could do that with your toString(). i was just to lazy to do that. Also, the only reason why i put an argument inside the parameter because without, you wouldnt know which direction you are facing, without using player#getRotation. That the point of having toString a static method. So when you call the enum you could use that method. With out having to choose one of the actual enum option, and since you have a argument, you could simply add in your player getRotation().

 

for example: instead of doing this

  • log(Direction.NORTH_WEST.toString());
  • log(Direction.SOUTH.toString());
  • log(Direction.EAST.toString());
  • log(Direction.NORTH.toString());

you could do 

  • log(Direction.toString(myPlayer().getRotation()));

     
  • Like 1
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...