Page 1 of 1

Java 101 - Counters class?

PostPosted: 01 Oct 2010, 17:16
by Rob Cashwalker
Java 101...

I get the basics of what enum does.... At least when we deal with adding the counters normally in code.

In response to adding Joraga Warcaller, I began adding counter counting to xCount. I found the method Counters.getType(String). Looking at that method, I'm totally confused.

Will it actually return correctly for "P1P1" or does it have to be passed "+1/+1"? Only the TOWER counter has a string association "tower", what does that indicate?

Re: Java 101 - Counters class?

PostPosted: 01 Oct 2010, 18:56
by friarsol
Rob Cashwalker wrote:Will it actually return correctly for "P1P1" or does it have to be passed "+1/+1"?
There's probably two ways to handle it.
The way I do it in abCost is to use the valueOf() call with all Caps for the String.

Code: Select all
String counterString = "P1P1"; // or "CHARGE"
Counters counter = Counters.valueOf(counterString);
.
But it looks like you can also use getType with the name set in the enum.
Code: Select all
String counterName = "+1/+1"; // or "Charge"
Counters = Counters.getType(counterName);
This function appears to convert +1/+1 to P1P1 for you.

Re: Java 101 - Counters class?

PostPosted: 01 Oct 2010, 19:30
by Rob Cashwalker
OK, so this proposed line added to CardFactoryUtil.xCount should work no problem? (passing "P1P1" in the case of Joraga)
Code: Select all
                  // Count$CardCounters.<counterType>
       if (sq[0].contains("CardCounters"))
           return doXMath(c.getCounters(Counters.getType(sq[1])), m);

Re: Java 101 - Counters class?

PostPosted: 01 Oct 2010, 20:00
by friarsol
Seems right to me. A quick test would prove either way though.