It is currently 06 Jun 2024, 11:02
   
Text Size

Java 101 - Counters class?

Post MTG Forge Related Programming Questions Here

Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins

Java 101 - Counters class?

Postby Rob Cashwalker » 01 Oct 2010, 17:16

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?
The Force will be with you, Always.
User avatar
Rob Cashwalker
Programmer
 
Posts: 2167
Joined: 09 Sep 2008, 15:09
Location: New York
Has thanked: 5 times
Been thanked: 40 times

Re: Java 101 - Counters class?

Postby friarsol » 01 Oct 2010, 18:56

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.
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times

Re: Java 101 - Counters class?

Postby Rob Cashwalker » 01 Oct 2010, 19:30

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);
The Force will be with you, Always.
User avatar
Rob Cashwalker
Programmer
 
Posts: 2167
Joined: 09 Sep 2008, 15:09
Location: New York
Has thanked: 5 times
Been thanked: 40 times

Re: Java 101 - Counters class?

Postby friarsol » 01 Oct 2010, 20:00

Seems right to me. A quick test would prove either way though.
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times


Return to Developer's Corner

Who is online

Users browsing this forum: flergeVes and 62 guests


Who is online

In total there are 63 users online :: 1 registered, 0 hidden and 62 guests (based on users active over the past 10 minutes)
Most users ever online was 4143 on 23 Jan 2024, 08:21

Users browsing this forum: flergeVes and 62 guests

Login Form