Java 101 - Counters class?
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
Java 101 - Counters class?
by 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?
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.
-
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?
by friarsol » 01 Oct 2010, 18:56
There's probably two ways to handle it.Rob Cashwalker wrote:Will it actually return correctly for "P1P1" or does it have to be passed "+1/+1"?
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);
- friarsol
- Global Moderator
- Posts: 7593
- Joined: 15 May 2010, 04:20
- Has thanked: 243 times
- Been thanked: 965 times
Re: Java 101 - Counters class?
by 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.
-
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?
by 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
4 posts
• Page 1 of 1
Who is online
Users browsing this forum: flergeVes and 62 guests