Thread: Points Base

Page 1 of 7 123 ... LastLast
Results 1 to 10 of 63
  1. #1 Points Base 
    Registered Member
    Join Date
    Feb 2016
    Posts
    123
    Thanks given
    32
    Thanks received
    31
    Rep Power
    68
    I made this thread to mostly to get feedback but I said why not and I released it as a snippet. I created this because I didn't want my Player class filled up with methods so I made universal methods for points.

    Code:
    package com.elvarg.util;
    
    public class MutableInteger {
    	
    	private int value;
    	
    	public MutableInteger(int value) {
    		this.value = value;
    	}
    	
    	public void set(int value) {
    		this.value = value;
    	}
    	
    	public int get() {
    		return value;
    	}
    	
    	public void increment(int value) {
    		this.value += value;
    	}
    	
    	public void decrement(int value) {
    		this.value -= value;
    	}
    
    }
    Code:
    public MutableInteger SLAYER_POINTS = new MutableInteger(0);
    Code:
    player.getPoints().SLAYER_POINTS.get();
    player.getPoints().SLAYER_POINTS.set(100);
    player.getPoints().SLAYER_POINTS.decrement(30);
    Reply With Quote  
     

  2. #2  
    What's a sundial in the shade?

    Lumiere's Avatar
    Join Date
    May 2013
    Age
    27
    Posts
    543
    Thanks given
    224
    Thanks received
    100
    Rep Power
    113
    Im assuming "getPoints()" is an instance for the "MutableInteger" class, or, is that a separate class?
    Edit: Nvm Im dumb lol

    Spoiler for Revy is perfect:
    Reply With Quote  
     

  3. #3  
    Software Developer

    Tyrant's Avatar
    Join Date
    Jul 2013
    Age
    24
    Posts
    1,562
    Thanks given
    678
    Thanks received
    423
    Rep Power
    1060
    Nothin special about this as the MutableInteger class does not specialize anything, what I mean is that you could utilize some methods to be more realistic with the system,
    so somethin like:

    void decrement(int amount) {
    this.amount -= amount;
    if (amount < 0) amount = 0;
    }

    Etc etc etc..
    Reply With Quote  
     

  4. #4  
    Donator

    Jason's Avatar
    Join Date
    Aug 2009
    Posts
    6,092
    Thanks given
    2,402
    Thanks received
    2,823
    Rep Power
    4550
    Even better idea, just use a mapping of keys to values where the keys are point types and the values are the associated amounts. Simple as that.

    Code:
    Points points = player.getPoints();
    
    Integer individualPoints = points.getOr(SomeEnumOfKeys.SLAYER_POINTS, 0);
    
    points.setInteger(SomeEnumOfKeys.SLAYER_POINTS, 1);
    Reply With Quote  
     


  5. #5  
    Software Developer

    Tyrant's Avatar
    Join Date
    Jul 2013
    Age
    24
    Posts
    1,562
    Thanks given
    678
    Thanks received
    423
    Rep Power
    1060
    Quote Originally Posted by Jason View Post
    Even better idea, just use a mapping of keys to values where the keys are point types and the values are the associated amounts. Simple as that.

    Code:
    Points points = player.getPoints();
    
    Integer individualPoints = points.getOr(SomeEnumOfKeys.SLAYER_POINTS, 0);
    
    points.setInteger(SomeEnumOfKeys.SLAYER_POINTS, 1);
    Or instead of getting Integer you could use the MutableInteger class he provided, obviously modified, to have even more functionality.
    Reply With Quote  
     

  6. Thankful user:


  7. #6  
    Extreme Donator


    Join Date
    Oct 2010
    Posts
    2,853
    Thanks given
    1,213
    Thanks received
    1,622
    Rep Power
    5000
    Thanks for your contribution!

    Also, just wondering. But why not just have some kind of map holding attributes, including points and everything else?
    I think it would be much cleaner instead of filling up the player class with crap
    [Today 01:29 AM] RSTrials: Nice 0.97 Win/Loss Ratio luke. That's pretty bad.
    [Today 01:30 AM] Luke132: Ok u fucking moron i forgot i could influence misc.random
    Reply With Quote  
     

  8. Thankful user:


  9. #7  
    Registered Member
    Andys1814's Avatar
    Join Date
    Feb 2013
    Posts
    974
    Thanks given
    688
    Thanks received
    455
    Rep Power
    727
    why did u name it SLAYER_POINTS when the name is literally MutableInteger.
    Reply With Quote  
     

  10. Thankful users:


  11. #8  
    Registered Member

    Join Date
    Dec 2016
    Posts
    132
    Thanks given
    39
    Thanks received
    54
    Rep Power
    100
    Quote Originally Posted by Andys1814 View Post
    why did u name it SLAYER_POINTS when the name is literally MutableInteger.
    Lmao i was thinking the same thing.
    Nando Studios
    Reply With Quote  
     

  12. #9  
    Software Developer

    Tyrant's Avatar
    Join Date
    Jul 2013
    Age
    24
    Posts
    1,562
    Thanks given
    678
    Thanks received
    423
    Rep Power
    1060
    Quote Originally Posted by Andys1814 View Post
    why did u name it SLAYER_POINTS when the name is literally MutableInteger.
    Dont think thats the issue.. more like why would he name it like that when its not final
    Technically it would make sense to make it uppercased if it was final and MutableInteger, even though the #value of the MutableInteger is mutable but the actual class is final so..
    Reply With Quote  
     

  13. #10  
    Donator

    Jason's Avatar
    Join Date
    Aug 2009
    Posts
    6,092
    Thanks given
    2,402
    Thanks received
    2,823
    Rep Power
    4550
    Quote Originally Posted by Tyrant View Post
    Or instead of getting Integer you could use the MutableInteger class he provided, obviously modified, to have even more functionality.
    No. The java.lang.Number class already has everything you need to represent a mutable or immutable number.

    Quote Originally Posted by Tyrant View Post
    Technically it would make sense to make it uppercased if it was final and MutableInteger, even though the #value of the MutableInteger is mutable but the actual class is final so..
    No it wouldn't. An object or member cannot have a constant naming if the object is not effectively final and immutable.

    i.e
    Code:
    static final List<String> IMMUTABLE_STRING_VALUES = Arrays.asList("this", "is", "bad");
    
    static final List<String> IMMUTABLE_STRING_VALUES = ImmutableList.of("this", "is", "correct");
    The latter is correct because it provides no functions that mutate the underlying collection of strings. The former is incorrect because it provides function that mutate the underlying collection, such as set.
    Reply With Quote  
     

  14. Thankful users:


Page 1 of 7 123 ... LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Replies: 37
    Last Post: 06-28-2014, 12:33 PM
  2. [BASE] User Titles. (e.g loyalty point things)
    By Robin Spud in forum Tutorials
    Replies: 29
    Last Post: 12-31-2011, 12:34 AM
  3. Replies: 45
    Last Post: 05-02-2011, 06:06 PM
  4. in-game highscores based on points
    By Oxygen in forum Help
    Replies: 1
    Last Post: 05-06-2009, 05:37 PM
  5. [HUGE] Charecter based sig (C) [HUGE]
    By Looted in forum Tutorials
    Replies: 15
    Last Post: 05-20-2007, 05:23 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •